RT-Thread使用----OTA功能(1)----使能FAL

2 篇文章 0 订阅

1、新建基于F407ZG工程

开发板使用的是正点原子STM32F407ZG探索者。新建工程工打开CubeMx进行SPI接口、RCC时钟、USART1配置如下:

         生成代码,关闭Cubemx。必须关闭Cubemx,rtthread studio才会更新工程

2、配置使能rtt的SPI flash和FAL功能

  3、修改FLA分区信息

        编译报错,增加fal_cfg.h头文件路径。

        我们使用的是W25Q128芯片,芯片大小为65536*256bit即16M,对fal_flash_sfud_port.c文件进行更改。

struct fal_flash_dev nor_flash0 =
{
    .name       = FAL_USING_NOR_FLASH_DEV_NAME,
    .addr       = 0,
    .len        = 16 * 1024 * 1024,         //w25q128 大小为65536*256 = 16777216byte = 16M   128Mbit
    .blk_size   = 4096,
    .ops        = {init, read, write, erase},
    .write_gran = 1
};

        我们没有使能片上的flash,需要对分区表进行调整,修改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>

#define NOR_FLASH_DEV_NAME             "W25Q128"

/* ===================== Flash device Configuration ========================= */
extern struct fal_flash_dev nor_flash0;

/* flash device table */
#define FAL_FLASH_DEV_TABLE                                          \
{                                                                    \
    &nor_flash0,                                                     \
}
/* ====================== Partition Configuration ========================== */
#ifdef FAL_PART_HAS_TABLE_CFG
/* partition table */
#define FAL_PART_TABLE                                                               \
{                                                                                    \
    {FAL_PART_MAGIC_WORD, "download",   NOR_FLASH_DEV_NAME,          0,  896*1024,   0}, \
    {FAL_PART_MAGIC_WORD, "factory",    NOR_FLASH_DEV_NAME,   896*1024,  896*1024,   0}, \
    {FAL_PART_MAGIC_WORD, "filesystem", NOR_FLASH_DEV_NAME,  2*896*1024, 14592*1024, 0}, \
}
#endif /* FAL_PART_HAS_TABLE_CFG */

#endif /* _FAL_CFG_H_ */

修改main.c文件,进行fal初始化

#include <rtthread.h>
#include "fal.h"

int main(void)
{
    fal_init();
    rt_kprintf("Hello RT-Thread!\r\n");
    while (1)
    {
        rt_thread_mdelay(1000);
    }
    return RT_EOK;
}

3、SPI接口使能及挂载

        修改board.h文件,使能SPI1接口

        增加drv_spiflash.c文件,用于SPI flash的挂载。

#include "board.h"
#include <rtthread.h>
#include <rtdevice.h>
#include "drv_spi.h"
#include "drv_config.h"
#include <string.h>
#include "spi_flash_sfud.h"

static int rt_hw_spi_flash_init(void)
{
    __HAL_RCC_GPIOF_CLK_ENABLE();
    rt_hw_spi_device_attach("spi1", "spi10", GPIOB, GPIO_PIN_14);

    if (RT_NULL == rt_sfud_flash_probe("W25Q128", "spi10"))
    {
        return -RT_ERROR;
    };
    return RT_EOK;
}
/* 导出到自动初始化 */
INIT_COMPONENT_EXPORT(rt_hw_spi_flash_init);

4、下载验证

 

        

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值