Can't recover from out of memory

Discussion on the Lua Scripting capabilities for RaceCapture/Pro. Also see the <a href="">Lua Scripting Guide</a>

Moderators: JeffC, stieg

Posts: 47
Joined: Wed Oct 04, 2017 1:44 am

Post by lightningrod »

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:

Code: Select all

 while &#40;FLASH_EraseSector&#40;i, VoltageRange_3&#41; != FLASH_COMPLETE&#41;

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&#40;const void *address, const void *data,
        unsigned int length&#41;

    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&#40;address&#41;;
    if &#40;flashSector&#41; &#123;
                        FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR |
                        FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR&#41;;
        FLASH_EraseSector&#40;flashSector, VoltageRange_3&#41;;

        uint32_t addrTarget = &#40;uint32_t&#41; address;
        uint8_t *dataTarget = &#40;uint8_t *&#41; data;

        for &#40;unsigned int i = 0; i < length; i++&#41; &#123;
            if &#40;FLASH_ProgramByte&#40;addrTarget + i, *&#40;dataTarget + i&#41;&#41; != FLASH_COMPLETE&#41; &#123;
                rc = MEMORY_FLASH_WRITE_ERROR;
    &#125; else &#123;
    return rc;

Post Reply