The second bug is that the factory reset doesn't clear the script partition.
Looking at the firmware code below and doing a little googling, it appears that flashing will fail if the flags are not cleared or if the memory is not erased prior to the "program" call. The ClearFlag op does not return a value but a check to see if the flags are actually clear might be warranted, as everything following will fail. Also the EraseSector call does return an error value which is not being checked. Knowing if this is where things fail might be useful.
Third: the ProgramByte operation can return 3 different failure values. It might also be useful to know what the cause of this call failing is.
Finally: I saw some other flash code that include this for the erase code:
Code: Select all
while (FLASH_EraseSector(i, VoltageRange_3) != FLASH_COMPLETE)
But I think having a limit on the number of tries might be wise.
I'm not brave enough to modify this code and test it on my rcp3. Perhaps brent might be so good as to supply me with a version that adds more error checking and logging (which as been tested to work on his rcp) When I get the error next I can pass on the results from my logs.
Code: Select all
enum memory_flash_result_t memory_device_flash_region(const void *address, const void *data,
unsigned int length)
{
enum memory_flash_result_t rc = MEMORY_FLASH_SUCCESS;
/* Erase the entire page before you can write. This filters
* the incoming addresses to available flash pages for the STM32F4 */
uint32_t flashSector = selectFlashSector(address);
if (flashSector) {
FLASH_Unlock();
FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR |
FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR |
FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
FLASH_EraseSector(flashSector, VoltageRange_3);
uint32_t addrTarget = (uint32_t) address;
uint8_t *dataTarget = (uint8_t *) data;
for (unsigned int i = 0; i < length; i++) {
if (FLASH_ProgramByte(addrTarget + i, *(dataTarget + i)) != FLASH_COMPLETE) {
rc = MEMORY_FLASH_WRITE_ERROR;
break;
}
}
FLASH_Lock();
} else {
rc = MEMORY_FLASH_WRITE_ERROR;
}
return rc;
}
Code: Select all