u-boot-2010.03移植spi flash支持读、写、擦除操作!!!
开发环境:
MCU: NXP LPC1788
u-boot: u-boot-2010.03
SPI Flash: AT45DB321D
由于ATMEL的spi flash在u-boot中已经实现,我们就不要去写AT45DB321D的驱动了,现在考虑SPI总线的问题(u-boot中的spi驱动在driver/spi目录中),在driver/spi目录中可以看到各种芯片的spi总线实现,不过lpc1788是没有的,别动别动看到了一个soft_spi.c,好了现在spi总线的驱动也不用写了,直接用soft spi。
在lpc1788的配置文件中加入以下内容:
-
#define CONFIG_CMD_SF //加入cmd_sf.c文件的编译,实现u-boot中spi flash的操作命令sf
-
#define CONFIG_SOFT_SPI //加入driver/spi/soft_spi.c文件编译,实现软件spi总线
-
#define CONFIG_SPI_FLASH //加入driver/mtd/spi/spi_flash.c文件编译
-
#define CONFIG_SPI_FLASH_ATMEL //加入driver/mtd/spi/atmel.c文件编译,实现AT45的驱动
-
-
-
#define CONFIG_SF_DEFAULT_MODE SPI_MODE_1
-
#define SPI_SCL spi_scl
-
#define SPI_SDA spi_sda
-
#define SPI_READ spi_read()
-
void spi_scl(int);
-
void spi_sda(int);
-
unsigned char spi_read(void);
-
#define SPI_DELAY udelay(2)
在board/nxp/lpc1788/board.c文件中加入以下内容:
-
void spi_scl(int bit)
-
{
-
struct lpc178x_gpio_dsc dsc;
-
dsc.port = 2;
-
dsc.pin = 22;
-
lpc178x_gpout_set(&dsc, bit);
-
}
-
-
void spi_sda(int bit)
-
{
-
struct lpc178x_gpio_dsc dsc;
-
dsc.port = 2;
-
dsc.pin = 27;
-
lpc178x_gpout_set(&dsc, bit);
-
}
-
-
unsigned char spi_read(void)
-
{
-
struct lpc178x_gpio_dsc dsc;
-
dsc.port = 2;
-
dsc.pin = 26;
-
return (unsigned char)lpc178x_gpin_get(&dsc);
-
}
-
<span style="font-size: 14px; line-height: 1.5;">int spi_cs_is_valid(unsigned int bus, unsigned int cs)</span>
-
{
-
return bus == 0 && cs == 0;
u-boot中spi flash的操作命令:
1、选择spi flash
sf probe 0
2、擦除命令
sf erase 0 0x210 //注意擦除长度一定是0x210的整数倍
3、读命令
sf read addr offset len
4、写命令
sf write addr offset len
参考一下内容:
阅读(6005) | 评论(0) | 转发(0) |