RegisterSearchFAQMemberlistUsergroupsLog in
Reply to topic Page 2 of 2
Goto page Previous  1, 2
Can't recover from out of memory
Author Message
Reply with quote
This probably belongs on a different thread at this point - I think we're looking at 2 bugs here: the first bug is that a lua script can cause corruption.
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:
 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.
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_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;
    } else {
    return rc;

View user's profile Send private message
Display posts from previous:
Reply to topic Page 2 of 2
Goto page Previous  1, 2
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum