全能電路設計實戰

2023年10月4日 星期三

Linux kernel : SPI device 兩種存取模式


Raw SPI Device Access

 $ sudo modprobe spi_bcm2835

 $ ls -l /dev/spidev*

crw-rw---- 1 root spi 153, 0 Nov 19 11:13 /dev/spidev0.0

crw-rw---- 1 root spi 153, 1 Nov 19 11:13 /dev/spidev0.1

Now everything is ready to access the SPI devices from a user-space application using the SPIDEV interface. There is abundant documentation in the Internet on how to use SPIDEV in application code. 



Access SPI Flash as MTD

sudo modprobe mtd
sudo modprobe spi-nor
sudo insmod m25p80.ko


/ # cat /proc/mtd
dev: size erasesize name
mtd0: 00020000 00020000 "flash_uboot_env"
mtd1: 00a00000 00020000 "flash_linux_image"
mtd2: 005e0000 00020000 "flash_jffs2"
mtd3: 00100000 00010000 "spi_flash_part0"
mtd4: 00300000 00010000 "spi_flash_part1"