MCXN5 CMPA Write Fails

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

MCXN5 CMPA Write Fails

2,659 Views
mosesrs
Contributor I

Hi,

 

I'm trying to update CMPA flash region by the firmware.

My code looks like this (very similar to the one in the reference manual):

 

 

flash_config_t flashConfig;
uint8_t      cmpa[512] = {0};

if (FLASH_Init(&flashConfig) != kStatus_FLASH_Success)
{
    return kStatus_FLASH_Error;
}

if (FFR_Init(&flashConfig) != kStatus_FLASH_Success)
{
    return kStatus_FLASH_Error;
}

if (FFR_GetCustomerData(&flashConfig, cmpa, 0u, 512u) != kStatus_FLASH_Success)
{
    return kStatus_FLASH_Error;
}

if (FFR_CustFactoryPageWrite(&flashConfig, cmpa, false) != kStatus_FLASH_Success)
{
    return kStatus_FLASH_Error;
}

 

 

The last call (FFR_CustFactoryPageWrite) ends with HardFault. 

Is there an SDK example code that demonstrate CMPA write?

What might be causing the behavior?

 

Thanks

Labels (1)
0 Kudos
Reply
10 Replies

2,255 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello @mosesrs 

Thanks for your patience. 

Sorry CMAC calculation is not supported by the ROM API when programing CMPA, so the seal_part should be set as false and set the CMPA CMAC value of the as 0x00, then the CMPA value can be programmed without the CMAC. After all the CMPA value is verified and user can use the ISP write command the CMPA, that will calculate the CMPA CMAC, which will be checked when the lifecycle advance to secure_world(0x7) above.

 

BR

Alice

0 Kudos
Reply

2,598 Views
mosesrs
Contributor I

the project is flashiap from the SDK (latest version). here is the main source file:

 

/*
 * Copyright 2021 NXP
 * All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include "fsl_debug_console.h"
#include "fsl_flash.h"
#include "fsl_flash_ffr.h"
#include "fsl_common.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "board.h"
#if defined(LPCAC_INVALIDATE) && LPCAC_INVALIDATE
#include "fsl_cache_lpcac.h"
#endif

#include "fsl_clock.h"
/*******************************************************************************
 * Definitions
 ******************************************************************************/
#define SECTOR_INDEX_FROM_END 2U /* start from the last 2 page*/
#define BUFFER_LEN 512 / 4

/*******************************************************************************
 * Prototypes
 ******************************************************************************/
static void error_trap();
void app_finalize(void);

/*******************************************************************************
 * Variables
 ******************************************************************************/

/*! @brief Flash driver Structure */
static flash_config_t s_flashDriver;
/*! @brief Buffer for program */
static uint32_t s_buffer[BUFFER_LEN];
/*! @brief Buffer for readback */
static uint32_t s_buffer_rbc[BUFFER_LEN];

volatile uint32_t g_systickCounter;

/*******************************************************************************
 * Code
 ******************************************************************************/
void SysTick_Handler(void)
{
    if (g_systickCounter != 0U)
    {
        g_systickCounter--;
    }
}

void SysTick_DelayTicks(uint32_t n)
{
    g_systickCounter = n;
    while (g_systickCounter != 0U)
    {
    }
}

/*
 * @brief Gets called when an error occurs.
 *
 * @details Print error message and trap forever.
 */
void error_trap(void)
{
    PRINTF("\r\n\r\n\r\n\t---- HALTED DUE TO FLASH ERROR! ----");
    while (1)
    {
    }
}

/*
 * @brief Gets called when the app is complete.
 *
 * @details Print finshed message and trap forever.
 */
void app_finalize(void)
{
    /* Print finished message. */
    PRINTF("\r\n End of PFlash Example! \r\n");
    while (1)
    {
    }
}

int main()
{
    status_t status;
    uint32_t destAdrss; /* Address of the target location */
    uint32_t i, failedAddress, failedData;
    uint32_t pflashBlockBase  = 0U;
    uint32_t pflashTotalSize  = 0U;
    uint32_t pflashSectorSize = 0U;
    uint32_t PflashPageSize   = 0U;

    /* Init board hardware. */
    /* attach FRO 12M to FLEXCOMM4 (debug console) */
    CLOCK_SetClkDiv(kCLOCK_DivFlexcom4Clk, 1u);
    CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);

    BOARD_InitPins();
    BOARD_InitBootClocks();
    BOARD_InitDebugConsole();

    /* Clean up Flash, Cache driver Structure*/
    memset(&s_flashDriver, 0, sizeof(flash_config_t));

    /* Print basic information for Flash Driver API.*/
    PRINTF("\r\n Flash driver API tree demo application. \r\n");
    /* Initialize flash driver */
    PRINTF("\r\n Initializing flash driver.");
    if (FLASH_Init(&s_flashDriver) != kStatus_Success)
    {
        error_trap();
    }
    PRINTF("\r\n Flash init successfull! \r\n");

    PRINTF("\r\n Initializing FFR driver.");
    if (FFR_Init(&s_flashDriver) != kStatus_Success)
    {
        error_trap();
    }
    PRINTF("\r\n FFR init successfull! \r\n");

    /* Adjust the clock cycle for accessing the flash memory according to the system clock. */
    PRINTF("\r\n Config flash memory access time. \r\n");

    /* Set systick reload value to generate 1ms interrupt */
    if (SysTick_Config(SystemCoreClock / 1000U))
    {
        error_trap();
    }

    /* Get flash properties kFLASH_ApiEraseKey */
    FLASH_GetProperty(&s_flashDriver, kFLASH_PropertyPflashBlockBaseAddr, &pflashBlockBase);
    FLASH_GetProperty(&s_flashDriver, kFLASH_PropertyPflashSectorSize, &pflashSectorSize);
    FLASH_GetProperty(&s_flashDriver, kFLASH_PropertyPflashTotalSize, &pflashTotalSize);
    FLASH_GetProperty(&s_flashDriver, kFLASH_PropertyPflashPageSize, &PflashPageSize);

    /* print welcome message */
    PRINTF("\r\n PFlash Information:");
    /* Print flash information - PFlash. */
    PRINTF("\r\n kFLASH_PropertyPflashBlockBaseAddr = 0x%X", pflashBlockBase);
    PRINTF("\r\n kFLASH_PropertyPflashSectorSize = %d", pflashSectorSize);
    PRINTF("\r\n kFLASH_PropertyPflashTotalSize = %d", pflashTotalSize);
    PRINTF("\r\n kFLASH_PropertyPflashPageSize = 0x%X", PflashPageSize);

    uint8_t      cmpa[512u] = {0};

    if (FFR_GetCustomerData(&s_flashDriver, cmpa, 0u, 512u) != (status_t)kStatus_FLASH_Success)
    {
        return 0u;
    }

    if (FFR_CustFactoryPageWrite(&s_flashDriver, cmpa, false) != (status_t)kStatus_FLASH_Success)
    {
        return 0u;
    }

    PRINTF("\r\n DONE = 0x%X", PflashPageSize);


    return 0;
}
0 Kudos
Reply

2,537 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello @mosesrs 

Thanks for your patience. 

I have reproduced your issue on my side. And I am checking with internal. I will send to you 

after I get any update. Sorry for the inconvenient to you.

 

BR

Alice

0 Kudos
Reply

2,517 Views
mosesrs
Contributor I
Thank you. Waiting for your update.
0 Kudos
Reply

2,485 Views
mosesrs
Contributor I

Hello @Alice_Yang , any update?

Thanks

0 Kudos
Reply

2,463 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello @mosesrs 

Thanks for your patience. 

I have escalate this issue to our internal team. And I have pushed again. I will send to you with any information. Sorry for the inconvenient to you.

 

BR

Alice

0 Kudos
Reply

2,401 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello @mosesrs 

Sorry let me correct my answer.

It will go to hard fault if write all FF to CMPA. Please write a valid CMPA. Or at least the last 16 bytes can't be all F. Build and debug. It can work well. We haven't find the root cause, this is just a workaround. I will send to you after get any update.

In fact, in our real development, we're not going to write all 0xff to CMPA. Just refer the definition of CMPA to config. You can find detail of CMPA in attachment of User Manual.

 

BR

Alice

 

0 Kudos
Reply

2,367 Views
mosesrs
Contributor I

indeed, it is working. However, it seems like if seal_part=false, CRC and CMAC aren't calculated and the new data written to CMPA does not affect anything.

Can you try with seal_part=true ?

0 Kudos
Reply

2,347 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello @mosesrs 

It is not recommended to set seal_part=true before your product is in mass production.

About write CMCA, I have escalate this issue to our internal SE team. And I will send to you with any update. For now, recommend using ISP to program CMPA. It will calculate the CMPA automatically when write CMPA.

 
 

2024-09-11_13-44-39.jpg

 

BR

Alice 

0 Kudos
Reply

2,621 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello @mosesrs 

Please send your whole project to me, I help you check it on my side. Thanks.

 

BR

Alice

0 Kudos
Reply