不管是在RT-Thread Studio 还是 自己下载之后打算进行移植,都需要把fal_cfg.h
文件进行重新的编辑 。对于ST的单片机而言使用RT-Thread的时候可能会比较方便,使能片内Flash的时候就会自动的生成drv_stm32f4.c
的文件,根据这个文件下我们需要在fal_cfg.h
中实现一些宏定义:
#define FLASH_SIZE_GRANULARITY_16K (4 * 16 * 1024)
#define FLASH_SIZE_GRANULARITY_64K (1 * 64 * 1024)
#define FLASH_SIZE_GRANULARITY_128K (7 * 128 * 1024)
#define STM32_FLASH_START_ADRESS_16K STM32_FLASH_START_ADRESS
#define STM32_FLASH_START_ADRESS_64K (STM32_FLASH_START_ADRESS_16K + FLASH_SIZE_GRANULARITY_16K)
#define STM32_FLASH_START_ADRESS_128K (STM32_FLASH_START_ADRESS_64K + FLASH_SIZE_GRANULARITY_64K)
/* ===================== Flash device Configuration ========================= */
extern const struct fal_flash_dev stm32_onchip_flash_16k;
extern const struct fal_flash_dev stm32_onchip_flash_64k;
extern const struct fal_flash_dev stm32_onchip_flash_128k;
/* flash device table */
#define FAL_FLASH_DEV_TABLE \
{ \
&stm32_onchip_flash_16k, \
&stm32_onchip_flash_64k, \
&stm32_onchip_flash_128k, \
}
同时在fal_cfg.h
中需要把分区重新定义,需要注意在F4中分区和F1是不一样的。
#define FAL_PART_TABLE \
{ \
{FAL_PART_MAGIC_WROD, "bootloader", "onchip_flash_16k", 0 , FLASH_SIZE_GRANULARITY_16K , 0}, \
{FAL_PART_MAGIC_WROD, "param", "onchip_flash_64k", 0 , FLASH_SIZE_GRANULARITY_64K , 0}, \
{FAL_PART_MAGIC_WROD, "app", "onchip_flash_128k", 0 , FLASH_SIZE_GRANULARITY_128K, 0}, \
}
之后再main函数中加入fal_init()
之后就好了
结果如下:
msh >fal probe
No flash device or partition was probed.
Usage: fal probe [dev_name|part_name] - probe flash device or partition by given name.
[I/FAL] ==================== FAL partition table ====================
[I/FAL] | name | flash_dev | offset | length |
[I/FAL] -------------------------------------------------------------
[I/FAL] | Bootloader | stm32_onchip_flash_16k | 0x00000000 | 0x00010000 |
[I/FAL] | Param | stm32_onchip_flash_64k | 0x00000000 | 0x00010000 |
[I/FAL] | App | stm32_onchip_flash_128k | 0x00000000 | 0x000e0000 |
[I/FAL] =============================================================
msh >