This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

SIMPLELINK-CC2640R2-SDK: v2.20: Factory Reset Image OAD Implementation?

Part Number: SIMPLELINK-CC2640R2-SDK
Other Parts Discussed in Thread: CC2650, CC2640R2F

Hi,

    At CC2650 SensorTag there is the sensortag_factoryreset.c and sensortag_factoryreset.h to do factory reset oad if both left and right buttons are pressed for a long time. I am trying to implement the same at Simple Peripheral Off-Chip OAD example program SDK v2.20. I want to know if I can use the sensortag_factoryreset.c and sensortag_factoryreset.h at Simple Peripheral Off-Chip OAD example program SDK v2.20. It seems though that I would need to modify the metadata write at sensortag_factoryreset.c. I am asking to confirm because SDK 2.20 uses Enhanced OAD and using sensortag_factoryreset.c and sensortag_factoryreset might not work.

   Also, would this code from sensortag_factoryreset.c work at SDK 2.20 BIM? I am referring to the "Load and launch factory image" part code which links to BIM Bim_copyImage()

void SensorTagFactoryReset_applyFactoryImage(void)
{
    SensorTagDisplay_suspend();

    if (SensorTagFactoryReset_hasImage())
    {
        // Indicate that factory image is launched
#ifdef IOID_GREEN_LED
        PIN_setOutputValue(hGpioPin, IOID_GREEN_LED, Board_LED_ON);
#endif
        // Load and launch factory image; page 0 and 31 must be omitted
        ((void (*)(uint32_t, uint32_t, uint32_t))BL_OFFSET)
            (EFL_ADDR_RECOVERY + APP_START, // Location in external flash
             EFL_SIZE_RECOVERY - 0x2000,    // Length
             APP_START);                    // Location in internal flash
    }
    else
    {
        // Indicate that factory image launch failed
        PIN_setOutputValue(hGpioPin, IOID_RED_LED, Board_LED_ON);
    }

    SensorTagDisplay_resume();
}

   I see at the BIM that you can save factory image to external flash by setting predefined symbol "CREATE_FACT_IMG_INT_TO_EXT_FLSH". But if I do that every time the device boots up it will save the factory image to external flash. Is that the recommended way to save the factory image to external flash or use this c function from sensortag_factoryreset.c

bool SensorTagFactoryReset_storeCurrentImage(void)
{
  bool success;

  success = ExtFlash_open();

  if (success)
  {
    uint32_t address;
    uint16_t imageCRC = 0;

    // Install factory image
    for (address=0; address<EFL_SIZE_RECOVERY && success; address+=EFL_PAGE_SIZE)
    {
        size_t offset;
        bool ledToggle;

        ledToggle = (address % (EFL_PAGE_SIZE * 2)) == 0;

        // LED on
        if (ledToggle)
        {
#ifdef IOID_GREEN_LED
            PIN_setOutputValue(hGpioPin, IOID_GREEN_LED, Board_LED_ON);
#endif
            PIN_setOutputValue(hGpioPin, IOID_RED_LED, Board_LED_OFF);
        }

        // Erase the page
        ExtFlash_erase(EFL_ADDR_RECOVERY + address, EFL_PAGE_SIZE);

        for (offset=0; offset<EFL_PAGE_SIZE && success; offset+=sizeof(buf))
        {
            const uint8_t *pIntFlash;
            int i;

            // Copy from internal to external flash
            pIntFlash = (const uint8_t*)address + offset;
            memcpy(buf, pIntFlash, sizeof(buf));
            success = ExtFlash_write(EFL_ADDR_RECOVERY + address + offset,
                                    sizeof(buf), buf);

            if (success)
            {
                // Add CRC
                for (i = 0; i < sizeof(buf); i++)
                {
                    imageCRC = crc16(imageCRC, buf[i]);
                }
            }
        }

        // LED off
        if (ledToggle)
        {
#ifdef IOID_GREEN_LED
            PIN_setOutputValue(hGpioPin, IOID_GREEN_LED, Board_LED_OFF);
#endif
            PIN_setOutputValue(hGpioPin, IOID_RED_LED, Board_LED_ON);
        }
    }

    if (success)
    {
        PIN_setOutputValue(hGpioPin, IOID_RED_LED, Board_LED_OFF);

        imageCRC = crc16(imageCRC, 0);
        imageCRC = crc16(imageCRC, 0);

        // Erase mata-data page
        ExtFlash_erase(EFL_IMAGE_INFO_ADDR_FACTORY, EFL_PAGE_SIZE);

        // Populate meta-data
        imgInfo.crc[0] = imageCRC;
        imgInfo.crc[1]= 0xFFFF;
        imgInfo.addr = 0x0000;
        imgInfo.ver = 0;
        imgInfo.len = EFL_SIZE_RECOVERY / EFL_OAD_ADDR_RESOLUTION;
        imgInfo.imgType = EFL_OAD_IMG_TYPE_FACTORY;
        imgInfo.uid[0]= 'F';
        imgInfo.uid[1]= 'F';
        imgInfo.uid[2]= 'F';
        imgInfo.uid[3]= 'F';
        imgInfo.status = 0xFF;

        // Store CRC in the meta-data region for factory image
        ExtFlash_write(EFL_IMAGE_INFO_ADDR_FACTORY, sizeof(ExtImageInfo_t),
                       (uint8_t*)&imgInfo);
    }
    else
    {
        // Erase the meta-data to invalidate factory image
        ExtFlash_erase(EFL_IMAGE_INFO_ADDR_FACTORY, EFL_PAGE_SIZE);
    }

    ExtFlash_close();
  }

  return success;
}

-kel

  • Hi Kel,

    Please allow me some time to review the SensorTag code. I will get back to you in time.

    Best regards,

    David
  • Hi DavidL,

        Thanks for your time. this code below I find to be complicated. I traced it before and I am not sure it really links to Bim_copyImage() C function. I have not fully confirmed the factory reset works for CC2650 SensorTag. I am not confident this code below would work for CC2640R2F.

    // Load and launch factory image; page 0 and 31 must be omitted
            ((void (*)(uint32_t, uint32_t, uint32_t))BL_OFFSET)
                (EFL_ADDR_RECOVERY + APP_START, // Location in external flash
                 EFL_SIZE_RECOVERY - 0x2000,    // Length
                 APP_START);                    // Location in internal flash

    -kel

  • Hi,

    I set the "CREATE_FACT_IMG_INT_TO_EXT_FLSH" Predefined Symbol at BIM and I am getting these errors and warnings below.

    Description Resource Path Location Type
    #20 identifier "intFlashPageSize" is undefined bim_main.c /bim_oad_offchip_cc2640r2lp_app/Application line 363 C/C++ Problem
    gmake: *** [Application/bim_main.obj] Error 1 bim_oad_offchip_cc2640r2lp_app C/C++ Problem
    gmake: Target 'all' not remade because of errors. bim_oad_offchip_cc2640r2lp_app C/C++ Problem


    #154-D conversion of nonzero integer to pointer bim_main.c /bim_oad_offchip_cc2640r2lp_app/Application line 352 C/C++ Problem
    #515-D a value of type "unsigned int" cannot be assigned to an entity of type "uint32_t *" bim_main.c /bim_oad_offchip_cc2640r2lp_app/Application line 352 C/C++ Problem
    <a href="processors.wiki.ti.com/.../225"> function "CRC32_calc" declared implicitly bim_main.c /bim_oad_offchip_cc2640r2lp_app/Application line 363 C/C++ Problem

    -kel
  • Hi,

        I am reading the documentation for BIM for Off-Chip OAD. At the flowchart below to do Factory Reset I would just need to invalidate the image header of the application firmware at internal flash then I would do a system reset. Then it will "Revert to Factory Image". But, I do not see any code at the BIM for Off-Chip OAD to copy Factory Image stored at External Flash to Internal Flash. Is this really implemented or not?

    -kel

  • Hi,

    With the build errors setting predefined symbol "CREATE_FACT_IMG_INT_TO_EXT_FLSH" and the flow chart not actually implemented. It seems that factory reset implementation at SDK is unfinished work. It is up to us to implement it.

    I will leave this post as unresolved since no one able to provide solution.

    -kel