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

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

被折叠的 条评论
为什么被折叠?



