Linux下spi读写flash

Linux系统中配置与操作SPI Flash的实践
本文档详细介绍了如何在Linux设备树中添加SPI Flash支持,内核菜单配置相应的驱动,并提供了读写SPI Flash的C语言实现。通过示例代码展示了如何进行文件的读写操作,以及进行闪存擦除的功能。

1.在设备树中添加flash

&dspi	{
   
   
		fpga_flash@3 {
   
   
                compatible = "w25q32";
                reg = <3>;
                spi-max-frequency = <10000000>;
        };
};

2.在内核菜单添加对应驱动

│-> Device Drivers
│ -> Memory Technology Device (MTD) support (MTD [=y])
│ (1) -> Self-contained MTD device drivers
│<*> Support most SPI Flash chips (AT26DF, M25P, W25X, …)

3.读写/dev/下flash文件

#include <stdint.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/types.h>
#include <linux/spi/spidev.h>

#define FLASH_MAX_SIZE      (4 * 1024 * 1024)
#define FLASH_PAGE_SIZE     (64*1024)

static void pabort(const char *s)
{
   
   
    perror(s);
    abort();
}

static uint32_t mode;
static uint8_t bits = 8;
static uint32_t speed = 10000000;
static uint16_t delay;

/*
 * flash 读写配置 
*/
static void 
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值