Hardfault when using eeprom in KW36 BLE demo

cancel
Showing results for 
Search instead for 
Did you mean: 

Hardfault when using eeprom in KW36 BLE demo

Jump to solution
275 Views
Contributor III

I want to use eeprom in KW36 BLE demo. In frdmkw36_wireless_examples_bluetooth_hrs_freertos, I set gAppUseNvm_d and gNvUseFlexNVM_d to 1. In __NvModuleInit(), it configures eeprom and reset. However, after it reset, in hardware_init(), it calls NV_ReadHWParameters(&gHardwareParameters), and then it run into HardFault_Handler()! How to use eeprom in BLE demo?

in __NvModuleInit(), before I call FLASH_ProgramPartition(...),the data at 0x7f800:

pastedImage_1.png

after I call  FLASH_ProgramPartition(...):

pastedImage_2.png

pastedImage_3.png

Labels (1)
1 Solution
23 Views
NXP Employee
NXP Employee

I am not an expert (yet) with FlexNVM. I did some check today, but couldn't find definite answer.

Our colleagues designed FlexNVM in a relatively complicated way to learn and use. (Just search FlexNVM, there are many questions raised.) also documentation on this can be further improved.

I have 2 guesses for your issue.

(1) is that after partitioning, with default values in codes, all 256KB D-Flash are turned into EEPROM backup space. My guess is in this case, the flash space is no longer accessible with addresses. So when trying to load data in FREESCALE_PROD_DATA area (e.g. *((uint32_t*)gRngSeedStorageAddr_d) ), a bus access error would occur and results as a hard fault.

It is easy to test this, just try: * (uint32_t *) 0x0007F7F8

This would read the address in the previous flash sector (shown in your picture as 0xFFFFFFFF). Or try any other address in the D-FLASH area. If all accesses can trigger hard fault, then this region is no longer accessible.

Btw, in your debugger (memory) window, it shows values of 0xFFFFFFFFs, but this maybe cached. And could become ???????? as well.

(2) is that in KW36 user manual, section 29.4.11.16 Program Partition command.

It says "Prior to launching the Program Partition command, the data flash IFR must be in an erased state, which can be accomplished by executing the Erase All Blocks command or by an external request ..."

The "external request" is probably submitted by a debugger. Then, from user codes, the only way is to issue an Erase All Blocks command to the whole D-Flash area. (This is my understanding to the sentence.)

And when looking at the KW36 demo codes, this is clearly not done before the partition command. And it is not designed this way, because the FREESCALE_PROD_DATA is placed at the end of the D-FLASH. A Erase-All would remove the factory production data.

Summary, I would do it this way,

- copy out the FREESCALE_PROD_DATA, and relocate it to a different flash sector

- do a full erase of D-flash, and then partition the flash. (Note that this is only need 1 time, can be done at factory manufacturing)

- then don't access the EEPROM Backup space with address, but only via the FlexRAM.

View solution in original post

5 Replies
23 Views
NXP Employee
NXP Employee

The last 2KB in flash is production data, as you pointed out already. I heard it is advised not to touch this flash sector.

And when calling FLASH_ProgramPartition(), the comments say:

(around line 2557, NV_Flash.c)

    /* If no EEPROM set, partition the device as follows:
          -> DFLASH size = 0,
          -> EEPROM backup size = 256KB,
          -> EEPROM dataset size = 2KB,
          -> FLEXRAM = 8KB
    */

So all 256KB including the PROD_DATA are reconfigured as EEPROM backup memory.

I suspect there must be some conflicts between the PROD_DATA and EEPROM backup memory.

When you have a hard_fault, could you take some more analysis to see how the hard_fault is entered? Which function was executing before hard fault triggered?

0 Kudos
23 Views
Contributor III

Thanks for youe response!

When I try to read the data in FREESCALE_PROD_DATA, it will trigger hard fault. Such as NV_ReadHWParameters(&gHardwareParameters), or seed = *((uint32_t*)gRngSeedStorageAddr_d); in RNG_Init().

0 Kudos
24 Views
NXP Employee
NXP Employee

I am not an expert (yet) with FlexNVM. I did some check today, but couldn't find definite answer.

Our colleagues designed FlexNVM in a relatively complicated way to learn and use. (Just search FlexNVM, there are many questions raised.) also documentation on this can be further improved.

I have 2 guesses for your issue.

(1) is that after partitioning, with default values in codes, all 256KB D-Flash are turned into EEPROM backup space. My guess is in this case, the flash space is no longer accessible with addresses. So when trying to load data in FREESCALE_PROD_DATA area (e.g. *((uint32_t*)gRngSeedStorageAddr_d) ), a bus access error would occur and results as a hard fault.

It is easy to test this, just try: * (uint32_t *) 0x0007F7F8

This would read the address in the previous flash sector (shown in your picture as 0xFFFFFFFF). Or try any other address in the D-FLASH area. If all accesses can trigger hard fault, then this region is no longer accessible.

Btw, in your debugger (memory) window, it shows values of 0xFFFFFFFFs, but this maybe cached. And could become ???????? as well.

(2) is that in KW36 user manual, section 29.4.11.16 Program Partition command.

It says "Prior to launching the Program Partition command, the data flash IFR must be in an erased state, which can be accomplished by executing the Erase All Blocks command or by an external request ..."

The "external request" is probably submitted by a debugger. Then, from user codes, the only way is to issue an Erase All Blocks command to the whole D-Flash area. (This is my understanding to the sentence.)

And when looking at the KW36 demo codes, this is clearly not done before the partition command. And it is not designed this way, because the FREESCALE_PROD_DATA is placed at the end of the D-FLASH. A Erase-All would remove the factory production data.

Summary, I would do it this way,

- copy out the FREESCALE_PROD_DATA, and relocate it to a different flash sector

- do a full erase of D-flash, and then partition the flash. (Note that this is only need 1 time, can be done at factory manufacturing)

- then don't access the EEPROM Backup space with address, but only via the FlexRAM.

View solution in original post

23 Views
Contributor III

Thanks for youe response!

I set the flash as below:

pastedImage_1.jpg

 and I set the backup size to 128KB:

pastedImage_2.jpg

It looks like work.

23 Views
NXP Employee
NXP Employee

Glad it works!

Just want to point out small things in your picture.

- FREESCALE_PROD_DATA only needs 2KB I think, but you assigned a size of 7KB (0x1C00). Seemingly unnecessary.

- After 128KB reserved for EEPROM, there should be 128KB (0x20000) left in D-Flash. But now you are only use 0x4000 + 0x1C00 of those. About ~100KB in the device not allocated and not seen from the current memory map.

0 Kudos