darrylring opened a new pull request, #20433:
URL: https://github.com/apache/nuttx/pull/20433

   ## Summary
   
   Add support for the STM32H5's high-cycle flash region (EDATA) and an MTD 
driver to make use of it.
   
   The STM32H5 has up to 96 KiB of high-cycle flash (100,000 erase and write 
cycles) split across two banks. This PR adds code to configure the flash, 
perform writes, erases, and reads (dealing with ICACHE and flash double ECC 
errors) as well as an MTD driver which can make the region available to 
applications.
   
   As noted previously 
(https://github.com/apache/nuttx/issues/20188#issuecomment-5937385077), reading 
unwritten flash causes double ECC errors which, by default, trigger NMIs. 
Without an NMI handler, this crashes NuttX. There are three approaches to take 
here:
   
   1. Attach an NMI handler in `stm32h563xx_flash.c` that can share some state 
with the read functions to check what address is read accessed and act 
accordingly.
   2. Mask the flash double ECC error NMI before each read.
   3. Mask the flash double ECC error NMI at initialization.
   
   This PR takes approach 2 as the least invasive, though the worst performing.
   
   In addition, the EDATA flash region must either be marked as non-cacheable 
with the MPU, or be read with the ICACHE disabled. The closest precedent I can 
find is that `stm32_get_uniqueid` disables the ICACHE before reading the unique 
ID (which is in the same region as the OTP). This PR does the same, again, to 
be less invasive.
   
   ## Impact
   
   Adds new functionality, and only when `CONFIG_STM32_EDATA` is selected. The 
`FLASH_NSSR_ALL_ERRORS` macro in `arch/arm/src/stm32h5/stm32h563xx_flash.c` has 
been modified to exclude non-error bits. `CONFIG_STM32_SBS` is now selected 
when `CONFIG_STM32_EDATA` is selected to ensure the SBS clock is enabled.
   
   ## Testing
   
   This has been tested on the NUCLEO-H563ZI board with both the `cfgdata` and 
`mtdconfig_fs_test` applications.
   
   ### `cfgdata`
   
   ```
   nsh> cfgdata format
   nsh> cfgdata all
   Name                            Len   Data
   nsh> cfgdata set foo "Hello, World!"
   nsh> cfgdata set bar 1234
   nsh> cfgdata all
   Name                            Len   Data
   bar                             4     0xD2 0x04 0x00 0x00 
   foo                             14    Hello, World!
   nsh> cfgdata set bar 2345
   nsh> cfgdata all
   Name                            Len   Data
   bar                             4     0x29 0x09 0x00 0x00 
   foo                             14    Hello, World!
   nsh> cfgdata unset foo
   nsh> cfgdata all
   Name                            Len   Data
   bar                             4     0x29 0x09 0x00 0x00
   nsh> cfgdata set foo "baz"
   nsh> cfgdata all
   Name                            Len   Data
   foo                             4     baz
   bar                             4     0x29 0x09 0x00 0x00
   ```
   
   ### `mtdconfig_fs_test`
   
   The `corrupt` tests expect to be able to overwrite data and perform byte 
writes, neither of which are possible here.
   
   | Test  | Result |
   | --- | --- |
   | `test_nvs_mount`  | :white_check_mark: PASS |
   | `test_nvs_write` | :white_check_mark: PASS |
   | `test_nvs_corrupt_expire` | :x: FAIL |
   | `test_nvs_corrupted_write` | :x: FAIL |
   | `test_nvs_gc` | :white_check_mark: PASS |
   | `test_nvs_gc_3sectors` | :white_check_mark: PASS |
   | `test_nvs_corrupted_sector_close` | :x: FAIL |
   | `test_nvs_full_sector` | :white_check_mark: PASS |
   | `test_nvs_gc_corrupt_close_ate` | :x: FAIL |
   | `test_nvs_gc_corrupt_ate` | :x: FAIL |
   | `test_nvs_gc_touched_deleted_ate` | :x: FAIL |
   | `test_nvs_gc_touched_expired_ate` | :x: FAIL |
   | `test_nvs_gc_not_touched_expired_ate` | :x: FAIL |


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to