This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Problem with IAP on LPC2138

The IAP is driving me crazy. When I single step my code using ulink it works, but when I just let it run the micro reboots itself and the IAP hasn't worked. I've read the manual, AN10256, searched the forums and looked at the sample code.

Here's my code:

ErrorCode_t writeBufToOneFlashSector(uint8_t secNum)
{
    BOOL good = TRUE;
    ErrorCode_t retCode = ERR_NO_ERROR;
        unsigned int enables;
    BOOL pllStat;

    // Disable interrupts during erase and write operations
    // Keep a copy of what was enabled
    enables = VICIntEnable;
    command[0] = IAP_PrepareSectors;
    command[1] = (uint32_t)secNum;
    command[2] = (uint32_t)secNum;
    waitTXComplete();
    pauseTX(TRUE);
    pllStat = usePLL(FALSE);
    iap_entry(command, result);
    good = (BOOL)(IAP_CMD_SUCCESS == result[0]);
    if(!good)
    {
        usePLL(pllStat);
        retCode = ERR_IAP_ERASE_PREPARE | ERR_NUM_USED;
        errVal = (ParamType)result[0];
    }
    else
    {
        command[0] = IAP_EraseSectors;
        command[1] = (uint32_t)secNum;
        command[2] = (uint32_t)secNum;
        command[3] = XTAL_OSC_KHZ;
        // Disable interrupts during erase
        VICIntEnable = 0;
        iap_entry(command, result);
        VICIntEnable = enables;
        good = (BOOL)(IAP_CMD_SUCCESS == result[0]);
        if(!good)
        {
            usePLL(pllStat);
            retCode = ERR_IAP_ERASE | ERR_NUM_USED;
            errVal = (ParamType)result[0];
        }
    }

    // See about doing the write
    if(good)
    {
        command[0] = IAP_PrepareSectors;
        command[1] = (uint32_t)secNum;
        command[2] = (uint32_t)secNum;
        iap_entry(command, result);
        good = (BOOL)(IAP_CMD_SUCCESS == result[0]);
        if(!good)
        {
            usePLL(pllStat);
            retCode = ERR_IAP_WRITE_PREPARE | ERR_NUM_USED;
            errVal = (ParamType)result[0];
        }
    }

    // Ready to write at last
    if(good)
    {
        command[0] = IAP_CopyRAMtoFlash;
        command[1] = SectorStartAddr[secNum];
        command[2] = (unsigned int)nvBuf;
        command[3] = FLASH_NV_PAGE_SIZE8;
        command[4] = XTAL_OSC_KHZ;
        // Disable interrupts during erase
        VICIntEnable = 0;
        iap_entry(command, result);
        usePLL(pllStat);
        VICIntEnable = enables;
        good = (BOOL)(IAP_CMD_SUCCESS == result[0]);
        if(!good)
        {
            retCode = ERR_IAP_WRITE | ERR_NUM_USED;
            errVal = (ParamType)result[0];
        }
    }
    pauseTX(FALSE);
    return retCode;
}

Parents
  • Generate pulses on a single processor pin and use a digital scope to count the number of pulses before the reboot. That should allow you to pin-point where the reset is.

    Repeat a number of times to figure out if the reset point is fixed or is jittering. Jittering would often be caused by some interrupt source not being deactivated.

    Then add delays at different steps of the code and check how that affects the reset point. People who gets hit by the watchdog would quickly notice a big difference during this test.

    Are you sure that you don't have any DMA transfers ongoing?

    If I remember correctly, the IAP routine needs a number of bytes of RAM to operate - any collision with your memory use, for example with a stack?

    Have you tried to contact a NXP support engineer?

Reply
  • Generate pulses on a single processor pin and use a digital scope to count the number of pulses before the reboot. That should allow you to pin-point where the reset is.

    Repeat a number of times to figure out if the reset point is fixed or is jittering. Jittering would often be caused by some interrupt source not being deactivated.

    Then add delays at different steps of the code and check how that affects the reset point. People who gets hit by the watchdog would quickly notice a big difference during this test.

    Are you sure that you don't have any DMA transfers ongoing?

    If I remember correctly, the IAP routine needs a number of bytes of RAM to operate - any collision with your memory use, for example with a stack?

    Have you tried to contact a NXP support engineer?

Children