1# RK SPI Standalone Bin 2 3This is the readme for the Das U-Boot standalone program rkspi 4 5 6How To Use 7------------------------ 8### Compile 9 101.Define the standalone load address in includes/configs/rkxxxxx_common.h 11 12```shell 13#define CONFIG_STANDALONE_LOAD_ADDR 0x40000000 14``` 15 162.Enable rkspi in defconfig 17 18``` 19CONFIG_ROCKCHIP_SPI=y 20``` 21 22### Setting SPI hardware 23 241.Setting the iomux and spiclk through: 25 26- u-boot shell command 27- define it in rkspi.c spi_hw_init 28 29Note: 30 31- spiclk is the clock for spi controller, output to IO after internal frequency division of the controller. 32 33### Load And Executable 34 351. load the bin by serial or tftp, take tftp as example: 36 37```shell 38setenv ipaddr 172.16.12.157 39setenv serverip 172.16.12.167 40tftp 0x40000000 rkspi.bin # 0x40000000 is define by CONFIG_STANDALONE_LOAD_ADDR 41``` 42 432. execute it 44 45```shell 46go 0x40000000 # 0x40000000 is define by CONFIG_STANDALONE_LOAD_ADDR 47``` 48 49## Abort Codes 50 51### Introduction 52 53```c 54int rockchip_spi_probe(u8 bus, uintptr_t base_addr, u32 rsd, u32 clock_div, u32 mode); 55``` 56 57- bus: spi bus 58- base_addr: spi register base address 59- rsd: read sample clock shift with spiclk which is controller working rate 60- clock_div: internal frequency division of the controller 61- mode: spi mode, support: 62 63```c 64#define SPI_CPHA BIT(0) /* clock phase */ 65#define SPI_CPOL BIT(1) /* clock polarity */ 66#define SPI_MODE_0 (0 | 0) /* (original MicroWire) */ 67#define SPI_MODE_1 (0 | SPI_CPHA) 68#define SPI_MODE_2 (SPI_CPOL | 0) 69#define SPI_MODE_3 (SPI_CPOL | SPI_CPHA) 70``` 71 72 73 74```c 75int rockchip_spi_claim_bus(u8 bus); 76``` 77 78- bus: spi bus 79 80 81 82```c 83void rockchip_spi_release_bus(u8 bus); 84``` 85 86- bus: spi bus 87 88 89 90```c 91int rockchip_spi_xfer(u8 bus, u8 cs, unsigned int bitlen, const void *dout, void *din, unsigned long flags); 92``` 93 94- bus: spi bus 95- cs: spi cs 96- bitlen: the transfer length in bits 97- dout: write buffer (if exits) 98- din: read buffer (if exits), if the dout and din both defined, spi work in duplex mode 99- flags: operation chip select, support: 100 101```c 102#define SPI_XFER_BEGIN BIT(0) /* Assert CS before transfer */ 103#define SPI_XFER_END BIT(1) /* Deassert CS after transfer */ 104#define SPI_XFER_ONCE (SPI_XFER_BEGIN | SPI_XFER_END) 105``` 106 107 108 109```c 110int rockchip_spi_write_then_read(u8 bus, u8 cs, 111 const u8 *opcode, size_t n_opcode, 112 const u8 *txbuf, u8 *rxbuf, size_t n_buf); 113``` 114 115- bus: spi bus 116- cs: spi cs 117- opcode: command code 118- n_opcode: the numbers of command code in bytes 119- txbuf: write buffer (if exits) 120- rxbuf: read buffer (if exits), if the dout and din both defined, spi work in duplex mode 121- n_buf: the transfer length in bytes 122 123### Demo 124 125Is right in the main function of rkspi. 126 127