-
-
Notifications
You must be signed in to change notification settings - Fork 24
spi_slave
Boris Lovosevic edited this page Jul 27, 2019
·
9 revisions
Slave mode allows other SPI masters to acces the K210 slave buffer memory.
Slave buffer can be configured as memory area of 512B ~ 1MB, with optional read only area at the end of the buffer.
Master can read from or write to slave buffer (except to the read only area.
Master <-> Slave communication is performed using the simple communication protocol:
- Master sends to the slave a command block requesting specific operation
- Master reads or sends data from/to slave depending on the requested operation
Before reading or writting any data, master must send to slave the 8-bytes command block describing the specific operation.
The structure of the command block is as follows:
Position | Length | Desctiption |
---|---|---|
0 | 1 | Command code |
1 | 3 | 24-bit slave buffer address |
4 | 3 | 24-bit data size or special meaning, depending on command |
7 | 1 | CSUM byte, generated as xor operation over 1st 7 bytes |
Here is a typical Python code used to generate the command block:
def setcmd(cmd, addr, size):
spi_cmd = bytearray(8)
spi_cmd[7] = 0
spi_cmd[0] = cmd;
spi_cmd[1] = addr & 0xff
spi_cmd[2] = (addr >> 8) & 0xff
spi_cmd[3] = (addr >> 16) & 0xff
spi_cmd[4] = size & 0xff
spi_cmd[5] = (size >> 8) & 0xff
spi_cmd[6] = (size >> 16) & 0xff
for i in range(7):
spi_cmd[7] ^= spi_cmd[i]
return spi_cmd
The following commands are accepted by K210 SPI slave:
Command code | Command | Description |
---|---|---|
1 | SLAVE_CMD_TEST |
Test command, slave responds by sending requeste number of bytes of requested value address field must be set to the requested byte balue (0~255) size field must be set to the requested number of bytes |
2 | SLAVE_CMD_INFO |
Request K210 SPI slave info Slave send the 18-byte info block containing the slave driver version, size of the slave buffer and size of the read only area See below for more information |
3 | SLAVE_CMD_STATUS |
Request the status of the previously executed command Slave responds by sending 26-bytes status block See below for more information |
4 | SLAVE_CMD_WRITE |
Master writes data block to slave buffer. address field must be set to the slave buffer address size field must be set to the data block size |
5 | SLAVE_CMD_WRITE_CSUM |
Master writes data block to slave buffer. address field must be set to the slave buffer address size field must be set to the data block size 2-bytes CRC16 csum must be appended to the data block by the master |
6 | SLAVE_CMD_READ |
Master reads data block from slave buffer. address field must be set to the slave buffer address size field must be set to the data block size |
7 | SLAVE_CMD_READ_CSUM |
Master reads data block from slave buffer. address field must be set to the slave buffer address size field must be set to the data block size 2-bytes CRC16 csum is appended to the data block by the slave |
- Maix-M1 schematic
- Maix-Bit schematic
- Maix-Go schematic
- Kendryte K210 datasheet
- RISC-V ISA Design
- RISC-V ISA Manual
- Forum
- MicroPython documentation
If you find this project useful, you can contribute by making a donation