Просмотр исходного кода

【完善】SFUD 移植适配文件。

Signed-off-by: armink <armink.ztl@gmail.com>
armink 7 лет назад
Родитель
Сommit
fdb0c2f213
3 измененных файлов с 58 добавлено и 16 удалено
  1. 9 6
      samples/porting/fal_cfg.h
  2. 48 9
      samples/porting/fal_flash_sfud_port.c
  3. 1 1
      src/fal_rtt.c

+ 9 - 6
samples/porting/fal_cfg.h

@@ -28,9 +28,11 @@
 #include <rtconfig.h>
 #include <board.h>
 
+#define NOR_FLASH_DEV_NAME             "norflash0"
+
 /* ===================== Flash device Configuration ========================= */
 extern const struct fal_flash_dev stm32f2_onchip_flash;
-extern const struct fal_flash_dev nor_flash0;
+extern struct fal_flash_dev nor_flash0;
 
 /* flash device table */
 #define FAL_FLASH_DEV_TABLE                                          \
@@ -41,11 +43,12 @@ extern const struct fal_flash_dev nor_flash0;
 /* ====================== Partition Configuration ========================== */
 #ifdef FAL_PART_HAS_TABLE_CFG
 /* partition table */
-#define FAL_PART_TABLE                                                          \
-{                                                                               \
-    {FAL_PART_MAGIC_WROD,       "bl", "stm32_onchip",         0,   64*1024, 0}, \
-    {FAL_PART_MAGIC_WROD,      "app", "stm32_onchip",   64*1024,  704*1024, 0}, \
-    {FAL_PART_MAGIC_WROD, "download",    "norflash0", 1024*1024, 1024*1024, 0}, \
+#define FAL_PART_TABLE                                                               \
+{                                                                                    \
+    {FAL_PART_MAGIC_WROD,        "bl",     "stm32_onchip",         0,   64*1024, 0}, \
+    {FAL_PART_MAGIC_WROD,       "app",     "stm32_onchip",   64*1024,  704*1024, 0}, \
+    {FAL_PART_MAGIC_WROD, "easyflash", NOR_FLASH_DEV_NAME,         0, 1024*1024, 0}, \
+    {FAL_PART_MAGIC_WROD,  "download", NOR_FLASH_DEV_NAME, 1024*1024, 1024*1024, 0}, \
 }
 #endif /* FAL_PART_HAS_TABLE_CFG */
 

+ 48 - 9
samples/porting/fal_flash_sfud_port.c

@@ -23,23 +23,62 @@
  */
 
 #include <fal.h>
-
 #include <sfud.h>
 
-extern sfud_flash sfud_norflash0;
+#ifdef RT_USING_SFUD
+#include <spi_flash_sfud.h>
+#endif
+
+#ifndef NOR_FLASH_DEV_NAME
+#define NOR_FLASH_DEV_NAME             "norflash0"
+#endif
+
+static int init(void);
+static int read(long offset, uint8_t *buf, size_t size);
+static int write(long offset, const uint8_t *buf, size_t size);
+static int erase(long offset, size_t size);
+
+static sfud_flash_t sfud_dev = NULL;
+struct fal_flash_dev nor_flash0 = {NOR_FLASH_DEV_NAME, 0, 8*1024*1024, 4096, {init, read, write, erase}};
+
+static int init(void)
+{
+
+#ifdef RT_USING_SFUD
+    /* RT-Thread RTOS platform */
+    sfud_dev = rt_sfud_flash_find_by_dev_name(NOR_FLASH_DEV_NAME);
+#else
+    /* bare metal platform */
+    extern sfud_flash sfud_norflash0;
+    sfud_dev = &sfud_norflash0;
+#endif
+
+    if (NULL == sfud_dev)
+    {
+        return -1;
+    }
+
+    /* update the flash chip information */
+    nor_flash0.blk_size = sfud_dev->chip.erase_gran;
+    nor_flash0.len = sfud_dev->chip.capacity;
+
+    return 0;
+}
 
 static int read(long offset, uint8_t *buf, size_t size)
 {
-    assert(sfud_norflash0.init_ok);
-    sfud_read(&sfud_norflash0, nor_flash0.addr + offset, size, buf);
+    assert(sfud_dev);
+    assert(sfud_dev->init_ok);
+    sfud_read(sfud_dev, nor_flash0.addr + offset, size, buf);
 
     return size;
 }
 
 static int write(long offset, const uint8_t *buf, size_t size)
 {
-    assert(sfud_norflash0.init_ok);
-    if (sfud_write(&sfud_norflash0, nor_flash0.addr + offset, size, buf) != SFUD_SUCCESS)
+    assert(sfud_dev);
+    assert(sfud_dev->init_ok);
+    if (sfud_write(sfud_dev, nor_flash0.addr + offset, size, buf) != SFUD_SUCCESS)
     {
         return -1;
     }
@@ -49,12 +88,12 @@ static int write(long offset, const uint8_t *buf, size_t size)
 
 static int erase(long offset, size_t size)
 {
-    assert(sfud_norflash0.init_ok);
-    if (sfud_erase(&sfud_norflash0, nor_flash0.addr + offset, size) != SFUD_SUCCESS)
+    assert(sfud_dev);
+    assert(sfud_dev->init_ok);
+    if (sfud_erase(sfud_dev, nor_flash0.addr + offset, size) != SFUD_SUCCESS)
     {
         return -1;
     }
 
     return size;
 }
-const struct fal_flash_dev nor_flash0 = { "norflash0", 0, 8*1024*1024, 4096, {NULL, read, write, erase} };

+ 1 - 1
src/fal_rtt.c

@@ -476,7 +476,7 @@ static int char_dev_fwrite(struct dfs_fd *fd, const void *buf, size_t count)
     return ret;
 }
 
-const static struct dfs_file_ops char_dev_fops =
+static const struct dfs_file_ops char_dev_fops =
 {
     char_dev_fopen,
     RT_NULL,