blob: 06e0008b9f9c54bf1c23bf88d19bc848733a7b28 [file] [log] [blame]
Sean Anderson445fd222020-06-24 06:41:24 -04001.. SPDX-License-Identifier: GPL-2.0+
2.. Copyright (C) 2020 Sean Anderson <seanga2@gmail.com>
3
4Maix Bit
5========
6
7Several of the Sipeed Maix series of boards cotain the Kendryte K210 processor,
8a 64-bit RISC-V CPU. This processor contains several peripherals to accelerate
9neural network processing and other "ai" tasks. This includes a "KPU" neural
10network processor, an audio processor supporting beamforming reception, and a
11digital video port supporting capture and output at VGA resolution. Other
12peripherals include 8M of SRAM (accessible with and without caching); remappable
13pins, including 40 GPIOs; AES, FFT, and SHA256 accelerators; a DMA controller;
14and I2C, I2S, and SPI controllers. Maix peripherals vary, but include spi flash;
15on-board usb-serial bridges; ports for cameras, displays, and sd cards; and
16ESP32 chips. Currently, only the Sipeed Maix Bit V2.0 (bitm) is supported, but
17the boards are fairly similar.
18
19Documentation for Maix boards is available from
20`Sipeed's website <http://dl.sipeed.com/MAIX/HDK/>`_.
21Documentation for the Kendryte K210 is available from
22`Kendryte's website <https://kendryte.com/downloads/>`_. However, hardware
23details are rather lacking, so most technical reference has been taken from the
24`standalone sdk <https://github.com/kendryte/kendryte-standalone-sdk>`_.
25
26Build and boot steps
27--------------------
28
29To build u-boot, run
30
31.. code-block:: none
32
33 make sipeed_maix_bitm_defconfig
34 make CROSS_COMPILE=<your cross compile prefix>
35
36To flash u-boot to a maix bit, run
37
38.. code-block:: none
39
40 kflash -tp /dev/<your tty here> -B bit_mic u-boot-dtb.bin
41
42Boot output should look like the following:
43
44.. code-block:: none
45
46 U-Boot 2020.04-rc2-00087-g2221cc09c1-dirty (Feb 28 2020 - 13:53:09 -0500)
47
48 DRAM: 8 MiB
49 In: serial@38000000
50 Out: serial@38000000
51 Err: serial@38000000
52 =>
53
54Loading Images
55^^^^^^^^^^^^^^
56
57To load a kernel, transfer it over serial.
58
59.. code-block:: none
60
61 => loady 80000000 1500000
62 ## Switch baudrate to 1500000 bps and press ENTER ...
63
64 *** baud: 1500000
65
66 *** baud: 1500000 ***
67 ## Ready for binary (ymodem) download to 0x80000000 at 1500000 bps...
68 C
69 *** file: loader.bin
70 $ sz -vv loader.bin
71 Sending: loader.bin
72 Bytes Sent:2478208 BPS:72937
73 Sending:
74 Ymodem sectors/kbytes sent: 0/ 0k
75 Transfer complete
76
77 *** exit status: 0 ***
78 ## Total Size = 0x0025d052 = 2478162 Bytes
79 ## Switch baudrate to 115200 bps and press ESC ...
80
81 *** baud: 115200
82
83 *** baud: 115200 ***
84 =>
85
86Running Programs
87^^^^^^^^^^^^^^^^
88
89Binaries
90""""""""
91
92To run a bare binary, use the ``go`` command:
93
94.. code-block:: none
95
96 => loady
97 ## Ready for binary (ymodem) download to 0x80000000 at 115200 bps...
98 C
99 *** file: ./examples/standalone/hello_world.bin
100 $ sz -vv ./examples/standalone/hello_world.bin
101 Sending: hello_world.bin
102 Bytes Sent: 4864 BPS:649
103 Sending:
104 Ymodem sectors/kbytes sent: 0/ 0k
105 Transfer complete
106
107 *** exit status: 0 ***
108 (CAN) packets, 5 retries
109 ## Total Size = 0x000012f8 = 4856 Bytes
110 => go 80000000
111 ## Starting application at 0x80000000 ...
112 Example expects ABI version 9
113 Actual U-Boot ABI version 9
114 Hello World
115 argc = 1
116 argv[0] = "80000000"
117 argv[1] = "<NULL>"
118 Hit any key to exit ...
119
120Legacy Images
121"""""""""""""
122
123To run legacy images, use the ``bootm`` command:
124
125.. code-block:: none
126
127 $ tools/mkimage -A riscv -O u-boot -T standalone -C none -a 80000000 -e 80000000 -d examples/standalone/hello_world.bin hello_world.img
128 Image Name:
129 Created: Thu Mar 5 12:04:10 2020
130 Image Type: RISC-V U-Boot Standalone Program (uncompressed)
131 Data Size: 4856 Bytes = 4.74 KiB = 0.00 MiB
132 Load Address: 80000000
133 Entry Point: 80000000
134
135 $ picocom -b 115200 /dev/ttyUSB0i
136 => loady
137 ## Ready for binary (ymodem) download to 0x80000000 at 115200 bps...
138 C
139 *** file: hello_world.img
140 $ sz -vv hello_world.img
141 Sending: hello_world.img
142 Bytes Sent: 4992 BPS:665
143 Sending:
144 Ymodem sectors/kbytes sent: 0/ 0k
145 Transfer complete
146
147 *** exit status: 0 ***
148 CAN) packets, 3 retries
149 ## Total Size = 0x00001338 = 4920 Bytes
150 => bootm
151 ## Booting kernel from Legacy Image at 80000000 ...
152 Image Name:
153 Image Type: RISC-V U-Boot Standalone Program (uncompressed)
154 Data Size: 4856 Bytes = 4.7 KiB
155 Load Address: 80000000
156 Entry Point: 80000000
157 Verifying Checksum ... OK
158 Loading Standalone Program
159 Example expects ABI version 9
160 Actual U-Boot ABI version 9
161 Hello World
162 argc = 0
163 argv[0] = "<NULL>"
164 Hit any key to exit ...
165
166Over- and Under-clocking
167------------------------
168
169To change the clock speed of the K210, you will need to enable
170``CONFIG_CLK_K210_SET_RATE`` and edit the board's device tree. To do this, add a
171section to ``arch/riscv/arch/riscv/dts/k210-maix-bit.dts`` like the following:
172
173.. code-block:: none
174
175 &sysclk {
176 assigned-clocks = <&sysclk K210_CLK_PLL0>;
177 assigned-clock-rates = <800000000>;
178 };
179
180There are three PLLs on the K210: PLL0 is the parent of most of the components,
181including the CPU and RAM. PLL1 is the parent of the neural network coprocessor.
182PLL2 is the parent of the sound processing devices. Note that child clocks of
183PLL0 and PLL2 run at *half* the speed of the PLLs. For example, if PLL0 is
184running at 800 MHz, then the CPU will run at 400 MHz. This is the example given
185above. The CPU can be overclocked to around 600 MHz, and underclocked to 26 MHz.
186
187It is possible to set PLL2's parent to PLL0. The plls are more accurate when
188converting between similar frequencies. This makes it easier to get an accurate
189frequency for I2S. As an example, consider sampling an I2S device at 44.1 kHz.
190On this device, the I2S serial clock runs at 64 times the sample rate.
191Therefore, we would like to run PLL2 at an even multiple of 2.8224 MHz. If
192PLL2's parent is IN0, we could use a frequency of 390 MHz (the same as the CPU's
193default speed). Dividing by 138 yields a serial clock of about 2.8261 MHz. This
194results in a sample rate of 44.158 kHz---around 50 Hz or .1% too fast. If,
195instead, we set PLL2's parent to PLL1 running at 390 MHz, and request a rate of
1962.8224 * 136 = 383.8464 MHz, the achieved rate is 383.90625 MHz. Dividing by 136
197yields a serial clock of about 2.8228 MHz. This results in a sample rate of
19844.107 kHz---just 7 Hz or .02% too fast. This configuration is shown in the
199following example:
200
201.. code-block:: none
202
203 &sysclk {
204 assigned-clocks = <&sysclk K210_CLK_PLL1>, <&sysclk K210_CLK_PLL2>;
205 assigned-clock-parents = <0>, <&sysclk K210_CLK_PLL1>;
206 assigned-clock-rates = <390000000>, <383846400>;
207 };
208
209There are a couple of quirks to the PLLs. First, there are more frequency ratios
210just above and below 1.0, but there is a small gap around 1.0. To be explicit,
211if the input frequency is 100 MHz, it would be impossible to have an output of
21299 or 101 MHz. In addition, there is a maximum frequency for the internal VCO,
213so higher input/output frequencies will be less accurate than lower ones.
214
215Technical Details
216-----------------
217
218Boot Sequence
219^^^^^^^^^^^^^
220
2211. ``RESET`` pin is deasserted.
2222. Both harts begin executing at ``0x00001000``.
2233. Both harts jump to firmware at ``0x88000000``.
2244. One hart is chosen as a boot hart.
2255. Firmware reads value of pin ``IO_16`` (ISP).
226
227 * If the pin is low, enter ISP mode. This mode allows loading data to ram,
228 writing it to flash, and booting from specific addresses.
229 * If the pin is high, continue boot.
2306. Firmware reads the next stage from flash (SPI3) to address ``0x80000000``.
231
232 * If byte 0 is 1, the next stage is decrypted using the built-in AES
233 accelerator and the one-time programmable, 128-bit AES key.
234 * Bytes 1 to 4 hold the length of the next stage.
235 * The SHA-256 sum of the next stage is automatically calculated, and verified
236 against the 32 bytes following the next stage.
2377. The boot hart sends an IPI to the other hart telling it to jump to the next
238 stage.
2398. The boot hart jumps to ``0x80000000``.
240
241Memory Map
242^^^^^^^^^^
243
244========== ========= ===========
245Address Size Description
246========== ========= ===========
2470x00000000 0x1000 debug
2480x00001000 0x1000 rom
2490x02000000 0xC000 clint
2500x0C000000 0x4000000 plic
2510x38000000 0x1000 uarths
2520x38001000 0x1000 gpiohs
2530x40000000 0x400000 sram0 (non-cached)
2540x40400000 0x200000 sram1 (non-cached)
2550x40600000 0x200000 airam (non-cached)
2560x40800000 0xC00000 kpu
2570x42000000 0x400000 fft
2580x50000000 0x1000 dmac
2590x50200000 0x200000 apb0
2600x50200000 0x80 gpio
2610x50210000 0x100 uart0
2620x50220000 0x100 uart1
2630x50230000 0x100 uart2
2640x50240000 0x100 spi slave
2650x50250000 0x200 i2s0
2660x50250200 0x200 apu
2670x50260000 0x200 i2s1
2680x50270000 0x200 i2s2
2690x50280000 0x100 i2c0
2700x50290000 0x100 i2c1
2710x502A0000 0x100 i2c2
2720x502B0000 0x100 fpioa
2730x502C0000 0x100 sha256
2740x502D0000 0x100 timer0
2750x502E0000 0x100 timer1
2760x502F0000 0x100 timer2
2770x50400000 0x200000 apb1
2780x50400000 0x100 wdt0
2790x50410000 0x100 wdt1
2800x50420000 0x100 otp control
2810x50430000 0x100 dvp
2820x50440000 0x100 sysctl
2830x50450000 0x100 aes
2840x50460000 0x100 rtc
2850x52000000 0x4000000 apb2
2860x52000000 0x100 spi0
2870x53000000 0x100 spi1
2880x54000000 0x200 spi3
2890x80000000 0x400000 sram0 (cached)
2900x80400000 0x200000 sram1 (cached)
2910x80600000 0x200000 airam (cached)
2920x88000000 0x20000 otp
2930x88000000 0xC200 firmware
2940x8801C000 0x1000 riscv priv spec 1.9 config
2950x8801D000 0x2000 flattened device tree (contains only addresses and
296 interrupts)
2970x8801f000 0x1000 credits
298========== ========= ===========