Question
STM32L Flash Programming problem
Posted on January 10, 2014 at 15:49
Hi,
I'm coding a bootloader using the STM32L151VB, this bootloader read chunks of 128 bytes from a SD Card and put into the STM32L flash through FLASH_ProgramHalfPage ram function from ST Standard library. Before programming, I erase the necessary pages of the flash:FLASH_Unlock();
for
(actualPage = APPLICATION_PAGE; actualPage < (APPLICATION_PAGE + pageQuantity); actualPage++) {
if
(FLASH_ErasePage((actualPage * 256) + FLASH_BASE) != FLASH_COMPLETE)
break
;
}
and then write the new firmware from sd card:
if
(actualPage >= (APPLICATION_PAGE + pageQuantity)) {
actualPage = APPLICATION_PAGE;
actualAddress = (APPLICATION_PAGE * 256) + FLASH_BASE;
pageQuantity = fileSize / 128;
// divide now in half pages
if
(fileSize % 128)
pageQuantity++;
while
(actualPage < (APPLICATION_PAGE + pageQuantity)) {
if
(STORAGE_Read_File(buffer, 128)) {
if
(FLASH_ProgramHalfPage(actualAddress, (uint32_t*) buffer) == FLASH_COMPLETE) {
actualAddress += 128;
actualPage++;
}
else
break
;
}
else
break
;
}
}
The problem is that FLASH_ProgramHalfPage is freezing sometimes, I could not found the cause and when exactly it happens, it varies.
Am I missing something?
Thanks
Thanks