0
\$\begingroup\$

I am attempting to write some data to my stm32 discovery board (STM32F4VET11). Following the data sheet: (Sector 11, address 0x080E0000).

The code compiles, however, the write never takes place. When I enter debug mode and check rdBuf, the addresses hold 0x00.

Any tips?

//setup memory
HAL_FLASH_Unlock();
FLASH_Erase_Sector(11, FLASH_VOLTAGE_RANGE_3);
HAL_FLASH_Lock();

//write to memory
HAL_FLASH_Unlock();
uint8_t rdBuf[5];
uint8_t wrBuf[5] = {0x11, 0x22, 0x33, 0x44, 0x55};

uint32_t flashAddress = 0x080E0000;
for(uint32_t i=0; i<5; i++)
{
    HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, flashAddress, ((uint8_t *)wrBuf)[i]);
    flashAddress++;
}
HAL_FLASH_Lock();

//read
flashAddress = 0x080E0000;
for(uint32_t i=0; i<5; i++)
{
    *((uint8_t *)rdBuf + i) = *(uint8_t *)flashAddress;
    flashAddress++;
}
\$\endgroup\$
  • 3
    \$\begingroup\$ You don't need to unlock the flash to perform a read on it. Use the return values of the functions to get an idea where something is going wrong. Check that the required clocks are enabled. Stop casting arrays when it's not needed. \$\endgroup\$ – Arsenal Sep 23 '19 at 13:49
  • 1
    \$\begingroup\$ Change the post title. It is not about EEPROM memory \$\endgroup\$ – P__J__ Sep 24 '19 at 6:54
  • \$\begingroup\$ Can you specify which generation of F4 you are using? \$\endgroup\$ – Jeroen3 Sep 24 '19 at 10:58
2
\$\begingroup\$

Flash sector 11 might not available on the E type, only on the G type. As it is the last sector.
Sectors are truncated from the higher addresses when selecting lower size parts.
See chapter "Part numbering" in the datasheet.

Any tips?

Remove the flash lock/unlock between the erase and write. Some of the older ST parts require this to be one session.

Flash unlock is not required to read it.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ You hit the nail on the head. I changed it to sector 6 and it worked instantly. \$\endgroup\$ – Roo Sep 24 '19 at 12:41
0
\$\begingroup\$

To program the flash you need to erase the page you are going to program. Some STM devices allow to program memory cells which were erased before, without the need of the page erase. But you can only change the bit values to zero. Some devices require page erase every time you are going the program it (CRC checked FLASH)

Show the source code of your write function

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Is that one line 3 is taking care of? FLASH_Erase_Sector(11, FLASH_VOLTAGE_RANGE_3); \$\endgroup\$ – Roo Sep 24 '19 at 10:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.