I have it working with your advice,
"Flash_Bank_Number" should set automatically with the following logic shouldn't it?
Code: Select all
/* Be able to change FLASH_BANK_NUMBER to use if relevant */
#if !defined(FLASH_BANK_NUMBER) && defined(FLASH_BANK_1)
#if defined(FLASH_BANK_2)
#define FLASH_BANK_NUMBER FLASH_BANK_2
#else /* FLASH_BANK_1 */
#define FLASH_BANK_NUMBER FLASH_BANK_1
#endif /* FLASH_BANK_2 */
#ifndef FLASH_BANK_NUMBER
#error "FLASH_BANK_NUMBER could not be defined"
#endif
#endif /* !FLASH_BANK_NUMBER */
Though that never looks to define FLASH_BANK_NUMBER, regardless of FLASH_BANK_1 or FLASH_BANK_2 being set. Is this the expected behaviour?
tests where performed with the following code, based on the BufferedEEPROM example
Code: Select all
#include <EEPROM.h>
#include "stm32yyxx_ll_utils.h"
#if defined(DATA_EEPROM_BASE)
#warning "STM32 devices have an integrated EEPROM. No buffered API available."
void setup() {
}
void loop() {
}
#else
/**
Most STM32 devices don't have an integrated EEPROM.
To emulate a EEPROM, the STM32 Arduino core emulated
the operation of an EEPROM with the help of the embedded
flash.
Writing to a flash is very expensive operation, since a
whole flash page needs to be written, even if you only
want to access the flash byte-wise.
The STM32 Arduino core provides a buffered access API
to the emulated EEPROM. The library has allocated the
buffer even if you don't use the buffered API, so
it's strongly suggested to use the buffered API anyhow.
*/
#define DATA_LENGTH E2END
void setup() {
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB
}
#if defined(DATA_LENGTH)
Serial.print("DATA_LENGTH: ");
Serial.print(DATA_LENGTH/1024.0);
Serial.println("k");
#endif
#if defined(FLASH_PAGE_NUMBER)
Serial.print("FLASH_PAGE_NUMBER: ");
Serial.println(FLASH_PAGE_NUMBER);
#endif
#if defined(FLASH_BANK_NUMBER)
Serial.print("FLASH_BANK_NUMBER: ");
Serial.println(FLASH_BANK_NUMBER);
#endif
#if defined(FLASH_BANK_1)
Serial.print("FLASH_BANK_1: ");
Serial.println(FLASH_BANK_1);
#endif
#if defined(FLASH_BANK_2)
Serial.print("FLASH_BANK_2: ");
Serial.println(FLASH_BANK_2);
#endif
#if defined(FLASH_SECTOR_TOTAL)
Serial.print("FLASH_SECTOR_TOTAL: ");
Serial.println(FLASH_SECTOR_TOTAL);
#endif
#if defined(FLASH_DATA_SECTOR)
Serial.print("FLASH_DATA_SECTOR: ");
Serial.println(FLASH_DATA_SECTOR);
#endif
#if defined(FLASH_BASE)
Serial.print("FLASH_BASE: 0x0");
Serial.println(FLASH_BASE, HEX);
#endif
#if defined(FLASH_BASE_ADDRESS)
Serial.print("FLASH_BASE_ADDRESS: 0x0");
Serial.println(FLASH_BASE_ADDRESS, HEX);
#endif
#if defined(FLASH_PAGE_SIZE)
Serial.print("FLASH_PAGE_SIZE: ");
Serial.print(FLASH_PAGE_SIZE/1024.0);
Serial.println("k");
#endif
#if defined(FLASH_END)
Serial.print("FLASH_END: 0x0");
Serial.println(FLASH_END, HEX);
#endif
#if defined(EEPROM_RETRAM_MODE)
Serial.print("EEPROM_RETRAM_MODE: True ");
Serial.println(EEPROM_RETRAM_MODE);
#endif
#if defined(EEPROM_RETRAM_START_ADDRESS)
Serial.print("EEPROM_RETRAM_START_ADDRESS: 0x0");
Serial.println(EEPROM_RETRAM_START_ADDRESS, HEX);
#endif
#if defined(EEPROM_RETRAM_MODE_SIZE)
Serial.print("EEPROM_RETRAM_MODE_SIZE: ");
Serial.println(EEPROM_RETRAM_MODE_SIZE);
#endif
#if defined(DATA_EEPROM_END)
Serial.print("DATA_EEPROM_END: 0x0");
Serial.println(DATA_EEPROM_END, HEX);
#endif
#if defined(FLASH_BANK2_END)
Serial.print("FLASH_BANK2_END: 0x0");
Serial.println(FLASH_BANK2_END, HEX);
#endif
#if defined(FLASH_BANK1_END)
Serial.print("FLASH_BANK1_END: 0x0");
Serial.println(FLASH_BANK1_END, HEX);
#endif
#if defined(DATA_EEPROM_BASE)
Serial.print("DATA_EEPROM_BASE: ");
Serial.println(DATA_EEPROM_BASE);
#endif
// Serial.print("FLASH_PAGE_NUMBER: ");
// Serial.println((uint32_t)(((LL_GetFlashSize() * 1024) / FLASH_PAGE_SIZE) - 1));
Serial.print("FlashSize: ");
Serial.print((uint32_t)(LL_GetFlashSize()));
Serial.println("k");
}
void loop() {
// Fill the EEPROM buffer in memory with data
for (uint16_t i = 0; i < DATA_LENGTH; i++) {
eeprom_buffered_write_byte(i, i % 256);
}
// Copy the data from the buffer to the flash
eeprom_buffer_flush();
// Clear the buffer for demonstration purpose
for (uint16_t i = 0; i < DATA_LENGTH; i++) {
eeprom_buffered_write_byte(i, 0);
}
// Print the 254th byte of the current buffer (should be 0)
Serial.println(eeprom_buffered_read_byte(254));
// Copy the data from the flash to the buffer
eeprom_buffer_fill();
// Print the 254th byte of the current buffer (should be 254)
Serial.println(eeprom_buffered_read_byte(254));
delay(100000);
}
#endif