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.

OAD recovery HalFlashWrite is not working



I wish to remap the ImgA and ImgB such that ImgA is OAD and ImgB provides custom services.  To do this I need to reboot into ImgA to enable OAD.  At this stage I am using BIM and writing to the CRC.  Is there a persistent register I can use instead?

To do the reboot I have been using the oad_target.c mechanism of writing 0x0000 to the CRC location.  The BIM looks for this and ignores that image.  What I want to avoid is bricking the unit by going into OAD mode and not being able to recover the old image.

To avoid this I wish to write 0x0000 to crc[1] from the app and in the BIM recognize this, set it back to 0xFFFF (so it gets CRC checked) but continue and boot once from ImgA.  To set this back to a non-zero value I need to clear the page (set it back to 0xFF) and rewrite it with the correction.  However I am finding a write following an erase fails.  However this is done in oad_target.c ~ line 330.

The following snippet of code demonstrates the issue.  Add this to the beginning of main in bim_main.c and comment out the rest, then step through it.  I would expect the crc values to be

crc[0] = 0xffff;

crc[1] = 0xcafe;

But they are both 0xff

void main( void )

{
    HAL_BOARD_INIT();
    uint16 crc[2];

    uint8 page = BIM_IMG_B_PAGE;
    img_hdr_t *pImgHdr = (img_hdr_t *)(pgBuf + BIM_HDR_OSET);

    uint16 addr = page * (HAL_FLASH_PAGE_SIZE / HAL_FLASH_WORD_SIZE) +
                                 BIM_CRC_OSET / HAL_FLASH_WORD_SIZE;

    HalFlashRead(page, 0, pgBuf, HAL_FLASH_PAGE_SIZE);

    HalFlashErase( page );

    pImgHdr->crc1 = 0xcafe;

    HalFlashWrite( addr, pgBuf, HAL_FLASH_PAGE_SIZE / HAL_FLASH_WORD_SIZE );


  /* // Prefer to run Image-B over Image-A so that Image-A does not have to invalidate itself. */
  HalFlashRead(BIM_IMG_B_PAGE, BIM_CRC_OSET, (uint8 *)crc, 4);

Thanks to a Zach Dennis (http://e2e.ti.com/support/wireless_connectivity/f/538/t/321348.aspx) for at least letting me reboot to ImgA.

It would appear related to the DMA, I suspect I am not setting something up or waiting long enough?  Any thoughts?