0

I'm using STM32F103 and moving my code to STM32F746. The F103 was able to update Flash on a per-page basis in 1KB and 2KB. I have STM32F746ZG Nucleo-board and my code size is big, flash took up to 0x08038000. I want to save other small applications on 0x08040000(sector_5). This applications consist of several 2KB sizes. I need to store multiple applications in Sector_5 and M7 cannot use Flash in 1KB or 2KB increments.

The followings are sector sizes of STM32F746ZG.

#define ADDR_FLASH_SECTOR_0 ((uint32_t)0x08000000) // 32 Kbytes
#define ADDR_FLASH_SECTOR_1 ((uint32_t)0x08008000) // 32 Kbytes
#define ADDR_FLASH_SECTOR_2 ((uint32_t)0x08010000) // 32 Kbytes
#define ADDR_FLASH_SECTOR_3 ((uint32_t)0x08018000) // 32 Kbytes
#define ADDR_FLASH_SECTOR_4 ((uint32_t)0x08020000) // 128 Kbytes
#define ADDR_FLASH_SECTOR_5 ((uint32_t)0x08040000) // 256 Kbytes
#define ADDR_FLASH_SECTOR_6 ((uint32_t)0x08080000) // 256 Kbytes
#define ADDR_FLASH_SECTOR_7 ((uint32_t)0x080C0000) // 256 Kbytes

STM32F746 consists of flash in a sector size of 256 KB each from Sector_5 to Sector7. If I want to use the Sector_5, I have to erase the whole of one sector. What if I want to update only about 2KB in the front of the Sector_5 and keep the area after 2KB intact? It means I only update the content from 0x08040000 to 0x08042000. I have to keep from 0x08042001 to 0x0807FFFF.

I can't even copy 256 KB of Flash to RAM. Because F746 only have 240KB of internal RAM and my many tasks already used RAM, so there is not enough RAM to copy one sector. In this case, please let me know how to update part of 256KB in flash.

Hans
  • 398
  • 2
  • 4
  • 14

2 Answers2

2

On the ST's flash technology, there is no way to update anywhere in the sector without first erasing it. So if there are content in the first 2KB, you cannot update it without erasing the rest of the sector.

One possibility is that you can keep one sector as a temporary buffer and never use it for real storage. Let's say you use sector 7 for that. So when you want to update sector 5, erase sector 7, copy sector 5 into sector 7, and then erase sector 5 and copy relevant content back.

Another possibility is to add an external EEPROM or SRAM for this purpose. SPI flash EEPROM is fairly inexpensive and they have a typical 100,000 write cycles, so also perfect for this use.

  • This uC allows programming the unprogrammed areas (ie having 0xff values) of the sector without need of erase. So You can for example write 2k of it Then another 2k etc etc. Erase is only needed if you want to reprogram already programmed aread as it is not possible to change the FLASH bits from 0 to 1 without erasing the page/sector – 0___________ Jun 01 '19 at 21:04
  • That is correct, from the flash's PoV, 0xff is equivalent to erased, but the same 2K section cannot be reused without clearing the whole sector. – Richard at ImageCraft Jun 01 '19 at 21:10
  • Not all STMs. Many families have CRC written when the FLASH is locked and those cannot be programmed without the erase – 0___________ Jun 01 '19 at 22:07
  • Thank you Richard. I have to use sector 7 for updating. – Hans Jun 04 '19 at 03:44
0

That depends. On many STM32 microcontrollers you can zero the bits of the FLASH without erasing it. But you cant set the bits of course - it can only be done by the erase operation. Some chips do not allow it as the flash sector has its own CRC.

If your chip allows the writing to the 0xff filled FLASH you can store the data in another place of this sector. If not You need to copy data to another sector, arase the sector and the write the data back.

0___________
  • 60,014
  • 4
  • 34
  • 74