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

   ## Summary
   
   H5 implementation of functions defined in `include/nuttx/progmem.h`. The 
driver supports a subset of the flash peripheral functions.
     - Assumes non-secure memory accesses. Does not check for memory protection 
mechanisms.
   
   References implementation in `arch/arm/src/stm32h7/stm32h743xx_flash.c`, 
with slight difference in how bank1/2 is handled because banks share registers 
on the H5 but are separate in the H7.
   
   ## Impact
   
   This adds a few new options to the H5 Kconfig, which will include the new 
flash file when progmem is enabled.
   
   ## Testing
   
   OS: Docker container of Ubuntu 24.04 running on Ubuntu 24.04 host.
   CPU: STM32H563ZIT6U
   Compiler: Arm GNU Toolchain 13.3.Rel1 (Build arm-13.24)
   Target: Nucleo-H563ZI
   
   Testing was done using a custom application, called from NSH, to write and 
erase flash blocks. Breakpoints were placed between each erase/write step, and 
the flash memory was inspected using the debugger.
   
   Testing application:
   ```c
   #include <stdint.h>
   #include <stdio.h>
   #include <stdlib.h>
   #include <string.h>
   #include <errno.h>
   
   #include <nuttx/config.h>
   #include <nuttx/mtd/mtd.h>
   #include <nuttx/progmem.h>
   
   #include <sys/types.h>
   
   #if !defined(CONFIG_ARCH_HAVE_PROGMEM) || !defined(CONFIG_MTD_PROGMEM)
   #  error "progmemtest requires CONFIG_MTD_PROGMEM"
   #endif
   
   #define BLOCK_SIZE (8 * 1024)
   #define BANK2_STARTADDR 0x08100000
   
   static struct mtd_dev_s *progmem_mtd;
   static uint8_t *buff;
   
   static int mount_progmem(void) {
     int result = 0;
     if (progmem_mtd)
       {
         return 0;
       }
   
     progmem_mtd = progmem_initialize();
     if (progmem_mtd)
       {
         printf("Progmem device initialized.\n");
       }
   
     return result;
   }
   
   uint8_t* create_and_fill_buffer(void) {
     uint32_t pattern = 0xDEADBEEF;
     uint8_t *buffer = (uint8_t *)malloc(BLOCK_SIZE);
   
     if (!buffer)
       {
         printf("Failed to allocate buffer: %s\n", strerror(errno));
         return NULL;
       }
     
     for (size_t i = 0; i < BLOCK_SIZE; i += sizeof(pattern))
       {
         if (i + sizeof(pattern) <= BLOCK_SIZE)
           {
             memcpy(buffer + i, &pattern, sizeof(pattern));
           }
       }
     return buffer; 
   }
   
   int main(int argc, char *argv[])
   {
     ssize_t ret;
     uint32_t addr;
   
     buff = create_and_fill_buffer();
   
     if (buff)
       {
         /* Erase all blocks of memory in bank 2 */
         for (int i = 128; i <= 255; i++)
           {
             ret = up_progmem_eraseblock(i);
             if (ret < 0)
               {
                 printf("Progmem erase block %d failed: %d\n", i, ret);
                 goto exit_with_free;
               }
           }
         
         for (int i = 0; i <= 127; i++)
         {
           addr = BANK2_STARTADDR + (i * BLOCK_SIZE);
   
           ret = up_progmem_write(addr, (const void *)buff, BLOCK_SIZE);
           if (ret < 0)
           {
             printf("Progmem write failed: %d\n", ret);
             goto exit_with_free;
           }
         }
   
         for (int i = 128; i <= 255; i++)
           {
             ret = up_progmem_eraseblock(i);
             if (ret < 0)
               {
                 printf("Progmem erase block %d failed: %d\n", i, ret);
                 goto exit_with_free;
               }
           }
   
   exit_with_free:
         free(buff);
       }
     
     return 0;
   }
   ``` 
   
   
   


-- 
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: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to