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