stm32-external-loader icon indicating copy to clipboard operation
stm32-external-loader copied to clipboard

Erasing sector in dual flash mode

Open 1saeed opened this issue 2 years ago • 0 comments

I faced an issue while I worked through the erasing cycle on STM32H745I-DISCO with dual MT25QL512ABB8ESF-0SIT QSPI flash. When the QSPI is in dual flash mode, the CSP_QSPI_EraseSector() method will erase the next or the previous sector as well (based on the destination sector) i.e:

#define MEMORY_SECTOR_SIZE 0x10000

  • If you erase sector 0 then sector 1 will be erased too ( CSP_QSPI_EraseSector(0 * MEMORY_SECTOR_SIZE, (0 + 1) * MEMORY_SECTOR_SIZE - 1) )
  • If you erase sector 1 then sector 0 will be erased too! ( CSP_QSPI_EraseSector(1 * MEMORY_SECTOR_SIZE, (1 + 1) * MEMORY_SECTOR_SIZE - 1) )
  • If you erase sector 2 then sector 3 will be erased too ( CSP_QSPI_EraseSector(2 * MEMORY_SECTOR_SIZE, (2 + 1) * MEMORY_SECTOR_SIZE - 1) )
  • If you erase sector 3 then sector 2 will be erased too! ( CSP_QSPI_EraseSector(3 * MEMORY_SECTOR_SIZE, (3 + 1) * MEMORY_SECTOR_SIZE - 1) )

and so on.

I didn't find any workaround to fix this issue so right now for the demo code to work I had to erase the sectors first and then run writing loop:

	 for (var = 0; var < SECTORS_COUNT; var++)
	 {
		 if (CSP_QSPI_EraseSector(var * MEMORY_SECTOR_SIZE, (var + 1) * MEMORY_SECTOR_SIZE - 1) != HAL_OK)
		 {
			 while (1) {}
		 }
	 }

	 for (var = 0; var < SECTORS_COUNT; var++)
	 {
		 if (CSP_QSPI_WriteMemory(buffer_test, var * MEMORY_SECTOR_SIZE, MEMORY_SECTOR_SIZE) != HAL_OK)
		 {
			 while (1) {}
		 }
	 }

1saeed avatar Jan 06 '23 18:01 1saeed