LPC54605 IAP Not Erasing Or Writing

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC54605 IAP Not Erasing Or Writing

Jump to solution
1,437 Views
guitardenver
Contributor IV

Hello,

I am using the fsl_iap.h driver to write internal flash. I'm pretty much using the example code that comes with the SDK for the MCU. The problem is that the IAP calls are returning a success status code, but the task did nothing. It does not erase or write to flash. I'm using the memory viewer to what address 0x8000. It does not erase to all 0xFF and it does not write new data to it.

Below is the code.

Inputs to PTI_FLASH_BlockWrite are as follows in my test code that is not erase or writing. 

Start = 0x8000

pSrc  = 0x200097ac which points to a 32kbyte RAM buffer. 

Notes:
ECRP register is 0x00000000 and I have not touched OTP. MCU Core is running at 180MHz = systemCoreClock

#define PTI_FLASH_PAGE_SIZE (4)            ///< Minimum amount of bytes that can be written
#define PTI_FLASH_BLOCK_SIZE (256)         ///< Minimum amount of bytes that can be erased
#define PTI_FLASH_SECTOR_SIZE (32 * 0x400) ///< Largest amount of bytes that can be erased.

#define PTI_FLASH_PAGE_ALIGNMENT PTI_FLASH_PAGE_SIZE     ///< Address alignment for page operations
#define PTI_FLASH_BLOCK_ALIGNMENT PTI_FLASH_BLOCK_SIZE   ///< Address alignment for block operations
#define PTI_FLASH_SECTOR_ALIGNMENT PTI_FLASH_SECTOR_SIZE ///< Address alignment for sector operations

#define m_PTI_FLASH_IsPageAligned(addr) (addr % PTI_FLASH_PAGE_ALIGNMENT ? 0 : 1)
#define m_PTI_FLASH_IsBlockAligned(addr) (addr % PTI_FLASH_BLOCK_ALIGNMENT ? 0 : 1)
#define m_PTI_FLASH_IsSectorAligned(addr) (addr % PTI_FLASH_SECTOR_ALIGNMENT ? 0 : 1)

#define m_PTI_FLASH_AddrToSector(addr) (uint32_t)(addr / PTI_FLASH_SECTOR_SIZE) ///< Returns sector the address is in
#define m_PTI_FLASH_AddrToBlock(addr) (uint32_t)(addr / PTI_FLASH_BLOCK_SIZE) ///< Returns what block the address is in
static pti_return_t PTI_FLASH_BlockWrite(uint32_t startconst uint8_tpSrc) {
    PTI_ASSERT(pSrc);

    if(!m_PTI_FLASH_IsBlockAligned(start)) {
        return pti_flash_err_alignment;
    }

    uint32_t systemCoreClock = CLOCK_GetCoreSysClkFreq();

    // Prepare the sector for write
    status_t status = IAP_PrepareSectorForWrite(m_PTI_FLASH_AddrToSector(start), m_PTI_FLASH_AddrToSector(start));
    if(status != kStatus_IAP_Success) {
        return pti_flash_err_write;
    }

    // Erase the block
    status = IAP_ErasePage(m_PTI_FLASH_AddrToBlock(start), m_PTI_FLASH_AddrToBlock(start), systemCoreClock);    
    if(status != kStatus_IAP_Success) {
        return pti_flash_err_write;
    }

    // Prepare the sector for write
    status = IAP_PrepareSectorForWrite(m_PTI_FLASH_AddrToSector(start), m_PTI_FLASH_AddrToSector(start));
    if(status != kStatus_IAP_Success) {
        return pti_flash_err_write;
    }

    // Program the block
    status = IAP_CopyRamToFlash(start, (uint32_t*)pSrc, PTI_FLASH_BLOCK_SIZE, systemCoreClock);
    if(status != kStatus_IAP_Success) {
        return pti_flash_err_write;
    }

    return pti_success;
}
 
Labels (2)
Tags (2)
0 Kudos
1 Solution
1,227 Views
Sabina_Bruce
NXP Employee
NXP Employee

Hello Matt,

I've not been able to detect anything in the code you have provided that might be the reason why it is not working. You are using the functions provided in the driver and the steps taken should be ok. However, the code you have provided is just the block that executes the erase and write I am not able to see if you have in fact initialized the clocks correctly. If you could share a simple example project and attach it to your next post I would appreciate it so I can check it with detail.

Also, could you attempt yo do a mass erase prior to debugging, to check and see if the space in memory does read as FF or it still reads as zeros.

Let me know your results.

Sabina

View solution in original post

0 Kudos
5 Replies
1,227 Views
guitardenver
Contributor IV

Hello,

This is on custom hardware. I am not running an example code, bud I did copy paste the above code from the lpcxpresso54608_iap_flash SDK example from SDK 2.7.0.

The MCUXpresso example works on the dev board OM13092 LPCXpresso54608. I can not run the MCUXpresso example on my hardware.

My code does not work on the OM13092 dev board either. So I think it may be a peripheral setting issue like a clock or IAP setting.

I am using SEGGER Embedded Studio. I put the example code in my project and nothing seems to write to flash.

Below is some simpler code to help debug the issue. I also attached a GIF of me stepping through the debugger. You can see the 0x8000 memory view and the local variables. You can see the status returned is 0x00 and the 0x8000 memory is never changes.

Below is an image of address 0x00 of my application binary. So you can see ECRP values.

pastedImage_1.png

    uint32_t systemCoreClock = CLOCK_GetCoreSysClkFreq();

    OS_INT_DisableAll();
    status_t status = IAP_PrepareSectorForWrite(11);
    status = IAP_EraseSector(11, systemCoreClock);

    status = IAP_PrepareSectorForWrite(11);

    status = IAP_CopyRamToFlash(0x8000, (uint32_t*)pSrc, 256, systemCoreClock);

    __asm("NOP");
0 Kudos
1,228 Views
Sabina_Bruce
NXP Employee
NXP Employee

Hello Matt,

I've not been able to detect anything in the code you have provided that might be the reason why it is not working. You are using the functions provided in the driver and the steps taken should be ok. However, the code you have provided is just the block that executes the erase and write I am not able to see if you have in fact initialized the clocks correctly. If you could share a simple example project and attach it to your next post I would appreciate it so I can check it with detail.

Also, could you attempt yo do a mass erase prior to debugging, to check and see if the space in memory does read as FF or it still reads as zeros.

Let me know your results.

Sabina

0 Kudos
1,225 Views
guitardenver
Contributor IV

I took your idea to confirm that the memory viewer does read 0xFF and you were right. Turns out the code was working fine, but the memory viewer is not updating for some reason. I read the flash region after erase into a RAM buffer and it all reads FF and after I program the flash it reads with the correct data.

It was an IDE issue.

0 Kudos
1,225 Views
Sabina_Bruce
NXP Employee
NXP Employee

I'm glad that you resolved the issue.If you would like to use another IDE I recommend MCUXPresso, this also has a user friendly memory viewer. If you have any questions on that IDE please don't hesitate to let me know.

Have a good week!

0 Kudos
1,227 Views
Sabina_Bruce
NXP Employee
NXP Employee

Hello Matt,

Hope you are doing well.

First in order for me to understand the environment that they are working with. Could you please have them confirm if you are working on a custom board or an evaluation board,SDK and IDE version.Also are you basing your code on an example, so that I may try to reproduce this behavior from my end.

Best Regards,

Sabina

-----------------------------------------------------------------------------------------------------------------------

Note: If this post answers your question, please click the Correct Answer button. Thank you!

----------------------------------------------------------------------------------------------------------------------- 

0 Kudos