Looking for something similar to the EEPROM memory block on the LPC546xx parts.
The MCX parts seem to have a flash ROMAPI but its really poorly documented and lacks clear examples. CFPA vs. CMPA? Incrementing fields? Lots of pre-assigned locations? Unclear block size restrictions? Factory vs. infield vs keystore?
Plus its in ROM so its not even possible to follow the code. Reminds me of the LPC546xx USB functions which were likewise difficult to understand due to the poor documentation.
Oh and I have read AN14259 which helps a little but not enough.
All I want is a persistent but not OTP memory area that I can store application specific constants in. I'm probably missing something so please point me in the right direction.
Thanks in advance for any help!
解決済! 解決策の投稿を見る。
Hi Pablo,
Thank you for your continued support with this.
I think I have finally achieved a solution to this and I can now place my data into the free area in the CMPA page. It all hinges on understanding the MBC and unfortunately the reference manual is not very clear about how it is used. However the Security Reference Manual chapter 21 is more helpful and once I configuring the MBC the ROM flash APIs started working as I expected.
I really think some better examples in this area would have saved me a lot of time. The flash hiding one is probably the nearest to what is required but without a good explaination of what it is actually going on is just too unclear to be useful.
Best wishes and thank you once again for your help,
Andy
Hi @andyjackson,
The MCXN features a Protected Flash Region (PFR), which includes two configurable pages: CFPA (Customer In-field Programmable Area) and CMPA (Customer Manufacturing/Factory Programmable Area). Both of these areas can be written to multiple times.
As you mentioned, Application Note AN14259 provides examples of how to modify the CFPA bit fields using the ROM APIs.
You can also use the MCUXpresso Secure Provisioning Tool for this purpose. The tool’s User Guide includes Section 5.2.8: OTP/PFR/IFR/BCA/FCF Configuration, which explains how to use the GUI to modify the CFPA bit fields. The GUI also provides detailed descriptions of each field.
Additionally, Application Note AN14178 may be helpful, as it demonstrates how to perform flash read and write operations using the Flash Command Controller instead of the ROM API.
Also, there is an example on the MCXN947 SDK called mcxromapi_flash_hiding_cm33_core0 that you may be interest in, this example demonstrates a program showing flash hiding.
Best Regards,
Pablo
Hi Pablo,
Thank you for your reply. I want to be able to read and save persistent application data at runtime so the Secure Provisioning Tool is not an option.
The main flash banks might be reflashed during firmware updates so using that doesn't seem to be an option either.
Also, a reboot after updating is likewise not possible as this would disrupt execution so this seems to rule out the CFPA which leaves the CMPA.
Looking at AN14259 almost all locations in the CFPA and CMPA appear to have predefined usage so I'm not sure where I can safely write to anyway.
I tried playing with FFR_GetCustKeystoreData/FFR_CustKeystoreWrite and FFR_GetCustomerData/FFR_CustFactoryPageWrite and whilst reads appeared to work, writes seemed to always generate hard faults. Plus I'm guessing at how to use them properly as I'm not aware of an code example for them.
I can't help feeling that I'm missing something as a small user EEPROM like area seems essential for most microcontroller applications. Unfortunately with a nearly 4000 page reference manual its hard to digest all the information.
Best wishes,
Andy
Hi @andyjackson
I understand that Reference Manuals may be overwhelming.
The following community post may be helpful for more information on the ROM API.
Re: Using MCX N ROM API for Internal Flash Erase/Programming - NXP Community
Also, example mcxromapi_flash_hiding_cm33_core0 may be helpful since it show how MBC provides read, write, and execute access control per block to internal flash memory.
Best Regards,
Pablo
Hello again Pablo,
Thanks for your last reply. I've been digging into this further and according to the MCXNx4x_IFR.xlsx spreadsheet in the Reference Manual 0x01004200 to 0x01005FFF of the CMPA is customer defined which seems perfect. However, I have yet to find a way of accessing this area.
FFR_GetCustomerData() will let me read up to byte 0x1FF of the CMPA 8Kbyte page and the standard flash functions FLASH_Read/Program/Erase etc only seem to work within the main program flash. How can I access the rest of the CMPA page?
I've seen examples where the first 512 bytes of the CMPA page can be updated but nothing that accesses the rest of the page. Any ideas?
Best wishes,
Andy
Hi @andyjackson,
To program and read the CMPA region, you can use the FLASH APIs. Typically, the function used to write CMPA data is ffr_cust_factory_page_write. You can find more information about this function in section 13.2.2.10 of the reference manual.
Additionally, the following community post may be helpful for understanding how to use the FLASH API to update the CMPA flash region.
MCXN5 CMPA Write Fails - NXP Community
Best Regards,
Pablo
Hi Pablo,
Thank you for your continued support with this.
I think I have finally achieved a solution to this and I can now place my data into the free area in the CMPA page. It all hinges on understanding the MBC and unfortunately the reference manual is not very clear about how it is used. However the Security Reference Manual chapter 21 is more helpful and once I configuring the MBC the ROM flash APIs started working as I expected.
I really think some better examples in this area would have saved me a lot of time. The flash hiding one is probably the nearest to what is required but without a good explaination of what it is actually going on is just too unclear to be useful.
Best wishes and thank you once again for your help,
Andy