-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Add officialstm32 eeprom write API functions and wrap in conditionals #13
base: master
Are you sure you want to change the base?
Conversation
(save-image) seems to work but (load-image) crashes my bluepill. All help would be appreciated |
OK I'll take a look at it this afternoon. |
I've had a look at your code. However, I can't work out where the EEPROM library is that you're using. I have the official STM32 core version 1.9.0 installed, but the EEPROM library in libraries just looks like the original Arduino one. Where did you find the example code such as:
The key question is: how much emulated EEPROM does it provide? With the current settings uLisp assumes there are 10240 bytes, and it uses a minimum of 512 for the symbol table. |
I saw the function defs in |
Looking closer, the actual implementation seems to be in |
I can't spot anything wrong with your code - I think it's unnecessary to clear the buffer, but it can't do any harm. I'd be interested to know what the value of E2END is; can you insert:
|
It gives me From the /*
* FLASH_PAGE_SIZE is not defined for STM32F2xx, STM32F4xx and STM32F7xx
* Could be redefined in variant.h or using build_opt.h
* Warning: This is not the sector size, only the size used for EEPROM
* emulation. Anyway, all the sector size will be erased.
* So pay attention to not use this sector for other stuff.
*/
#define FLASH_PAGE_SIZE ((uint32_t)(16*1024)) /* 16kB page */
#endif
#define E2END (FLASH_PAGE_SIZE - 1)
#endif |
Try changing:
to:
|
With the change
|
Are we overwriting something or ... ? I can re-program it from Arduino using the STM32 ST-Link V2 STM32CubeProgrammer SWD . |
This program leaves it in a good state and outputs
|
Sorry, I'm not sure what else to suggest. |
Thank you. I'll keep debugging. Currently trying to produce a minimal saveimage/loadimage and see why it bugs out. writes seem to be fine at least. |
Oh christ, I found the error! Once I cut down the code to being a very small portion everywhere I started staring at FlashReadByte and ... I was sending in the pointer (addr) instead of its value to Corrected to |
OK, one small issue. It seems the eeprom does not persist over reboots. I flash the ulisp image with the boot0 jumper set to 1, then set it to 0, reset the board and connect over serial to a ulisp prompt. Here I run
which writes a bunch of stuff. If I run (load-image) without resetting the board it works as well. |
#include <EEPROM.h>
#define DATA_LENGTH E2END
void setup() {
Serial.begin(115200);
while(!Serial) {;;}
Serial.write("Old contents of buffer pre-reset are:\n");
eeprom_buffer_fill();
for (uint16_t i=0; i < E2END; i++){
uint8_t d = eeprom_buffered_read_byte(i);
Serial.print("flash-read-from-buffer: 0x");Serial.print(i, HEX); Serial.print("->0x"); Serial.println(d,HEX);
}
// Fill the EEPROM buffer in memory with data
for (uint16_t i = 0; i < DATA_LENGTH; i++) {
eeprom_buffered_write_byte(i, (uint8_t) 255);
}
// Copy the data from the buffer to the flash
eeprom_buffer_flush();
// Copy the data from the flash to the buffer
eeprom_buffer_fill();
// Print the last byte of the current buffer
Serial.println("Wrote 0xFF to all available bytes in memory, last byte was:");
Serial.println(eeprom_buffered_read_byte(DATA_LENGTH - 1));
}
void loop() {} works across reboots. Weird. |
It works! Somewhat! I had to add the EEPROM offset that is used for roger's core's eeprom emu as a define so the stm32 eeprom layer picks it up for the API.
The issue seems to be that if we go above a certain size we bug up something and the MCU halts. I guess we only have 1023 bytes as I also got STM32CubeProgrammer running so I'll be trying to use that to debug some more. |
Well done getting it to work! 1023 bytes of flash is better than nothing. A recent improvement I've made to the forthcoming release of uLisp is to only save the part of SymbolTable[] that's actually used, which will help. I'd like to be able to update the STM32 version to use the official core, and remove references to Roger Clark's core from the documentation since it's no longer being supported. Do you think that's a good idea? |
I think Roger Clark's core is ("unfortunately") still rather popular and has a lot of support for third-party libraries. Maybe people would still want it to run for that reason. Could be worth asking on the forum |
Started fixing up a patch for #12
I've no real experience working with the emulated eeprom/flash so feel free to rewrite any/all parts.