KW21 256KB with FlexNVM module

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

KW21 256KB with FlexNVM module

Jump to solution
1,371 Views
seanwu
Contributor IV

Dear Sir,

I get an issue about KW21 256KB with NVM module.

I created a new example project about ZigBee using BeeKit.

Example is: Ha IASCIE.

Codebase is BeeStack Codebase 4.0.1.

pastedImage_0.png

Target board is TWR-KW21D256.

pastedImage_1.png

Enable NVM storage module.

And KW21 256 uses FlexNVM as storage.

#if (gTargetTWR_KW21D256_d == 1)

  #define gNvUseFlexNVM_d TRUE

#endif

pastedImage_2.png

Enable ZTC.

pastedImage_3.png

The device type is Coordinator.

pastedImage_4.png

Other settings are default, and export the project to IAR.

When run the example, all LEDs are always on.

pastedImage_5.png

I traced the code, it stops at while loop. This means NvModuleInit() is failed.

#if gNvStorageIncluded_d

  if (NvModuleInit() != gNVM_OK_c)

  {

/* NV Module has failed initialization. Lock up node */

TurnOnLeds();

while(1);

  }

#endif

I also traced the code more, and found the error point is:

  /* Initialize flash HAL driver */

NV_FlashInit(&mNvConfig);

#if (gNvUseFlexNVM_d == TRUE) && (gNV_DEBLOCK_SIZE_c != 0)  /* FlexNVM */

  /* check data flash IFR map */

  if(mNvConfig.EEEBlockSize == 0)

  {

    return gNVM_NvWrongFlashDataIFRMap_c;

  }

EEEDataSetSize and DEPartitionCode are 0.

FTFL_FCCOB6 and FTFL_FCCOB7 are 0xFF.

pastedImage_6.png

But I see SIM_FCFG1 register. EESIZE is 0x2 means 4k.

pastedImage_7.png

I am confused about the two differences, and why the FlexNVM module initialize failed?

The example code is generated from Beekit, I think it should work normally.

Please help to check and resolve this issue.

Thanks.

BR,

Sean Wu

Weikeng Inc.

0 Kudos
1 Solution
1,052 Views
mihaidragnea
NXP Employee
NXP Employee

Hello Sean,

It seems that your board is not configured to use Flex-Memory feature. Please note that each mass erase of the chip will set D-FLASH block as normal flash.

Try to use the following code to partition correctly your device:

- define somewhere in NV_Flash.c file the below 2 lines:

#define gFlashConfigUpdateAddress_c       0x40CuL

uint8_t FlashConfig[] = {0xFE, 0xFF, 0xFF, 0xFF};

- Add the following code just after NV_FlashInit(&mNvConfig) statement:

if(gNV_OK_c == NV_FlashEraseAllBlock(&mNvConfig))

{    

  (void)NV_FlashProgramLongword(&mNvConfig, gFlashConfigUpdateAddress_c, 4, (uint32_t)&FlashConfig[0]);    

}

- After the device mass erase will occur, you will loose the connection with the debugger, which is normal to happen. Close the current debug session and replace the previous lines of code with this one:

(void)NV_DEFlashPartition(&mNvConfig, gNV_EEPROM_DATASET_SIZE_CODE_c, gNV_EEPROM_BACKUP_SIZE_CODE_c);

- Start a new debug session and set a breakpoint at the line above. When the breakpoint is hit, execute this line of code (step over) and then exit the debug session.

- Remove the line above and the definitions from the start. Basically, you should get the same code as was before all these modifications.

- Run your application, it should work now.

Please let me know if this solved your issue.

  

Regards,

Mihai

View solution in original post

2 Replies
1,053 Views
mihaidragnea
NXP Employee
NXP Employee

Hello Sean,

It seems that your board is not configured to use Flex-Memory feature. Please note that each mass erase of the chip will set D-FLASH block as normal flash.

Try to use the following code to partition correctly your device:

- define somewhere in NV_Flash.c file the below 2 lines:

#define gFlashConfigUpdateAddress_c       0x40CuL

uint8_t FlashConfig[] = {0xFE, 0xFF, 0xFF, 0xFF};

- Add the following code just after NV_FlashInit(&mNvConfig) statement:

if(gNV_OK_c == NV_FlashEraseAllBlock(&mNvConfig))

{    

  (void)NV_FlashProgramLongword(&mNvConfig, gFlashConfigUpdateAddress_c, 4, (uint32_t)&FlashConfig[0]);    

}

- After the device mass erase will occur, you will loose the connection with the debugger, which is normal to happen. Close the current debug session and replace the previous lines of code with this one:

(void)NV_DEFlashPartition(&mNvConfig, gNV_EEPROM_DATASET_SIZE_CODE_c, gNV_EEPROM_BACKUP_SIZE_CODE_c);

- Start a new debug session and set a breakpoint at the line above. When the breakpoint is hit, execute this line of code (step over) and then exit the debug session.

- Remove the line above and the definitions from the start. Basically, you should get the same code as was before all these modifications.

- Run your application, it should work now.

Please let me know if this solved your issue.

  

Regards,

Mihai

1,052 Views
seanwu
Contributor IV

Dear Sir,

Thanks for your support, Your method is OK.

And I have resolved the issue before.

My method is add parameter in IAR like below:

In the project options, go to the Download Tab in the Debugger category.  Check the box "Override default .board file"  Then click the Edit button

a.png

Select the memory range for the program flash, starting at address 0x0.  Click the Edit button.

b.png

In the Extra Parameters field, add --partition 0x0432 after –erase_flexNVM.  Click OK.

c.png

04: FlexNVM Partition Code(DEPART).

32: EEPROM Data Set Size(3: EEESPLIT, 2: EEESIZE).

More description about “--partition”:

The "--partition" argument is used to program EEPROM Size and FlexNVM Partition Code in the Data Flash IFR.

The value after"--partition" should be 2 bytes. The LS byte is the EEPROM Size and the MS byte is the FlexNVM Partition Code.

Refer to device data sheet for EEPROM Size and Partition Code settings.

Note1: Using "--partition" arg will erase all program flash memory, data flash memory, data flash IFR space, EEPROM backup memory, and FlexRAM.

Thanks.

BR,

Sean

0 Kudos