Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
STM32H743
RT-Thread一般讨论
10
STM32H743.求大佬发个drv_flash_h7.c和.h文件
发布于 2023-12-08 15:51:39 浏览:420
订阅该版
打开fal,发现新建的工程里边没有drv_flash_h7文件。
查看更多
没有认真
2023-12-08
这家伙很懒,什么也没写!
git上直接·下载源码
2
个回答
默认排序
按发布时间排序
ZWH
2023-12-10
这个人很勤快,没空留下点什么
/* * Copyright (c) 2006-2023, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes * 2018-12-5 SummerGift first version * 2019-3-2 jinsheng add Macro judgment * 2020-1-6 duminmin support single bank mode * 2020-5-17 yufanyufan77 support support H7 * 2021-3-3 zhuyf233 fix some bugs */ #include "board.h" #ifdef BSP_USING_ON_CHIP_FLASH #include "drv_config.h" #include "drv_flash.h" #if defined(RT_USING_FAL) #include "fal.h" #endif //#define DRV_DEBUG #define LOG_TAG "drv.flash" #include
/** * Read data from flash. * @note This operation's units is word. * * @param addr flash address * @param buf buffer to store read data * @param size read bytes size * * @retval The length of bytes that have been read */ int stm32_flash_read(rt_uint32_t addr, rt_uint8_t *buf, size_t size) { size_t i; if ((addr + size - 1) > FLASH_END) { LOG_E("read outrange flash size! addr is (0x%p)", (void *)(addr + size)); return -RT_ERROR; } for (i = 0; i < size; i++, buf++, addr++) { *buf = *(rt_uint8_t *) addr; } return size; } /** * Write data to flash. * @note This operation's units is word. * @note This operation must after erase. @see flash_erase. * * @param addr flash address * @param buf the write data buffer * @param size write bytes size * * @return The length of bytes that have been written */ int stm32_flash_write(rt_uint32_t addr, const rt_uint8_t *buf, size_t size) { rt_err_t result = RT_EOK; rt_uint32_t end_addr = addr + size - 1, write_addr; rt_uint32_t write_granularity = FLASH_NB_32BITWORD_IN_FLASHWORD * 4; rt_uint32_t write_size = write_granularity; rt_uint8_t write_buffer[32] = {0}; if ((end_addr) > FLASH_END) { LOG_E("write outrange flash size! addr is (0x%p)", (void *)(addr + size)); return -RT_EINVAL; } if(addr % 32 != 0) { LOG_E("write addr must be 32-byte alignment"); return -RT_EINVAL; } if (size < 1) { return -RT_EINVAL; } HAL_FLASH_Unlock(); write_addr = (uint32_t)buf; __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR); while (addr < end_addr) { if(end_addr - addr + 1 < write_granularity) { write_size = end_addr - addr + 1; for(size_t i = 0; i < write_size; i++) { write_buffer[i] = *((uint8_t *)(write_addr + i)); } write_addr = (uint32_t)((rt_uint32_t *)write_buffer); } if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_FLASHWORD, addr, write_addr) == HAL_OK) { for(rt_uint8_t i = 0; i < write_size; i++) { if (*(rt_uint8_t *)(addr + i) != *(rt_uint8_t *)(write_addr + i)) { result = -RT_ERROR; goto __exit; } } addr += write_granularity; write_addr += write_granularity; } else { result = -RT_ERROR; goto __exit; } } __exit: HAL_FLASH_Lock(); if (result != RT_EOK) { return result; } return size; } /** * Erase data on flash. * @note This operation is irreversible. * @note This operation's units is different which on many chips. * * @param addr flash address * @param size erase bytes size * * @return result */ int stm32_flash_erase(rt_uint32_t addr, size_t size) { rt_err_t result = RT_EOK; rt_uint32_t SECTORError = 0; if ((addr + size - 1) > FLASH_END) { LOG_E("ERROR: erase outrange flash size! addr is (0x%p)\n", (void *)(addr + size)); return -RT_EINVAL; } rt_uint32_t addr_bank1 = 0; rt_uint32_t size_bank1 = 0; #ifdef FLASH_BANK_2 rt_uint32_t addr_bank2 = 0; rt_uint32_t size_bank2 = 0; #endif if((addr + size) < FLASH_BANK2_BASE) { addr_bank1 = addr; size_bank1 = size; #ifdef FLASH_BANK_2 size_bank2 = 0; #endif } else if(addr >= FLASH_BANK2_BASE) { size_bank1 = 0; #ifdef FLASH_BANK_2 addr_bank2 = addr; size_bank2 = size; #endif } else { addr_bank1 = addr; size_bank1 = FLASH_BANK2_BASE - addr_bank1; #ifdef FLASH_BANK_2 addr_bank2 = FLASH_BANK2_BASE; size_bank2 = addr + size - FLASH_BANK2_BASE; #endif } /*Variable used for Erase procedure*/ FLASH_EraseInitTypeDef EraseInitStruct; /* Unlock the Flash to enable the flash control register access */ HAL_FLASH_Unlock(); EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS; EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3; SCB_DisableDCache(); if(size_bank1) { EraseInitStruct.Sector = (addr_bank1 - FLASH_BANK1_BASE) / FLASH_SECTOR_SIZE; EraseInitStruct.NbSectors = (addr_bank1 + size_bank1 -1 - FLASH_BANK1_BASE) / FLASH_SECTOR_SIZE - EraseInitStruct.Sector + 1; EraseInitStruct.Banks = FLASH_BANK_1; if (HAL_FLASHEx_Erase(&EraseInitStruct, &SECTORError) != HAL_OK) { result = -RT_ERROR; goto __exit; } } #ifdef FLASH_BANK_2 if(size_bank2) { EraseInitStruct.Sector = (addr_bank2 - FLASH_BANK2_BASE) / FLASH_SECTOR_SIZE; EraseInitStruct.NbSectors = (addr_bank2 + size_bank2 -1 - FLASH_BANK2_BASE) / FLASH_SECTOR_SIZE - EraseInitStruct.Sector + 1; EraseInitStruct.Banks = FLASH_BANK_2; if (HAL_FLASHEx_Erase(&EraseInitStruct, &SECTORError) != HAL_OK) { result = -RT_ERROR; goto __exit; } } #endif __exit: SCB_EnableDCache(); HAL_FLASH_Lock(); if (result != RT_EOK) { return result; } LOG_D("erase done: addr (0x%p), size %d", (void *)addr, size); return size; } #if defined(RT_USING_FAL) static int fal_flash_read_128k(long offset, rt_uint8_t *buf, size_t size); static int fal_flash_write_128k(long offset, const rt_uint8_t *buf, size_t size); static int fal_flash_erase_128k(long offset, size_t size); const struct fal_flash_dev stm32_onchip_flash_128k = { "onchip_flash_128k", STM32_FLASH_START_ADRESS, FLASH_SIZE_GRANULARITY_128K, (128 * 1024), {NULL, fal_flash_read_128k, fal_flash_write_128k, fal_flash_erase_128k} }; static int fal_flash_read_128k(long offset, rt_uint8_t *buf, size_t size) { return stm32_flash_read(stm32_onchip_flash_128k.addr + offset, buf, size); } static int fal_flash_write_128k(long offset, const rt_uint8_t *buf, size_t size) { return stm32_flash_write(stm32_onchip_flash_128k.addr + offset, buf, size); } static int fal_flash_erase_128k(long offset, size_t size) { return stm32_flash_erase(stm32_onchip_flash_128k.addr + offset, size); } #endif #endif /* BSP_USING_ON_CHIP_FLASH */
撰写答案
登录
注册新账号
关注者
0
被浏览
420
关于作者
yc961213911
这家伙很懒
提问
78
回答
54
被采纳
5
关注TA
发私信
相关问题
1
有关动态模块加载的一篇论文
2
最近的调程序总结
3
晕掉了,这么久都不见layer2的踪影啊
4
继续K9ii的历程
5
[GUI相关] FreeType 2
6
[GUI相关]嵌入式系统中文输入法的设计
7
20081101 RT-Thread开发者聚会总结
8
嵌入式系统基础
9
linux2.4.19在at91rm9200 上的寄存器设置
10
[转]基于嵌入式Linux的通用触摸屏校准程序
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
最新文章
1
使用百度AI助手辅助编写一个rt-thread下的ONVIF设备发现功能的功能代码
2
RT-Thread 发布 EtherKit开源以太网硬件!
3
rt-thread使用cherryusb实现虚拟串口
4
《C++20 图形界面程序:速度与渲染效率的双重优化秘籍》
5
《原子操作:程序世界里的“最小魔法单位”解析》
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
USB
DMA
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
FAL
rt-smart
ESP8266
I2C_IIC
WIZnet_W5500
ota在线升级
UART
PWM
cubemx
freemodbus
flash
packages_软件包
BSP
潘多拉开发板_Pandora
定时器
ADC
GD32
flashDB
socket
中断
Debug
编译报错
msh
SFUD
keil_MDK
rt_mq_消息队列_msg_queue
at_device
ulog
C++_cpp
本月问答贡献
踩姑娘的小蘑菇
7
个答案
3
次被采纳
张世争
8
个答案
2
次被采纳
rv666
5
个答案
2
次被采纳
用户名由3_15位
11
个答案
1
次被采纳
KunYi
6
个答案
1
次被采纳
本月文章贡献
程序员阿伟
5
篇文章
2
次点赞
hhart
3
篇文章
4
次点赞
大龄码农
1
篇文章
2
次点赞
ThinkCode
1
篇文章
1
次点赞
Betrayer
1
篇文章
1
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部