Data-like flash read with memory barrier?
Heyho,
I recently finished - or so I thought - the ethernet bootloader for STM32H73x.
The bootloader can update the application and vice versa, updating, jumping back and forth, all working fine.
Until yesterday all of a sudden (when I was working on some other http POST stuff unrelated to the internal flash) the bootloader somehow got stuck when verifying the freshly written application.
Verification goes like:
- read (Octo-) SPI flash image page (256 bytes)
- compare SPI flash buffer to internal flash via pointer
The hard fault info that I got was not really useful, I was looking for all kinds of stuff, but could not solve the problem.
Until I added some memory barriers, as you can see below - combined with loading each flash byte into a variable, and then comparing (before that I used directly used the flash byte pointer sFlashIntCtl.pu8ChkAddr[i] in the for loop).
Now it's working again.
BUT... does that make sense?
Or was that just coincidence, and I have another problem?
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* read from SPI flash
* BLOCKING &
* ### outside of state machine ###
*/
sFlashIntCtl.u8ChkError = OspiFlashRdPage();
__DSB();
if( sFlashIntCtl.u8ChkError != HAL_OK )
{
#if DEBUG_FLASH_INT
uart_printf("\n\r# ERR: FLINT_STATE_CHECK OspiFlashRdPage()\n\r");
#endif /* DEBUG_FLASH_INT */
sFlashIntCtl.u32ChkErrors++;
u8FlashIntState = FLINT_STATE_ERROR;
}
else
{
/* compare */
uint32_t u32ErrOld = sFlashIntCtl.u32ChkErrors;
uint8_t u8FlashByte = 0;
/* compare internal flash to SPI flash page buffer */
for( uint32_t i = 0; i < (uint32_t)OSPI_FLASH_PAGE_SIZE; i++ )
{
u8FlashByte = sFlashIntCtl.pu8ChkAddr[i];
__DSB();
if( u8OspiFlashPageBuf[i] != u8FlashByte )
{
sFlashIntCtl.u32ChkErrors++;
}
if( (sFlashIntCtl.u32ChkBtDone + i) >= (sSpiFileInfo.u32Size - 1) ) break;
}
sFlashIntCtl.u32ChkBtDone += sFlashIntCtl.u32ChkLen;
PS: why is that very useful </> code insert button back in line 2? This should be the first one to appear, it's surely more often used than other stuff that appears first.
