当前位置: 首页 > news >正文

【env环境】rtthread5.1.0使用fal组件

配置

board/Kconfig

    config BSP_USING_ON_CHIP_FLASHbool "Enable On Chip Flash"default n

image.png

image.png

cp rt-thread/components/fal/samples/porting/fal_cfg.h board/

fal_cfg.h

/** Copyright (c) 2006-2018, RT-Thread Development Team** SPDX-License-Identifier: Apache-2.0** Change Logs:* Date           Author       Notes* 2018-05-17     armink       the first version*/#ifndef _FAL_CFG_H_
#define _FAL_CFG_H_#include <rtconfig.h>
#include <board.h>// 芯片型号:STM32407VET6 512Kb
// 起始地址
#define STM32_FLASH_START_ADRESS_16K ADDR_FLASH_SECTOR_0
#define STM32_FLASH_START_ADRESS_64K ADDR_FLASH_SECTOR_4
#define STM32_FLASH_START_ADRESS_128K ADDR_FLASH_SECTOR_5// 大小
#define FLASH_SIZE_GRANULARITY_16K (ADDR_FLASH_SECTOR_4 - ADDR_FLASH_SECTOR_0)  // 4个16K, 总共64K
#define FLASH_SIZE_GRANULARITY_64K (ADDR_FLASH_SECTOR_5 - ADDR_FLASH_SECTOR_4)  // 1个64K
#define FLASH_SIZE_GRANULARITY_128K (ADDR_FLASH_SECTOR_8 - ADDR_FLASH_SECTOR_5) // 3个128K, 总共384K/* ===================== 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, \}
/* ====================== Partition Configuration ========================== */
#ifdef FAL_PART_HAS_TABLE_CFG
/* partition table */
#define FAL_PART_TABLE                                                                   \{                                                                                    \{FAL_PART_MAGIC_WORD, "bl_a", "onchip_flash_16k", 0, 64 * 1024, 0},              \{FAL_PART_MAGIC_WORD, "bl_b", "onchip_flash_64k", 0, 64 * 1024, 0},              \{FAL_PART_MAGIC_WORD, "app", "onchip_flash_128k", 0, 256 * 1024, 0},             \{FAL_PART_MAGIC_WORD, "backup", "onchip_flash_128k", 256 * 1024, 384 * 1024, 0}, \}
#endif /* FAL_PART_HAS_TABLE_CFG */#endif /* _FAL_CFG_H_ */

main.c

/** Copyright (c) 2006-2018, RT-Thread Development Team** SPDX-License-Identifier: Apache-2.0** Change Logs:* Date           Author       Notes* 2018-11-06     SummerGift   first version*/#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>
#include <fal.h>/* defined the LED0 pin: PB1 */
#define LED0_PIN    GET_PIN(B, 1)int main(void)
{fal_init();int count = 1;/* set LED0 pin mode to output */rt_pin_mode(LED0_PIN, PIN_MODE_OUTPUT);while (count++){rt_pin_write(LED0_PIN, PIN_HIGH);rt_thread_mdelay(500);rt_pin_write(LED0_PIN, PIN_LOW);rt_thread_mdelay(500);}return RT_EOK;
}

烧录

scons -c
scons -j8
bash flash.bash

flash.bash

#!/bin/bash# Use first argument as ELF file, default to rtthread.elf
ELF_FILE="${1:-rt-thread.elf}"# OpenOCD configuration files
INTERFACE_CFG="/usr/local/share/openocd/scripts/interface/stlink-v2.cfg"
TARGET_CFG="/usr/local/share/openocd/scripts/target/stm32f4x.cfg"# Print info in English
echo "Flashing firmware using OpenOCD: $ELF_FILE"
echo "Interface: CMSIS-DAP"
echo "Target MCU: STM32F4xx"# Flash command
openocd \-f "$INTERFACE_CFG" \-f "$TARGET_CFG" \-c "init; program $ELF_FILE verify; reset run; exit"
 \ | /
- RT -     Thread Operating System/ | \     5.1.0 build Jul 15 2025 22:48:222006 - 2024 Copyright by RT-Thread team
[D/FAL] (fal_flash_init:47) Flash device |         onchip_flash_16k | addr: 0x08000000 | len: 0x00010000 | blk_size: 0x00004000 |initialized finish.
[D/FAL] (fal_flash_init:47) Flash device |         onchip_flash_64k | addr: 0x08010000 | len: 0x00010000 | blk_size: 0x00010000 |initialized finish.
[D/FAL] (fal_flash_init:47) Flash device |        onchip_flash_128k | addr: 0x08020000 | len: 0x00060000 | blk_size: 0x00020000 |initialized finish.
[I/FAL] ==================== FAL partition table ====================
[I/FAL] | name   | flash_dev         |   offset   |    length  |
[I/FAL] -------------------------------------------------------------
[I/FAL] | bl_a   | onchip_flash_16k  | 0x00000000 | 0x00010000 |
[I/FAL] | bl_b   | onchip_flash_64k  | 0x00000000 | 0x00010000 |
[I/FAL] | app    | onchip_flash_128k | 0x00000000 | 0x00040000 |
[I/FAL] | backup | onchip_flash_128k | 0x00040000 | 0x00060000 |
[I/FAL] =============================================================
[I/FAL] RT-Thread Flash Abstraction Layer initialize success.

文章转载自:
http://age.bdypl.cn
http://centinewton.bdypl.cn
http://aneurism.bdypl.cn
http://bardling.bdypl.cn
http://adversative.bdypl.cn
http://aglimmer.bdypl.cn
http://aasvogel.bdypl.cn
http://chlorpicrin.bdypl.cn
http://borage.bdypl.cn
http://austin.bdypl.cn
http://alchemize.bdypl.cn
http://aspirin.bdypl.cn
http://blithe.bdypl.cn
http://belie.bdypl.cn
http://briefcase.bdypl.cn
http://afebrile.bdypl.cn
http://aureola.bdypl.cn
http://backdate.bdypl.cn
http://blastomycetous.bdypl.cn
http://bunker.bdypl.cn
http://bordetela.bdypl.cn
http://avo.bdypl.cn
http://botulinus.bdypl.cn
http://armor.bdypl.cn
http://cardiogram.bdypl.cn
http://arose.bdypl.cn
http://agonisingly.bdypl.cn
http://afips.bdypl.cn
http://bryozoa.bdypl.cn
http://brahminism.bdypl.cn
http://www.dtcms.com/a/280338.html

相关文章:

  • AI的外挂知识库,RAG检索增强生成技术
  • 【PTA数据结构 | C语言版】将表达式树转换成中缀表达式
  • 数仓面试题
  • 2025最新国产用例管理工具评测:Gitee Test、禅道、蓝凌测试、TestOps 哪家更懂研发协同?
  • docker停止所有容器和删除所有镜像
  • 从一道题目(阿里2014 Crackme_2)开启unidbg还原算法入门(转载)
  • 强化学习书籍
  • vscode 打开c++文件注释乱码
  • 分布式存储之Ceph使用指南--部署篇(未完待续)
  • Claude 背后金主亚马逊亲自下场,重磅发布 AI 编程工具 Kiro 现已开启免费试用
  • 【交叉编译报错】fatal: not a git repository (or any of the parent directories): .git
  • 分布式全局唯一ID生成:雪花算法 vs Redis Increment,怎么选?
  • 内存的基础相关知识,什么是内存,内存管理
  • 死锁问题以及读写锁和自旋锁介绍【Linux操作系统】
  • Spring 中 @Component和@Bean注解的区别
  • 为何说分布式 AI 推理已成为下一代计算方式
  • SpringBoot 2.x→3.0升级实战:Jakarta EE兼容性改造清单
  • kotlin布局交互
  • Kotlin聚合方法
  • Python 操作Excel工作表:添加、删除、移动、隐藏
  • 前端安全指南:防御XSS与CSRF攻击
  • 给 Excel 整列空格文字内容加上前缀:像给文字穿衣服一样简单!
  • Excel制作玫瑰图
  • PostgreSQL FATAL: sorry, too many clients already 连接数爆满的处理办法
  • excel 通过openpyxl表格下载和插入图片
  • 京东平台商品评论接口接入指南与代码实现
  • 国内大模型技术与应用综述
  • 区块链:以太坊侧链Polygon
  • 日常运维问题汇总-59
  • STL的一些知识点