arm板子写flash(2)

本文是关于在IMX6 ARM板上写入SPI Flash的第二部分,主要介绍如何测试写入操作的正确性。通过写入并读取exe、pdf和bmp文件来验证数据完整性,经过测试,程序能成功且正确地将这些文件写入Flash。
摘要由CSDN通过智能技术生成

arm板子写flash(2)

imx6arm板子写spiflash的代码第一篇博客地址在下面,这里主要写一下测试,我们不知道我们写进入的数据是否正确,前面把写进入的数据读出去进行打印,当文件为几兆字节时,密密麻麻的二级制怎么看, 这里测试写入一些exe,pdf文件进行测试。
http://blog.csdn.net/chenqianleo/article/details/73658493

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/types.h>
#include <linux/spi/spidev.h>
#include <string.h>
/*
*  write a file to spi_flash
  */
#define W25_WRITE_ENABLE                0x06
#define W25_WRITE_DISABLE               0x04
#define W25_READ_STATUS_1               0x05
#define W25_READ_STATUS_2               0x35
#define W25_WRITE_STATUS                0x01
#define w25_WRITE_SATTUS_ENABLE 0x50
#define W25_READ_DATA                   0x03
#define W25_READ_FAST_DATA              0x0B
#define W25_ERASE_SECTOR                0x20
#define W25_ERASE_BLOCK                 0xD8
#define W25_ERASE_CHIP                  0xc7
#define W25_PAGE_PROGRAM                0x02
#define W25_CHIP_ID                     0x9F
#define RDSR_CNT                        1000

#define W25_SR_BUSY                     0x01
#define FLASH_MAX_SIZE                  (8*1024*1024) 
#define ONE_SELECTOR_SIZE               (4*1024)
#define WRITE_READ_ONCE_SIZE            256
#define ARRAY_SIZE(a)                   (sizeof(a) / sizeof((a)[0]))

static const char* spi_device = "/dev/spidev2.2";
static unsigned char mode;
static unsigned char bits = 8;
static unsigned int speed = 3000000;
static unsigned short delay;
static unsigned char buf[256] = {
  0};
static unsigned char rxbuffer[1];   
static unsigned char txbuffer[260];

static int getFileSize(const char* name);
static void dis_array(const char* info , const unsigned char* buf, unsigned int len);
static int w25_write_read(int fd , const char* wbuf,unsigned int wlen,
    const char* rbuf , unsigned int rlen);
static int wait_for_idle(int fd);
static int write_spiflash(int fd ,char* buf, int offset , 
    int address_one, int address_two , int address_three);
static int write_spiflash_finally(int fd ,char* buf, int offset , int num, 
    int address_one, int address_two , int address_three);
static void read_spiflash(int fd, int address_one , int address_two,
    int address_three);
static 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值