diff --git a/i18n/ja/code.json b/i18n/ja/code.json index 6c853257..b96c8549 100644 --- a/i18n/ja/code.json +++ b/i18n/ja/code.json @@ -726,7 +726,7 @@ "description": "mars info" }, "mars.page.info10": { - "message": "Raspberry pi 3Bケースに対応", + "message": "Raspberry Pi 3Bケースに対応", "description": "mars info" }, "mars.tech.info": { @@ -958,39 +958,39 @@ "description": "cv1800b" }, "homepage.corporations.Documentstitle": { - "message": "Milk-V Documents", + "message": "Milk-Vドキュメント", "description": "homepage documents" }, "homepage.corporations.Documentswords": { - "message": "View our documentation for technical support", + "message": "テクニカルサポートのために私達のドキュメントを見る", "description": "homepage documents" }, "homepage.corporations.CommunityBotton": { - "message": "Milk-V Community", + "message": "Milk-Vコミュニティ", "description": "Milk-V Community booton" }, "homepage.corporations.WhyRVBotton": { - "message": "Why RISC-V ?", + "message": "RISC-Vを選ぶ理由", "description": "Why RISC-V ? booton" }, "homepage.corporations.duo": { - "message": "Dual cores up to 1GHz (optional RISC-V / ARM), up to 256MB of memory, and a 1TOPS@INT8 TPU. Capable of running both Linux and RTOS simultaneously, with rich I/O interfaces.", + "message": "最大1GHzのデュアルコア(RISC-V/ARM切り替え可)、最大256MBのメモリ、1TOPS@INT8のNPUを搭載。豊富なインターフェースでLinuxとRTOSを同時に実行可能です。", "description": "duo description" }, "homepage.corporations.duolearnmore": { - "message": "Learn more", + "message": "もっと見る", "description": "duo Learn more" }, "homepage.corporations.duobuynow": { - "message": "Buy Now", + "message": "購入", "description": "duo buy" }, "homepage.corporations.pioneer": { - "message": "Milk-V Pioneer is a developer motherboard based on SOPHON SG2042 in a standard mATX form factor. It is the first choice for RISC-V developers and hardware pioneers to experience the cutting edge technology of RISC-V.", + "message": "Milk-V Pioneerは、標準的なmATXフォームファクターでSOPHON SG2042をベースにした開発者向けマザーボードです。RISC-V開発者やハードウェアパイオニアがRISC-Vの最先端技術を体験するための第一選択です。", "description": "pioneer description" }, "homepage.corporations.pioneerlearnmore": { - "message": "Learn more", + "message": "もっと見る", "description": "pioneer Learn more" }, "homepage.corporations.pioneerbuynow": { @@ -998,79 +998,79 @@ "description": "pioneer buy" }, "homepage.corporations.marscm": { - "message": "The Mars Compute Module is a System on Module (SoM) based on a the StarFive JH7110 System on Chip (SoC). ", + "message": "MarsコンピュートモジュールはStarFive JH7110 SoCを基に作られたSoMです。", "description": "mars cm" }, "homepage.corporations.mars": { - "message": "Milk-V Mars is a high-performance RISC-V Single Board Computer (SBC) the size of a credit card, built on the StarFive JH7110. An RJ45 Ethernet port that supports PoE (Power over Ethernet), and an M.2 E-Key slot for a WIFI/BT module. It also includes a 4-lane MIPI CSI and a 2-lane MIPI CSI, along with a 40-pin GPIO. ", + "message": "Milk-V Marsは、クレジットカードサイズの高性能RISC-Vシングルボードコンピュータ(SBC)で、StarFive JH7110を基に作られています。PoE(Power over Ethernet)をサポートするRJ45イーサネットポートや、WIFI/BTモジュール用のM.2 E-Keyスロットが備わっています。また、4レーンのMIPI CSIと2レーンのMIPI CSI、さらに40ピンのGPIOも搭載しています。 ", "description": "mars" }, "homepage.corporations.marslearnmore": { - "message": "Learn more", + "message": "もっと見る", "description": "mars Learn more" }, "homepage.corporations.marsbuynow": { - "message": "Buy Now", + "message": "購入", "description": "mars buy now" }, "homepage.corporations.meles": { - "message": "Milk-V Meles is a credit card-sized, single-board computer (SBC) based on the TH1520. It is powered by a Quad Core RISC-V 64GCV C910, capable of running up to 1.85GHz. This SBC is packed with rich interfaces and boasts powerful computing and AI capabilities, making it an ideal RISC-V intelligent hardware platform for hobbyists, makers, engineers, teachers, and students.", + "message": "Milk-V Melesは、TH1520を基にしたクレジットカードサイズのシングルボードコンピュータ(SBC)です。クアッドコアのRISC-V 64GCV C910を搭載し、最大1.85GHzで動作します。このSBCは豊富なインターフェースを備え、強力な計算能力とAI機能を誇り、愛好家、メイカー、エンジニア、教師、学生にとって理想的なRISC-Vインテリジェントハードウェアプラットフォームです。", "description": "meles " }, "homepage.corporations.melesbuynow": { - "message": "Buy Now", + "message": "購入", "description": "meles buy" }, "homepage.corporations.meleslearnmore": { - "message": "Learn more", + "message": "もっと見る", "description": "meles learn more" }, "homepage.corporations.vega": { - "message": "Milk-V Vega is a compact and low-density box-style open-source 10 Gigabit network switch developed by Milk-V for the next generation of network architecture. It serves as a unified platform for various services such as broadband, voice, video, and surveillance.", + "message": "Milk-V Vegaは、次世代のネットワークアーキテクチャのためにMilk-Vが開発したコンパクトで低密度のボックス型オープンソース10ギガビットネットワークスイッチです。ブロードバンド、音声、ビデオ、監視などのさまざまなサービスを統合するプラットフォームとして機能します。", "description": "vega " }, "homepage.corporations.vegabuynow": { - "message": "Buy Now", + "message": "購入", "description": "vega buy" }, "homepage.corporations.vegalearnmore": { - "message": "Learn more", + "message": "もっと見る", "description": "vega learn more" }, "homepage.corporations.docslearnmore": { - "message": "Learn more", + "message": "もっと見る", "description": "docs learn more" }, "homepage.corporations.joinus": { - "message": "Join Us to Share More", + "message": "参加してシェアしよう", "description": "Join Us to Share More" }, "homepage.corporations.emailtitle_1": { - "message": "Having questions?", + "message": "質問がありますか?", "description": "Having questions?" }, "homepage.corporations.emailtitle_2": { - "message": "Get in touch with us to resolve!", + "message": "ご連絡ください。", "description": "Get in touch with us to resolve!" }, "homepage.corporations.salesdepartment": { - "message": "Sales Department", + "message": "セールス部門", "description": "Sales Department" }, "homepage.corporations.devdepartment": { - "message": "Development Department", + "message": "開発部門", "description": "Development Department" }, "homepage.corporations.customerdepartment": { - "message": "Customer Support Department", + "message": "カスタマーサポート部門", "description": "Customer Support Department" }, "homepage.corporations.emailto": { - "message": "This e-mail is to", + "message": "宛先", "description": "This e-mail is to" }, "homepage.corporations.emailmessage": { - "message": "Message", + "message": "本文", "description": "main message" }, "homepage.corporations.companyname": { @@ -1086,11 +1086,11 @@ "description": "footer company address" }, "Send": { - "message": "Send", + "message": "送信", "description": "Send" }, "Embracing": { - "message": "Milk-VでRISC-Vをつくる", + "message": "Milk-VでRISC-Vを迎え入れる", "description": " " }, "overview": { @@ -1126,7 +1126,7 @@ "description": " " }, "ChoosingUs.item3.title": { - "message": "あんしんのアフターサポート", + "message": "安心のアフターサポート", "description": " " }, "ChoosingUs.item1.info": { @@ -1146,7 +1146,7 @@ "description": " " }, "Startingfrom": { - "message": "ここから始める", + "message": "開始価格", "description": " " }, "manykernels": { @@ -1154,7 +1154,7 @@ "description": " " }, "large": { - "message": "ほかよりももっとパワフル。", + "message": "もっとパワフル。", "description": " " }, "DualCore": { @@ -1182,7 +1182,7 @@ "description": " " }, "Interfaces": { - "message": "インターフェイスはRaspberry pi互換", + "message": "インターフェイスはRaspberry Pi互換", "description": " " }, "AUDIO": { diff --git a/i18n/ja/docusaurus-plugin-content-docs/current/duo/_category_.json b/i18n/ja/docusaurus-plugin-content-docs/current/duo/_category_.json new file mode 100644 index 00000000..898927aa --- /dev/null +++ b/i18n/ja/docusaurus-plugin-content-docs/current/duo/_category_.json @@ -0,0 +1,9 @@ +{ + "label": "🍐 Duo", + "position": 1, + "link": { + "type": "generated-index", + "slug": "/duo", + "description": "Hello, I am Milk-V Duo" + } +} diff --git a/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/_category_.json b/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/_category_.json new file mode 100644 index 00000000..051767fe --- /dev/null +++ b/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/_category_.json @@ -0,0 +1,9 @@ +{ + "label": "🖥️ App Development", + "position": 30, + "link": { + "type": "generated-index", + "slug": "/duo/app-dev", + "description": "Application Development" + } +} diff --git a/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/pinmux.md b/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/pinmux.md new file mode 100644 index 00000000..cb7f2e05 --- /dev/null +++ b/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/pinmux.md @@ -0,0 +1,159 @@ +--- +sidebar_label: 'pinmux' +sidebar_position: 05 +--- + +Note that many pin functions of the Duo series are multiplexed. When using applications (such as wiringX, pinpong) to control the functions of each pin, it is important to confirm the current state of the pin to ensure it matches the desired functionality. If it doesn't, you can use the `duo-pinmux` command to switch it to the desired function. + +### The pin names for Duo and Duo256M + +For Duo pin multiplexing function, please refer to: [Duo GPIO Pinout](https://milkv.io/docs/duo/getting-started/duo#duo-gpio-pinout) + +For Duo256M pin multiplexing function, please refer to: [Duo256M GPIO Pinout](https://milkv.io/docs/duo/getting-started/duo256m#duo256m-gpio-pinout) + +
+ +| PIN NAME | Pin# | Pin# | PIN NAME | +| -------- | :-----------------------------: | :------------------------------: | -------- | +| GP0 |
1
|
40
| VBUS | +| GP1 |
2
|
39
| VSYS | +| GND |
3
|
38
| GND | +| GP2 |
4
|
37
| 3V3_EN | +| GP3 |
5
|
36
| 3V3(OUT) | +| GP4 |
6
|
35
| | +| GP5 |
7
|
34
| | +| GND |
8
|
33
| GND | +| GP6 |
9
|
32
| GP27 | +| GP7 |
10
|
31
| GP26 | +| GP8 |
11
|
30
| RUN | +| GP9 |
12
|
29
| GP22 | +| GND |
13
|
28
| GND | +| GP10 |
14
|
27
| GP21 | +| GP11 |
15
|
26
| GP20 | +| GP12 |
16
|
25
| GP19 | +| GP13 |
17
|
24
| GP18 | +| GND |
18
|
23
| GND | +| GP14 |
19
|
22
| GP17 | +| GP15 |
20
|
21
| GP16 | +| |   | | | +| GP25 |
LED
| | | + +
+ +### The pin names for DuoS + +For DuoS pin multiplexing function, please refer to: [DuoS GPIO Pinout](https://milkv.io/docs/duo/getting-started/duos#duos-gpio-pinout) + +#### Header J3 + +GPIO on `Header J3` use 3.3V logic levels. + +
+ +| PIN NAME | PIN# | PIN# | PIN NAME | +|:---------|:--------------------------------:|:-------------------------------:|:---------| +| 3V3 |
1
|
2
| VSYS(5V) | +| B20 |
3
|
4
| VSYS(5V) | +| B21 |
5
|
6
| GND | +| B18 |
7
|
8
| A16 | +| GND\* |
9
|
10
| A17 | +| B11 |
11
|
12
| B19 | +| B12 |
13
|
14
| GND | +| B22 |
15
|
16
| A20 | +| 3V3 |
17
|
18
| A19 | +| B13 |
19
|
20
| GND | +| B14 |
21
|
22
| A18 | +| B15 |
23
|
24
| B16 | +| GND |
25
|
26
| A28 | + +
+ +*GND\*: Pin 9 is a low-level GPIO in the V1.1 version of the hardware, and is GND in the V1.2 version and later.* + +#### Header J4 + +GPIO on `Header J4` use 1.8V logic levels. + +Most of the pins on this header have dedicated functions, such as MIPI DSI signals, Touch Screen signals, and audio signals. If there is no special requirement, it is not recommended to use the pins on this header as GPIO. + +
+ +| PIN NAME | PIN# | PIN# | PIN NAME | +|----------|:-------------------------------:|:--------------------------------:|:------------| +| VSYS(5V) |
52
|
51
| AUDIO_OUT_R | +| B1 |
50
|
49
| AUDIO_OUT_L | +| B2 |
48
|
47
| AUDIO_IN_R | +| B3 |
46
|
45
| AUDIO_IN_L | +| E2 |
44
|
43
| 3V3 | +| E1 |
42
|
41
| C18 | +| E0 |
40
|
39
| C19 | +| GND |
38
|
37
| GND | +| C20 |
36
|
35
| C16 | +| C21 |
34
|
33
| C17 | +| GND |
32
|
31
| GND | +| C14 |
30
|
29
| C12 | +| C15 |
28
|
27
| C13 | + +
+ +### Pin multiplexing configuration + +The following uses Duo as an example to introduce how to configure pin multiplexing. + +Executing the `duo-pinmux` command directly allows you to view the usage instructions +``` +[root@milkv-duo]~# duo-pinmux +pinmux for duo +duo-pinmux -p <== List all pins +duo-pinmux -l <== List all pins and its func +duo-pinmux -r pin <== Get func from pin +duo-pinmux -w pin/func <== Set func to pin +``` + +To check the multiplexing status of a specific pin, such as pin 1 on Duo, you need to know the name of that pin. As indicated in the diagram above, the name of pin 1 is `GP0`. To view its multiplexing status, use the command `duo-pinmux -r` followed by the pin name +``` +[root@milkv-duo]~# duo-pinmux -r GP0 +GP0 function: +[ ] JTAG_TDI +[ ] UART1_TX +[ ] UART2_TX +[ ] GP0 +[v] IIC0_SCL +[ ] WG0_D0 +[ ] DBG_10 +``` +You can see that the current function is `IIC0_SCL`, indicating it is configured as the SCL pin for I2C0. If you want to configure pin 1 as a GPIO, you can use the following command: `duo-pinmux -w pin_name/function` +``` +duo-pinmux -w GP0/GP0 +``` +Now, check the multiplexing status of the pin again +``` +[root@milkv-duo]~# duo-pinmux -r GP0 +GP0 function: +[ ] JTAG_TDI +[ ] UART1_TX +[ ] UART2_TX +[v] GP0 +[ ] IIC0_SCL +[ ] WG0_D0 +[ ] DBG_10 +``` +You can see that it has been configured as `GP0` now + +Similarly, to configure pin 1 as the TX pin for UART1, you need to execute +``` +duo-pinmux -w GP0/UART1_TX +``` +Check the multiplexing status +``` +[root@milkv-duo]~# duo-pinmux -r GP0 +GP0 function: +[ ] JTAG_TDI +[v] UART1_TX +[ ] UART2_TX +[ ] GP0 +[ ] IIC0_SCL +[ ] WG0_D0 +[ ] DBG_10 +``` +It meets the expectation diff --git a/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/pinpong.md b/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/pinpong.md new file mode 100644 index 00000000..be804beb --- /dev/null +++ b/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/pinpong.md @@ -0,0 +1,115 @@ +--- +sidebar_label: 'pinpong' +sidebar_position: 20 +--- + +# Introduction + +The pinpong library is an open-source python library that is based on the firmata protocol and utilizes micropython syntax. Its primary objective is to provide developers with a tool that allows them to directly control various open-source hardware control boards through Python code. + +# Usage + +## Pin numbers + +
+ +| pinpong | PIN NAME | Pin# | Pin# | PIN NAME | pinpong | +| ------- | -------- | :-----------------------------: | :------------------------------: | -------- | ------- | +| 0 | GP0 |
1
|
40
| VBUS | | +| 1 | GP1 |
2
|
39
| VSYS | | +| | GND |
3
|
38
| GND | | +| 2 | GP2 |
4
|
37
| 3V3_EN | | +| 3 | GP3 |
5
|
36
| 3V3(OUT) | | +| 4 | GP4 |
6
|
35
| | | +| 5 | GP5 |
7
|
34
| | | +| | GND |
8
|
33
| GND | | +| 6 | GP6 |
9
|
32
| GP27 | 27 | +| 7 | GP7 |
10
|
31
| GP26 | 26 | +| 8 | GP8 |
11
|
30
| RUN | | +| 9 | GP9 |
12
|
29
| GP22 | 22 | +| | GND |
13
|
28
| GND | | +| 10 | GP10 |
14
|
27
| GP21 | 21 | +| 11 | GP11 |
15
|
26
| GP20 | 20 | +| 12 | GP12 |
16
|
25
| GP19 | 19 | +| 13 | GP13 |
17
|
24
| GP18 | 18 | +| | GND |
18
|
23
| GND | | +| 14 | GP14 |
19
|
22
| GP17 | 17 | +| 15 | GP15 |
20
|
21
| GP16 | 16 | +| | |   | | | | +| 25 | GP25 |
LED
| | | | + +
+ +## Pinmux + +Many of Duo's pins have multipurpose functionality. When using pinpong library to control the functions of each pin, it is important to confirm the current state of the pin to ensure it matches the desired functionality. If it doesn't, you can use the `duo-pinmux` command to switch it to the desired function + +Please refer to the instructions: [pinmux](https://milkv.io/docs/duo/application-development/pinmux) + +## GPIO + +### Onboard LED blinking + +This is an example of making the Duo onboard LED blink. You can create a new `blink.py` file directly in Duo, or create it on your computer and then upload it to Duo via ssh. + +:::tip +The Pin number of the LED is 25. If you use other pins to connect external LEDs, please refer to the table above for the Pin number. +::: + +Contents of the `blink.py` file: +```python +# -*- coding: utf-8 -*- + +import time +from pinpong.board import Board,Pin + +Board("MILKV-DUO").begin() + +led = Pin(Pin.D25, Pin.OUT) + +while True: + led.value(1) + print("1") + time.sleep(1) + + led.value(0) + print("0") + time.sleep(1) +``` + +Execute the `python blink.py` command in Duo's terminal: +``` +[root@milkv-duo]~# python blink.py +milkv-duo + + __________________________________________ + | ____ _ ____ | + | / __ \(_)___ / __ \____ ____ ____ _ | + | / /_/ / / __ \/ /_/ / __ \/ __ \/ __ `/ | + | / ____/ / / / / ____/ /_/ / / / / /_/ / | + |/_/ /_/_/ /_/_/ \____/_/ /_/\__, / | + | v0.5.2 Designed by DFRobot /____/ | + |__________________________________________| + +1 +0 +1 +0 +``` +You will see the LED blinking at 1 second intervals. + +**Note**: +To test the `blink.py` example, which involves LED blinking, you need to disable the script responsible for the automatic LED blinking on the default firmware of Duo. In the Duo terminal, execute the following command: +``` +mv /mnt/system/blink.sh /mnt/system/blink.sh_backup && sync +``` +This command renames the LED blinking script. After restarting Duo, the LED will no longer blink. + +Once you have finished testing the `blink.py`, if you want to restore the LED blinking script, you can rename it back using the following command and then restart Duo: +``` +mv /mnt/system/blink.sh_backup /mnt/system/blink.sh && sync +``` + +## Other examples + +Please refer to: [github](https://github.com/milkv-duo/duo-buildroot-sdk/tree/develop/buildroot-2021.05/package/python-pinpong/pinpong/examples/milkv-Duo) diff --git a/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/sensor-demo.md b/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/sensor-demo.md new file mode 100644 index 00000000..675124dc --- /dev/null +++ b/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/sensor-demo.md @@ -0,0 +1,524 @@ +--- +sidebar_label: 'Sensor Demo' +sidebar_position: 40 +--- +# Sensor Demo +## DHT22 + +### Hardware Information + +#### Duo development board pin + +GitHub Link: https://github.com/milkv-duo/duo-files/blob/main/duo/hardware/duo-schematic-v1.2.pdf + +![](/docs/duo/sensor-demo/1.jpg) + +#### DHT22 Temperature and Humidity Sensor + +dfrobotwiki Link: https://wiki.dfrobot.com.cn/\_SKU_SEN0137\_%E9%AB%98%E7%B2%BE%E5%BA%A6DHT22%E6%B8%A9%E6%B9%BF%E5%BA%A6%E4%BC%A0%E6%84%9F%E5%99%A8 + +The DHT22 Temperature and Humidity Sensor is a versatile and cost-effective sensor used for measuring environmental temperature and humidity. It is based on digital signal output, providing high-precision measurements with a temperature resolution of 0.1 degrees Celsius and humidity resolution of 0.1%. The sensor uses a capacitive humidity sensing element and a thermistor to measure humidity and temperature, respectively. The DHT22 sensor also has relatively low power consumption and can operate within a voltage range of 3.3V to 5V, making it suitable for battery-powered projects. Additionally, the sensor offers long-term stability and high reliability, making it an ideal choice for various applications, including HVAC systems, weather stations, and indoor air quality monitoring systems. + +#### ensor Module + +The DHT22 module has a total of 3 pins, while the DHT22 bare sensor has 4 pins. When considering the module with three pins, two are power pins, and one is the data pin. For the 4-pin sensor, the additional pin is an NC (No Connection) pin with no specific function. The pinout for both the module and the sensor is as follows: +![](/docs/duo/sensor-demo/DHT22_10.png) + +\- DATA: Data pin for 1-Wire communication. + +\- GND: Ground pin for the module. + +\- VCC: Power pin for the module. + +\- Not Used: This pin is not used in this sensor. + +#### HT22 Sensor Module Component Markings + +Apart from the sensor, the DHT22 module on the PCB includes only two components: a pull-up resistor and a decoupling capacitor. The component markings for the DHT22 module are as follows. + +![](/docs/duo/sensor-demo/DHT22_11.png) + +#### DHT22 Module Circuit Diagram + +The complete schematic diagram of the DHT22 Temperature and Humidity Sensor module is shown in the diagram below. + +![](/docs/duo/sensor-demo/DHT22_12.png) + +The schematic diagram of the DHT22 module is as shown above. As mentioned earlier, the board has only a few components. The VCC and GND pins are directly connected to the DHT22 sensor, and the pull-up resistor is connected to the DATA pin. Tantalum and multi-layer capacitors provide sufficient filtering. In some PCBs, you may find an LED indicator as a power indicator, but for most circuit boards, the LED is not present. + +#### Common Questions About DHT22 Sensor Module + +Q: In simple terms, what is DHT22? + +A: DHT22 is a more expensive version of the DHT11 sensor with better specifications. Its temperature measurement range is -40 to +125 degrees Celsius with an accuracy of ±0.5 degrees, while the DHT11 has a temperature range of 0 to 50 degrees Celsius with an accuracy of ±2 degrees. + +Q: Is DHT22 analog or digital? + +A: DHT-22 (also known as AM2302) is a digital output relative humidity and temperature sensor. + +Q: Is DHT22 waterproof? + +A: No, it is not waterproof. + +Q: What is the sampling rate of the DHT11 sensor? + +A: The sampling rate of the DHT22 is 1Hz. + +Q: What protocol does DHT22 use? + +A: The DHT22 sensor uses a proprietary single-wire communication protocol that sends and receives data through timed pulses. + +#### How does DHT22 work? + +If you are using an original DHT22 sensor, it contains an NTC thermistor and a sensor module. However, most sensors available in the market are non-original parts and contain a small sensor, as shown in the image below. + +![](/docs/duo/sensor-demo/DHT22_13.png) + +The humidity sensing element consists of a moisture-absorbing substrate sandwiched between two electrodes. As the substrate absorbs moisture, the resistance between the two electrodes decreases. The resistance change between the electrodes is proportional to the relative humidity. Higher relative humidity decreases the resistance between the electrodes, while lower relative humidity increases the resistance. This resistance change is measured by the onboard MCU's ADC and used to calculate relative humidity. + +![](/docs/duo/sensor-demo/DHT22_14.png) + +Each DHT22 component undergoes rigorous calibration in the laboratory, with extremely accurate humidity calibration. Calibration coefficients are stored as programs in OTP memory for use in the sensor's internal signal detection process. + +#### DHT22 Single-Wire Communication Protocol + +A single-wire communication protocol is used to communicate with the DHT22 and the microcontroller. Data sampling takes approximately 4 milliseconds to complete. The data consists of both decimal and integer parts and totals 40 bits in length, in MSB format. The data format is as follows: 8-bit integer RH data + 8-bit decimal RH data + 8-bit integer T data + 8-bit decimal T data + 8-bit checksum. If the data transmission is correct, the checksum should be the last 8 bits of "8-bit integer RH data + 8-bit decimal RH data + 8-bit integer T data + 8-bit decimal T data." + +When the MCU sends the start signal, the DHT changes from low-power mode to running mode and dumps all 40 bits of data to the microcontroller. The microcontroller reads the data and calculates temperature and humidity based on the binary data. + +![](/docs/duo/sensor-demo/DHT22_15.png) + +The image above shows how data communication works with the microcontroller and DHT22. + +#### Connecting to the Development Board + +DHT22: Red wire to 3V3 (OUT), black wire to ground, green wire to GPIOA15. + +The circuit diagram is as follows: The black circle represents the DHT22. + +![](/docs/duo/sensor-demo/5.jpg) + +DHT22 should be connected as follows: + +![](/docs/duo/sensor-demo/DHT22_16.jpg) + +### Example Code: +GitHub link: https://github.com/milkv-duo/duo-examples + +**dht22.c:** +``` +// Ref: https://github.com/technion/lol_dht22/blob/master/dht22.c +#include +#include +#include +#include +#include +#define MAXTIMINGS 85 +static int DHTPIN = 15; +static int dht22_dat[5] = {0, 0, 0, 0, 0}; +static uint8_t sizecvt(const int read) +{ + /* digitalRead() and friends from wiringpi are defined as returning a value + < 256. However, they are returned as int() types. This is a safety function */ + + if (read > 255 || read < 0) + { + printf("Invalid data from wiringPi library\n"); + exit(EXIT_FAILURE); + } + return (uint8_t)read; +} + +static int read_dht22_dat() +{ + uint8_t laststate = HIGH; + uint8_t counter = 0; + uint8_t j = 0, i; + + dht22_dat[0] = dht22_dat[1] = dht22_dat[2] = dht22_dat[3] = dht22_dat[4] = 0; + + // pull pin down for 18 milliseconds + pinMode(DHTPIN, PINMODE_OUTPUT); + digitalWrite(DHTPIN, HIGH); + // delay(500); + delayMicroseconds(500000); + digitalWrite(DHTPIN, LOW); + // delay(20); + delayMicroseconds(20000); + // prepare to read the pin + pinMode(DHTPIN, PINMODE_INPUT); + + // detect change and read data + for (i = 0; i < MAXTIMINGS; i++) + { + counter = 0; + while (sizecvt(digitalRead(DHTPIN)) == laststate) + { + counter++; + delayMicroseconds(2); + if (counter == 255) + { + break; + } + } + laststate = sizecvt(digitalRead(DHTPIN)); + + if (counter == 255) + break; + + // ignore first 3 transitions + if ((i >= 4) && (i % 2 == 0)) + { + // shove each bit into the storage bytes + dht22_dat[j / 8] <<= 1; + if (counter > 16) + dht22_dat[j / 8] |= 1; + j++; + } + } + + // check we read 40 bits (8bit x 5 ) + verify checksum in the last byte + // print it out if data is good + if ((j >= 40) && + (dht22_dat[4] == ((dht22_dat[0] + dht22_dat[1] + dht22_dat[2] + dht22_dat[3]) & 0xFF))) + { + float t, h; + h = (float)dht22_dat[0] * 256 + (float)dht22_dat[1]; + h /= 10; + t = (float)(dht22_dat[2] & 0x7F) * 256 + (float)dht22_dat[3]; + t /= 10.0; + if ((dht22_dat[2] & 0x80) != 0) + t *= -1; + printf("Humidity = %.2f %% Temperature = %.2f *C \n", h, t); + return 1; + } + else + { + printf("Data not good, skip\n"); + return 0; + } +} + +int main() +{ + // Duo: milkv_duo + // Duo256M: milkv_duo256m + // DuoS: milkv_duos + if (wiringXSetup("milkv_duo", NULL) == -1) + { + wiringXGC(); + return -1; + } + + if (wiringXValidGPIO(DHTPIN) != 0) + { + printf("Invalid GPIO %d\n", DHTPIN); + } + + while (1) + { + read_dht22_dat(); + delayMicroseconds(1500000); + } + + return 0; +} + +``` + +**Makefile:** +``` +TARGET=dht22 + +ifeq (,$(TOOLCHAIN_PREFIX)) +$(error TOOLCHAIN_PREFIX is not set) +endif + +ifeq (,$(CFLAGS)) +$(error CFLAGS is not set) +endif + +ifeq (,$(LDFLAGS)) +$(error LDFLAGS is not set) +endif + +CC = $(TOOLCHAIN_PREFIX)gcc +CFLAGS += -I$(SYSROOT)/usr/include +LDFLAGS += -L$(SYSROOT)/lib +LDFLAGS += -L$(SYSROOT)/usr/lib +LDFLAGS += -lwiringx + +SOURCE = $(wildcard *.c) +OBJS = $(patsubst %.c,%.o,$(SOURCE)) + +$(TARGET): $(OBJS) + $(CC) -o $@ $(OBJS) $(LDFLAGS) + +%.o: %.c + $(CC) $(CFLAGS) -o $@ -c $< + +.PHONY: clean +clean: + @rm *.o -rf + @rm $(OBJS) -rf + @rm $(TARGET) + +``` +### Build environment on Ubuntu20.04 + +You can also use Ubuntu installed in a virtual machine, Ubuntu installed via WSL on Windows, or Ubuntu-based systems using Docker. + +- Install the tools that compile dependencies. + ``` + sudo apt-get install wget git make + ``` +- Get example source code + ``` + git clone https://github.com/milkv-duo/duo-examples.git + ``` + +- Prepare compilation environment + ``` + cd duo-examples + source envsetup.sh + ``` + The first time you source it, the required SDK package will be automatically downloaded, which is approximately 180MB in size. Once downloaded, it will be automatically extracted to the `duo-examples` directory with the name `duo-sdk`. When source it next time, if the directory already exists, it will not be downloaded again. + +- Compile testing + + Take hello-world as an example, enter the hello-world directory and execute make + ``` + cd hello-world + make + ``` + After the compilation is successful, send the generated `helloworld` executable program to the Duo device through the network port or the RNDIS network. For example, the RNDIS method supported by the [default firmware](https://github.com/milkv-duo/duo-buildroot-sdk/releases), Duo’s IP is 192.168.42.1, the user name is `root`, and the password is `milkv` + ``` + scp helloworld root@192.168.42.1:/root/ + ``` + After sending successfully, run ./helloworld in the terminal logged in via ssh or serial port, and it will print `Hello, World!` + ``` + [root@milkv]~# ./helloworld + Hello, World! + ``` + **At this point, our compilation and development environment is ready for use.** +### Operation Procedure + +![](/docs/duo/sensor-demo/DF9GMS_7.png) + +Next, compile it. Taking dht22 as an example, enter the directory of the example and simply execute make + +``` +cd dht22 +make it +``` +Make an error report and source it. After compiling successfully, you will get the df9gms executable program. As shown in the figure below. + +![](/docs/duo/sensor-demo/DHT22_17.png) + + + + +Then upload df9gms to the root path of the development board, and enter``` ./dht22``` to run it. The screenshot of successful running is shown below + +![](/docs/duo/sensor-demo/DHT22_18.png) + +## DF9GMS 180° + +### Hardware Information + +#### Duo development board pin + +GitHub:https://github.com/milkv-duo/duo-files/blob/main/duo/hardware/duo-schematic-v1.2.pdf + +![](/docs/duo/sensor-demo/1.jpg) + +#### DF9GMS 180° + +![](/docs/duo/sensor-demo/DF9GMS_2.png) + +Micro Servo DF9GMS from DFRobot, this servo features a high-strength ABS transparent case with internal high-precision nylon gear set, precision control circuit and high-end lightweight hollow cup motor, resulting in a weight of only 9g for this mini servo, while the output torque reaches an amazing 1.6kg/cm. + +Technical Specifications: +Operating Voltage: 4.8V +Torque: 1.6kg/cm (4.8V) +Speed: 0.14 seconds/60 degrees (4.8V) +Operating Temperature: -30 to +60 degrees Celsius +Deadband Width: 0.5 milliseconds +Physical Size: 23x12.2x29mm +Weight: 9g + +#### Composition and Operating Principle of DF9GMS Micro Servo + +![](/docs/duo/sensor-demo/DF9GMS_3.png) + +#### Connection Diagram: +• Hardware +o 1 x Arduino UNO control board +o 1 x DF9GMS micro servo +o Several Dupont wires +o Gray - GND, red - VCC, yellow - signal line + +![](/docs/duo/sensor-demo/DF9GMS_4.png) + +#### connected to the development board + +DF9GMS: red wire connected to VSYS, brown wire connected to ground, orange wire connected to GPIO19. +Circuit diagram shown below: purple circle represents DF9GMS. + +![](/docs/duo/sensor-demo/5.jpg) + +DF9GMS should be connected as follows: + +![](/docs/duo/sensor-demo/DF9GMS_6.jpg) + +### Example Code: +GitHub link: https://github.com/milkv-duo/duo-examples + +**df9gms.c:** +``` +#include +#include +#include +/* +Duo +------------------------------------------ +PWM operation at a fixed frequency clock of 100MHz, writing Period in units of nanoseconds. + DF9GMS 360-degree PWM Duty Cycle + ------------------------------------------ + 0.4ms - 1.4ms CW deceleration + 1.5ms Stop + 1.6ms - 3ms CCW acceleration +*/ +static int PWM_PIN = 4; // PWM5@GP4 + +int main() +{ + long i; + + // Duo: milkv_duo + // Duo256M: milkv_duo256m + // DuoS: milkv_duos + if(wiringXSetup("milkv_duo", NULL) == -1) { + wiringXGC(); + return -1; + } + + wiringXPWMSetPeriod(PWM_PIN, 20000000); // 20ms + wiringXPWMSetDuty(PWM_PIN, 1500000); // 1.5ms stop + wiringXPWMSetPolarity(PWM_PIN, 0); // 0-normal, 1-inversed + wiringXPWMEnable(PWM_PIN, 1); // 1-enable, 0-disable + + delayMicroseconds(1000000); // 1s + + for (i = 10000; i< 3000000; i += 10000) // 10 us + { + wiringXPWMSetDuty(PWM_PIN, i); + printf("Duty: %ld\n", i); + delayMicroseconds(50000); // 50ms + } + + wiringXPWMSetDuty(PWM_PIN, 1500000); // 1.5ms stop + + return 0; +} + +``` + +**Makefile:** + +``` +TARGET=df9gms + +ifeq (,$(TOOLCHAIN_PREFIX)) +$(error TOOLCHAIN_PREFIX is not set) +endif + +ifeq (,$(CFLAGS)) +$(error CFLAGS is not set) +endif + +ifeq (,$(LDFLAGS)) +$(error LDFLAGS is not set) +endif + +CC = $(TOOLCHAIN_PREFIX)gcc + +CFLAGS += -I$(SYSROOT)/usr/include + +LDFLAGS += -L$(SYSROOT)/lib +LDFLAGS += -L$(SYSROOT)/usr/lib +LDFLAGS += -lwiringx + +SOURCE = $(wildcard *.c) +OBJS = $(patsubst %.c,%.o,$(SOURCE)) + +$(TARGET): $(OBJS) + $(CC) -o $@ $(OBJS) $(LDFLAGS) + +%.o: %.c + $(CC) $(CFLAGS) -o $@ -c $< + +.PHONY: clean +clean: + @rm *.o -rf + @rm $(OBJS) -rf + @rm $(TARGET) +``` + +### Build environment on Ubuntu20.04 + +You can also use Ubuntu installed in a virtual machine, Ubuntu installed via WSL on Windows, or Ubuntu-based systems using Docker. + +- Install the tools that compile dependencies. + ``` + sudo apt-get install wget git make + ``` +- Get example source code + ``` + git clone https://github.com/milkv-duo/duo-examples.git + ``` + +- Prepare compilation environment + ``` + cd duo-examples + source envsetup.sh + ``` + The first time you source it, the required SDK package will be automatically downloaded, which is approximately 180MB in size. Once downloaded, it will be automatically extracted to the `duo-examples` directory with the name `duo-sdk`. When source it next time, if the directory already exists, it will not be downloaded again. + +- Compile testing + + Take hello-world as an example, enter the hello-world directory and execute make + ``` + cd hello-world + make + ``` + After the compilation is successful, send the generated `helloworld` executable program to the Duo device through the network port or the RNDIS network. For example, the RNDIS method supported by the [default firmware](https://github.com/milkv-duo/duo-buildroot-sdk/releases), Duo’s IP is 192.168.42.1, the user name is `root`, and the password is `milkv` + ``` + scp helloworld root@192.168.42.1:/root/ + ``` + After sending successfully, run ./helloworld in the terminal logged in via ssh or serial port, and it will print `Hello, World!` + ``` + [root@milkv]~# ./helloworld + Hello, World! + ``` + **At this point, our compilation and development environment is ready for use.** + +### Operation Procedure + +![](/docs/duo/sensor-demo/DF9GMS_7.png) + +Next, compile it. Taking df9gms as an example, enter the directory of the example and simply execute make +``` +cd df9gms +make it +``` +Make an error report and source it. After compiling successfully, you will get the df9gms executable program. As shown in the figure below. + +![](/docs/duo/sensor-demo/DF9GMS_8.png) + + + +Then upload df9gms to the root path of the development board, and enter ```./df9gms``` to run it. The screenshot of successful running is shown below + +![](/docs/duo/sensor-demo/DF9GMS_9.png) + diff --git a/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tdl-sdk/_category_.json b/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tdl-sdk/_category_.json new file mode 100644 index 00000000..123a33b1 --- /dev/null +++ b/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tdl-sdk/_category_.json @@ -0,0 +1,8 @@ +{ + "label": "TDL SDK", + "position": 20, + "link": { + "type": "generated-index", + "slug": "/duo/app-dev/tdl-sdk" + } +} diff --git a/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tdl-sdk/tdl-sdk-face-detection.md b/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tdl-sdk/tdl-sdk-face-detection.md new file mode 100644 index 00000000..b10f293e --- /dev/null +++ b/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tdl-sdk/tdl-sdk-face-detection.md @@ -0,0 +1,104 @@ +--- +sidebar_label: 'Face Detection' +sidebar_position: 20 +--- + +# Face Detection + +The test program will pull the camera data, add the face detection algorithm, and use tools such as VLC to pull the stream in real time to view the effect. + +### Compilation + +Face detection program source code location: + +- Duo:[sample_vi_fd.c](https://github.com/milkv-duo/cvitek-tdl-sdk-cv180x/blob/main/sample/cvi_tdl/sample_vi_fd.c) + +- Duo256M and DuoS:[sample_vi_fd.c](https://github.com/milkv-duo/cvitek-tdl-sdk-sg200x/blob/main/sample/cvi_tdl/sample_vi_fd.c) + +Refer to the method in the previous chapter [Introduction](https://milkv.io/docs/duo/application-development/tdl-sdk/tdl-sdk-introduction) to compile the sample program. + +### Send test program and model files to Duo + +- Refer to the method in the [Boot the Duo](https://milkv.io/docs/duo/getting-started/boot) chapter to install the system + +- Refer to the method in the [Camera](https://milkv.io/docs/duo/camera/gc2083) chapter to power on the Duo after connecting the camera + +Send the compiled `sample_vi_fd` to the Duo board through the `scp` command on your PC: + +```bash +scp sample_vi_fd root@192.168.42.1:/root/ +``` + +Also use scp to send the model file used for face detection in the `cvimodel` directory to the Duo board: + +Duo: +``` +scrfd_480_270_int8.cvimodel +``` + +Duo256M and DuoS: +``` +scrfd_768_432_int8_1x.cvimodel +``` + +### Run the example + +Log in to the Duo terminal through the serial port or [ssh](https://milkv.io/docs/duo/getting-started/setup#ssh). + +Add executable permissions to the test program in Duo's terminal + +``` +chmod +x sample_vi_fd +``` + +Execute the test program in Duo's terminal: + +Duo: +``` +./sample_vi_fd scrfd_480_270_int8.cvimodel +``` + +Duo256M and DuoS: +``` +./sample_vi_fd scrfd_768_432_int8_1x.cvimodel +``` + +The following information will be displayed in the Duo terminal: +``` +Initialize RTSP +rtsp://127.0.1.1/h264 +prio:0 +version: 1.4.0 +scrfd768432 Build at 2023-12-25 01:21:44 For platform cv181x +Max SharedMem size:1658880 +``` + +At this time, point the camera at the face, and the Duo terminal will print the number of faces detected by the camera in real time: +``` +face count: 5 +face count: 6 +face count: 5 +face count: 4 +face count: 0 +face count: 1 +face count: 0 +``` + +### Use VLC to pull streams on PC to view the effect + +Open `VLC media player`, click `Media` in the upper left corner, select `Open Network Stream`, and enter the URL. + +If you are using USB Net(RNDIS), the address is: +``` +rtsp://192.168.42.1/h264 +``` + + + +If you are using the network port on the IO-Board or the network port integrated on DuoS, the IP address in the URL needs to be replaced with the IP of the network port (you can use the `ifconfig` command in the Duo terminal to view). + +Click the `Show more options` option in the lower left corner, and you can set the `Caching` option to adjust the delay. The default is 1000 milliseconds, which is 1 second. When the network environment is good, such as in a LAN, you can turn it down to reduce latency. You can set it to 100 to 300. If the network environment is poor or the screen freezes, you can try to increase it. + +After configuring, click `Play` to view the face detection effect of the camera. + + diff --git a/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tdl-sdk/tdl-sdk-introduction.md b/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tdl-sdk/tdl-sdk-introduction.md new file mode 100644 index 00000000..5101d156 --- /dev/null +++ b/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tdl-sdk/tdl-sdk-introduction.md @@ -0,0 +1,126 @@ +--- +sidebar_label: 'Introduction' +sidebar_position: 10 +--- + +# Introduction + +Cvitek provides TDL integration algorithms to reduce the time required for application development. + +This architecture realizes the algorithm required by TDL, including its pre and post processing, and provides a unified and convenient programming interface. + +At present, TDL SDK includes motion detection, face detection, face recognition, face tracking, pedestrian detection, semantic segmentation, license plate recognition, license plate detection, live recognition, IR live recognition, infant detection, cry detection, attitude detection, gesture detection, Gesture Recognition and other algorithms. + +## Documents + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Chinese Version(中文版)格式English VersionFormat
深度学习SDK软件开发指南htmlpdfTDL SDK Software Development Guidehtmlpdf
YOLO系列开发指南htmlpdfYOLO Development Guidehtmlpdf
+ +## Compilation + +The TDL-SDK program needs to be cross-compiled in the Linux environment of the PC host, such as Ubuntu 22.04 system. + +1. Download toolchain + + ```bash + wget https://sophon-file.sophon.cn/sophon-prod-s3/drive/23/03/07/16/host-tools.tar.gz + ``` + + Extracting Toolchain: + ```bash + tar xvf host-tools.tar.gz + ``` + + Enter the toolchain directory and export the toolchain path to the environment variable: + ```bash + cd host-tools + export PATH=$PATH:$(pwd)/gcc/riscv64-linux-musl-x86_64/bin + ``` + + Verify that the toolchain is available: + ``` + riscv64-unknown-linux-musl-gcc -v + ``` + The version information of the cross-compilation tool chain can be displayed normally, that is, the toolchain is available: + ``` + $ riscv64-unknown-linux-musl-gcc -v + Using built-in specs. + COLLECT_GCC=riscv64-unknown-linux-musl-gcc + ... + Thread model: posix + Supported LTO compression algorithms: zlib + gcc version 10.2.0 (Xuantie-900 linux-5.10.4 musl gcc Toolchain V2.6.1 B-20220906) + ``` + +2. Compile cvitek-tdl-sdk + + Download the TDL-SDK source code, the Duo and Duo256M/DuoS repositories are different: + + - Duo: + ```bash + git clone https://github.com/milkv-duo/cvitek-tdl-sdk-cv180x.git + cd cvitek-tdl-sdk-cv180x + ``` + + - Duo256M 和 DuoS: + ```bash + git clone https://github.com/milkv-duo/cvitek-tdl-sdk-sg200x.git + cd cvitek-tdl-sdk-sg200x + ``` + + If the repositories code is updated, you can execute `git pull` in the code directory to pull the latest code, such as Duo256M and DuoS: + ```bash + cd cvitek-tdl-sdk-sg200x + git pull + ``` + After pulling the latest code, continue compiling. + + Compile samples: + ``` + cd sample + ./compile_sample.sh + ``` + + The generated program is in the corresponding subdirectory in the sample directory. For example, the face detection example `sample_vi_fd` is located in + ``` + cvi_tdl/sample_vi_fd + ``` + + Clean: + ```bash + ./compile_sample.sh clean + ``` + +## Example description + +For detailed descriptions and running methods of each example, please refer to the following chapters. + +## Reference link + +[https://developer.sophgo.com/thread/556.html](https://developer.sophgo.com/thread/556.html) diff --git a/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tdl-sdk/tdl-sdk-yolov5.md b/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tdl-sdk/tdl-sdk-yolov5.md new file mode 100644 index 00000000..2bc1b2bd --- /dev/null +++ b/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tdl-sdk/tdl-sdk-yolov5.md @@ -0,0 +1,181 @@ +--- +sidebar_label: 'YOLOv5 Object Detection' +sidebar_position: 21 +--- + +# YOLOv5 Object Detection + +This program inference YOLOv5 model for object detection. + +## Cross-Compile YOLO Program for PC + +Duo256M YOLOv5 code location: [sample_yolov5.cpp](https://github.com/milkv-duo/cvitek-tdl-sdk-sg200x/blob/main/sample/cvi_yolo/sample_yolov5.cpp) + +### Compilation method + +Refer to the previous section [Introduction](https://milkv.io/zh/docs/duo/application-development/tdl-sdk/tdl-sdk-introduction) for compiling the sample program using the provided methods. After compilation is completed, the `sample_yolov5` program we need will be generated in the `sample/cvi_yolo/` directory. + +## Obtain cvimodel + +You can either download precompiled yolov5s INT8 symmetric or asymmetric quantized cvimodel models directly, or manually convert the models as described in [Model Compilation](#model-compilation). + +### Download Precompiled cvimodels + +- Duo256M + ```bash + # INT8 symmetric model + wget https://github.com/milkv-duo/cvitek-tdl-sdk-sg200x/raw/main/cvimodel/yolov5_cv181x_int8_sym.cvimodel + # INT8 asymmetric model (commented out as it is optional) + wget https://github.com/milkv-duo/cvitek-tdl-sdk-sg200x/raw/main/cvimodel/yolov5_cv181x_int8_asym.cvimodel + ``` + +### Model Compilation + +#### Export yolov5s.onnx Model + +- First, clone the YOLOv5 official repository. The repository link is: [ultralytics/yolov5\: YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite](https://github.com/ultralytics/yolov5) + ```bash + git clone https://github.com/ultralytics/yolov5.git + ``` +- Configure the working environment + ```bash + cd yolov5 + pip3 install -r requirements.txt + pip3 install onnx + ``` +- Obtain the .pt format model for yolov5, for example, download the yolov5s model: [yolov5s](https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5s.pt) + ```bash + wget https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5s.pt + ``` +- Copy cvitek-tdl-sdk-sg200x/sample/yolo_export/[yolov5_export.py](https://github.com/milkv-duo/cvitek-tdl-sdk-sg200x/blob/main/sample/yolo_export/yolov5_export.py) to the yolov5 repository directory. + Use yolov5_export.py to replace the forward function, allowing the RISC-V to handle post-processing and export the model in onnx format. + ```bash + python3 yolov5_export.py --weights ./yolov5s.pt --img-size 640 640 + ``` + Parameter explanation: + --weights: Path to the PyTorch model + --img-size: Input image size + +#### TPU-MLIR Model Conversion + +Please refer to [TPU-MLIR documentation](https://github.com/sophgo/tpu-mlir) to set up the TPU-MLIR working environment. For parameter details, see [TPU-MLIR documentation](https://github.com/sophgo/tpu-mlir). + +The specific implementation steps are divided into three parts: + +- `model_transform.py`: Converts the onnx model to the mlir intermediate format model. + onnx -> model_transform.py -> mlir + +- `run_calibration.py`: Generates the int8 quantization calibration table. + calibration_set -> run_calibration.py -> calibration_table + +- `model_deploy.py`: Generates the cvimodel for TPU inference using mlir and the int8 quantization table. + mlir + calibration_table ->model_deploy.py -> cvimodel + +##### onnx to MLIR + +```bash +model_transform.py \ +--model_name yolov5s \ +--model_def yolov5s.onnx \ +--input_shapes [[1,3,640,640]] \ +--mean 0.0,0.0,0.0 \ +--scale 0.0039216,0.0039216,0.0039216 \ +--keep_aspect_ratio \ +--pixel_format rgb \ +--test_input ../image/dog.jpg \ +--test_result yolov5s_top_outputs.npz \ +--mlir yolov5s.mlir +``` + +After converting to the mlir file, a yolov5s_in_f32.npz file will be generated, which is the model's input file. + +##### MLIR to INT8 Model (Supports INT8 Quantization Only) + +Before quantizing to INT8 model, run calibration.py to get the calibration table. Prepare around 100~1000 images, in this case, 100 images from the COCO2017 dataset are used for demonstration. + +```bash +run_calibration.py yolov5s.mlir \ +--dataset ../COCO2017 \ +--input_num 100 \ +-o yolov5s_cali_table +``` + +Then use the calibration table to generate the int8 symmetric cvimodel + +```bash +model_deploy.py \ +--mlir yolov5s.mlir \ +--quant_input --quant_output \ +--quantize INT8 \ +--calibration_table yolov5s_cali_table \ +--processor cv181x \ +--test_input yolov5s_in_f32.npz \ +--test_reference yolov5s_top_outputs.npz \ +--tolerance 0.85,0.45 \ +--model yolov5_cv181x_int8_sym.cvimodel +``` + +After compilation, a file named yolov5_cv181x_int8_sym.cvimodel will be generated. + +*(Optional) Generate INT8 asymmetric cvimodel* + +```bash +model_deploy.py \ +--mlir yolov5s.mlir \ +--quant_input --quant_output \ +--quantize INT8 --asymmetric \ +--calibration_table yolov5s_cali_table \ +--processor cv181x \ +--test_input yolov5s_in_f32.npz \ +--test_reference yolov5s_top_outputs.npz \ +--tolerance 0.85,0.45 \ +--model yolov5_cv181x_int8_asym.cvimodel +``` + +After compilation, a file named yolov5_cv181x_int8_asym.cvimodel will be generated. + +## Inference on the Board + +Copy the compiled [sample_yolov5](#cross-compile-yolo-program-for-pc), [cvimodel](#obtain-cvimodel), and the image to be inferred to the board, and then execute the binary program. +```bash +scp sample_yolov5 yolov5_cv181x_int8_asym.cvimodel 000000000113.jpg root@192.168.42.1:/root/ +``` +The image for inference is as follows: + +![duo-tdl-sdk-yolov5-detection.jpg](/docs/duo/tdl-sdk/duo-tdl-sdk-yolov5-detection.jpg) + +Run the command: + +```bash +export LD_LIBRARY_PATH='/mnt/system/lib' +./sample_yolov5 ./yolov5_cv181x_int8_asym.cvimodel 000000000113.jpg +``` + +result: +```bash +[root@milkv-duo]~/data/test_make# ./sample_yolov5 ./yolov5_cv181x_int8_asym.cvim +odel 000000000113.jpg +[ 5665.088539] vb has already inited, set_config cmd has no effect +version: 1.4.0 +yolov5s Build at 2024-01-30 16:32:00 For platform cv181x +Max SharedMem size:5734400 +model opened:./yolov5_cv181x_int8_asym.cvimodel +detect res: 340.399902 96.056824 415.000000 423.052612 0.866147 0 +detect res: 149.599243 52.756699 344.154053 434.715759 0.864127 0 +detect res: 165.295807 434.305786 389.069794 546.548950 0.739044 55 +detect res: 5.554703 34.055344 161.554688 521.089905 0.718132 0 +detect res: 79.427734 458.260071 124.559998 515.725830 0.677201 41 +detect res: 256.286438 367.324158 303.713562 450.689941 0.598015 43 +detect res: 282.405457 93.188477 309.046570 121.621582 0.555912 41 +detect res: 281.694244 60.846092 309.968231 91.153908 0.520292 41 +``` +The program performs YOLOv5 model inference on the image, and the inference results are printed. +The output interpretation is in the format `res: x y w h conf label`, representing the top-left coordinates `(x,y)` of the recognized result box, the width and height `(w,h)` of the recognized result box, the confidence `conf` of the recognized result, and the object label `label`. + +```bash +# Referring to the COCO2017 label file +0 person +55 cake +41 cup +43 knife +``` \ No newline at end of file diff --git a/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tpu/_category_.json b/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tpu/_category_.json new file mode 100644 index 00000000..21f9fccf --- /dev/null +++ b/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tpu/_category_.json @@ -0,0 +1,8 @@ +{ + "label": "TPU", + "position": 30, + "link": { + "type": "generated-index", + "slug": "/duo/app-dev/tpu" + } +} diff --git a/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tpu/tpu-densenet.md b/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tpu/tpu-densenet.md new file mode 100644 index 00000000..7b427e12 --- /dev/null +++ b/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tpu/tpu-densenet.md @@ -0,0 +1,194 @@ +--- +sidebar_label: 'Densenet Image Classification' +sidebar_position: 39 +--- + +# Image Classification Based on Densenet + +## 1. Configure Docker development environment + +Refer to [here](https://milkv.io/docs/duo/application-development/tpu/tpu-docker). After configuring the Docker development environment, return here to continue the next step. + +:::warning +If you are using a configured Docker development environment, please make sure to follow the Docker configuration tutorial to execute command `source ./tpu-mlir/envsetup.sh` after starting Docker, otherwise errors may occur in subsequent steps. +::: + +## 2. Prepare the working directory in Docker + +Create and enter the `densenet121` working directory, note that it is a directory at the same level as `tpu-mlir`. +``` +# mkdir densenet121 && cd densenet121 +``` + +Get the original model +``` +# wget https://media.githubusercontent.com/media/onnx/models/main/validated/vision/classification/densenet-121/model/densenet-12.tar.gz +``` +Extract `densenet-12.tar.gz` +``` +# tar -zxvf densenet-12.tar.gz +``` +After extraction is complete, the `densenet-12` folder will be generated in the current directory, which contains the `densenet-12.onnx` model file. + +Copy test image: +``` +# cp -rf ${TPUC_ROOT}/regression/dataset/ILSVRC2012/ . +# cp -rf ${TPUC_ROOT}/regression/image/ . +``` +`${TPUC_ROOT}` here is an environment variable, corresponding to the `tpu-mlir` directory, which is loaded in the `source ./tpu-mlir/envsetup.sh` step in the previous configuration of the Docker development environment. + +Create and enter the `work` working directory to store compiled files such as `MLIR` and `cvimodel` +``` +# mkdir work && cd work +``` + +## 3. ONNX Model Conversion + +:::tip +The Duo development board is equipped with the CV1800B chip, which supports the **ONNX series** and **Caffe models**. Currently, it does not support TFLite models. In terms of quantized data types, it supports **quantization in BF16 format** and **asymmetric quantization in INT8 format**. +::: + +The steps for model conversion are as follows: +- Convert ONNX model to MLIR +- Generate calibration tables required for quantification +- MLIR quantization into INT8 asymmetric cvimodel + +### ONNX model converted to MLIR + +The model in this example is RGB input, `mean` and `scale` are `123.675`,`116.28`,`103.53` and `0.0171`,`0.0175`,`0.0174` respectively. + +The command to convert an ONNX model to an MLIR model is as follows: +``` +model_transform.py \ + --model_name densenet121 \ + --model_def ../densenet-12/densenet-12.onnx \ + --test_input ../image/cat.jpg \ + --input_shapes [[1,3,224,224]] \ + --resize_dims 256,256 \ + --mean 123.675,116.28,103.53 \ + --scale 0.0171,0.0175,0.0174 \ + --pixel_format rgb \ + --test_result densenet121_top_outputs.npz \ + --mlir densenet121.mlir +``` + +Example of successful operation + +![duo](/docs/duo/tpu/duo-tpu-densenet_05.png) + +After converting to the MLIR model, a `densenet121.mlir` file will be generated, which is the MLIR model file. A `densenet121_in_f32.npz` file and a `densenet121_top_outputs.npz` file will also be generated, which are the input files for subsequent model conversion. + +![duo](/docs/duo/tpu/duo-tpu-densenet_06.png) + +### MLIR to INT8 model + +#### Generate calibration tables required for quantification + +Before converting to the INT8 model, you need to generate a calibration table. Here we use the existing 100 pictures from ILSVRC2012 as an example and execute the calibration command: +``` +run_calibration.py densenet121.mlir \ + --dataset ../ILSVRC2012 \ + --input_num 100 \ + -o densenet121_cali_table +``` + +Example of successful operation + +![duo](/docs/duo/tpu/duo-tpu-densenet_07.png) + +After the operation is completed, the `densenet121_cali_table` file will be generated, which is used for subsequent compilation of the INT8 model. + +![duo](/docs/duo/tpu/duo-tpu-densenet_08.png) + +#### MLIR quantized into INT8 asymmetric cvimodel + +The command to convert MLIR model to INT8 model is as follows: +``` +model_deploy.py \ + --mlir densenet121.mlir \ + --quantize INT8 \ + --calibration_table densenet121_cali_table \ + --chip cv180x \ + --test_input ../image/cat.jpg \ + --test_reference densenet121_top_outputs.npz \ + --compare_all \ + --fuse_preprocess \ + --model densenet121_int8_fuse.cvimodel +``` + +:::tip +If the development board you are using is not Duo, please replace the fifth line `-- chip cv180x` in the above command with the corresponding chip model. +When using Duo 256M/Duo S , it should be changed to ` -- chip cv181x`. +::: + +Example of successful operation + +![duo](/docs/duo/tpu/duo-tpu-densenet_09.png) + +After compilation is completed, the `densenet121_int8_fuse.cvimodel` file will be generated. + +![duo](/docs/duo/tpu/duo-tpu-densenet_10.png) + +## 4. Validate on Development Board Duo + +### Connecting the Duo development board + +Complete the connection between the Duo development board and the computer according to the previous tutorial, and use tools such as `mobaxterm` or `Xshell` to open a terminal to operate the Duo development board. + +### Get tpu-sdk + +Switch to the `/workspace` directory in the Docker terminal +``` +cd /workspace +``` + +Download tpu sdk, if you are using Duo, execute +``` +git clone https://github.com/milkv-duo/tpu-sdk-cv180x.git +mv ./tpu-sdk-cv180x ./tpu-sdk +``` + +Else,if you are using Duo 256M/Duo S , execute +``` +git clone https://github.com/milkv-duo/tpu-sdk-sg200x.git +mv ./tpu-sdk-sg200x ./tpu-sdk +``` + +### Copy tpu-sdk and model files to Duo + +In the terminal of the Duo board, create a new directory `/mnt/tpu/` +``` +# mkdir -p /mnt/tpu && cd /mnt/tpu +``` + +In the Docker terminal, copy `tpu-sdk` and model files to the Duo +``` +# scp -r /workspace/tpu-sdk root@192.168.42.1:/mnt/tpu/ +# scp /workspace/densenet121/work/densenet121_int8_fuse.cvimodel root@192.168.42.1:/mnt/tpu/tpu-sdk/ +``` + +### Set environment variables + +In the terminal of the Duo board, set the environment variables +``` +# cd /mnt/tpu/tpu-sdk +# source ./envs_tpu_sdk.sh +``` + +### Perform Image Classification + +On the Duo board, perform Image Classification on the image + +![duo](/docs/duo/tpu/duo-tpu-cat.jpg) + +Image classification using `densenet121_int8_fuse.cvimodel` model: +``` +./samples/bin/cvi_sample_classifier_fused_preprocess \ + ./densenet121_int8_fuse.cvimodel \ + ./samples/data/cat.jpg \ + ./samples/data/synset_words.txt +``` + +Example of successful classification results + +![duo](/docs/duo/tpu/duo-tpu-densenet_11.png) diff --git a/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tpu/tpu-docker.md b/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tpu/tpu-docker.md new file mode 100644 index 00000000..02403456 --- /dev/null +++ b/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tpu/tpu-docker.md @@ -0,0 +1,99 @@ +--- +sidebar_label: 'Docker dev environment' +sidebar_position: 20 +--- + +# Setting up Docker development environment + +## Docker installation + +In the windows environment, you can install `Docker Desktop for Windows`, Docker [download address](https://docs.docker.com/desktop/install/windows-install/) + +![duo](/docs/duo/tpu/duo-tpu-docker_01.png) + +Running Docker under Windows requires relevant dependencies, as shown in the figure, you need to use the WSL2 backend or Hyper-V backend as a running dependency. + +The enabling method for the Hyper-V backend is as follows: + +1. Control Panel - Programs and Features - Turn Windows features on or off +2. Find `Hyper-V`, check `Hyper-V Management Tools` and `Hyper-V Platform`, click OK and wait for the system file configuration to be completed before restarting the computer. + + ![duo](/docs/duo/tpu/duo-tpu-docker_02-en.png) + +Then you can install and download Docker Desktop for Windows, and make the appropriate check according to the selected backend in the installation guide. + +After the installation is complete, you need to restart your computer and then you can use Docker. + +## Pull the Docker image required for development + +Get the image file from Docker hub +``` +docker pull sophgo/tpuc_dev:v3.1 +``` + +``` +PS C:\Users\Carbon> docker pull sophgo/tpuc_dev:v3.1 +v3.1: Pulling from sophgo/tpuc_dev +b237fe92c417: Pull complete +db3c30810eab: Downloading 411.1MB/629.4MB +2651dfd68288: Download complete +db3c5981ae16: Download complete +16098f82aa65: Download complete +85e8821c88fd: Download complete +d8a25a7307da: Download complete +91fd425676de: Download complete +b3ad6c6ed19d: Downloading 346.1MB/480.6MB +ecaa420e1520: Download complete +a570c4642598: Download complete +2d76e68a7946: Download complete +1df3b38113a9: Download complete +4f4fb700ef54: Download complete +f835d42d7adc: Download complete +2b009425c205: Downloading 252.9MB/1.098GB +``` + +## Start Docker container + +``` +docker run --privileged --name -v /workspace -it sophgo/tpuc_dev:v3.1 +``` +`` is the container name defined by yourself, such as DuoTPU +``` +docker run --privileged --name DuoTPU -v /workspace -it sophgo/tpuc_dev:v3.1 +``` + +## Log in to the Docker container + +After starting the container, you will automatically log in to the terminal interface of the Docker window. If you need to open a new window, you can do it as follows + +Use the `docker ps` command to view the current Docker container list +``` +PS C:\Users\Carbon\Duo-TPU> docker ps +CONTAINER ID IMAGE COMMAND +f3a060efb1d3 sophgo/tpuc_dev:v3.1 "/bin/bash" +``` + +Log in to the Docker container using the `CONTAINER ID` +``` +docker exec -it f3a060efb1d3 /bin/bash +``` + +In Docker terminal, check whether the current directory is `/workspace`. If not, use the `cd` command to enter the directory. +``` +# cd /workspace/ +``` + +![duo](/docs/duo/tpu/duo-tpu-docker_03.png) + + +## Get development kit and add environment variables + +Download the TPU-MLIR model conversion toolkit in the Docker terminal +``` +git clone https://github.com/milkv-duo/tpu-mlir.git +``` + +In the Docker terminal, use the `source` command to add environment variables +``` +# source ./tpu-mlir/envsetup.sh +``` diff --git a/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tpu/tpu-googlenet.md b/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tpu/tpu-googlenet.md new file mode 100644 index 00000000..0c24182f --- /dev/null +++ b/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tpu/tpu-googlenet.md @@ -0,0 +1,221 @@ +--- +sidebar_label: 'Googlenet Image Classification' +sidebar_position: 37 +--- + +# Image Classification Based on Googlenet + +## 1. Configure Docker development environment + +Refer to [here](https://milkv.io/docs/duo/application-development/tpu/tpu-docker). After configuring the Docker development environment, return here to continue the next step. + +:::warning +If you are using a configured Docker development environment, please make sure to follow the Docker configuration tutorial to execute command `source ./tpu-mlir/envsetup.sh` after starting Docker, otherwise errors may occur in subsequent steps. +::: + +## 2. Prepare the working directory in Docker + +Create and enter the `googlenet` working directory, note that it is a directory at the same level as `tpu-mlir`. +``` +# mkdir googlenet && cd googlenet +``` + +Get the original model +``` +wget https://media.githubusercontent.com/media/onnx/models/main/validated/vision/classification/inception_and_googlenet/googlenet/model/googlenet-12.onnx +``` + +Copy test image: +``` +# cp -rf ${TPUC_ROOT}/regression/dataset/ILSVRC2012/ . +# cp -rf ${TPUC_ROOT}/regression/image/ . +``` +`${TPUC_ROOT}` here is an environment variable, corresponding to the `tpu-mlir` directory, which is loaded in the `source ./tpu-mlir/envsetup.sh` step in the previous configuration of the Docker development environment. + +Create and enter the `work` working directory to store compiled files such as `MLIR` and `cvimodel` +``` +# mkdir work && cd work +``` + +## 3. ONNX Model Conversion + +:::tip +The Duo development board is equipped with the CV1800B chip, which supports the **ONNX series** and **Caffe models**. Currently, it does not support TFLite models. In terms of quantized data types, it supports **quantization in BF16 format** and **asymmetric quantization in INT8 format**. +::: + +### ONNX model converted to MLIR + +The model in this example is RGB input, `mean` and `scale` are `123.675`,`116.28`,`103.53` and `0.0171`,`0.0175`,`0.0174` respectively. The model conversion command is as follows: +``` +model_transform.py \ + --model_name googlenet \ + --model_def ../googlenet-12.onnx \ + --test_input ../image/cat.jpg \ + --input_shapes [[1,3,224,224]] \ + --resize_dims 256,256 \ + --mean 123.675,116.28,103.53 \ + --scale 0.0171,0.0175,0.0174 \ + --pixel_format rgb \ + --test_result googlenet_top_outputs.npz \ + --mlir googlenet.mlir +``` + +Example of successful operation + +![duo](/docs/duo/tpu/duo-tpu-googlenet_05.png) + +After converting to the MLIR model, a `googlenet.mlir` file will be generated, which is the MLIR model file. A `googlenet_in_f32.npz` file and a `googlenet_top_outputs.npz` file will also be generated, which are the input files for subsequent model conversion. + +![duo](/docs/duo/tpu/duo-tpu-googlenet_06.png) + +### MLIR to BF16 model + +The command to convert the MLIR model to the BF16 model is as follows: +``` +model_deploy.py \ + --mlir googlenet.mlir \ + --quantize BF16 \ + --chip cv180x \ + --test_input googlenet_in_f32.npz \ + --test_reference googlenet_top_outputs.npz \ + --model googlenet_bf16.cvimodel +``` + +:::tip +If the development board you are using is not Duo, please replace the fourth line `-- chip cv180x` in the above command with the corresponding chip model. +When using Duo 256M/Duo S , it should be changed to ` -- chip cv181x`. +::: + +Example of successful operation + +![duo](/docs/duo/tpu/duo-tpu-googlenet_07.png) + +After compilation is completed, the `googlenet_bf16.cvimodel` file will be generated. + +![duo](/docs/duo/tpu/duo-tpu-googlenet_08.png) + +### MLIR to INT8 model + +#### Generate calibration tables required for quantification + +Run `run_calibration.py` to get the calibration table. The number of input data should be about 100~1000 pieces depending on the situation. Here we use the existing 100 images from ILSVRC2012 as an example and execute the calibration command: +``` +run_calibration.py googlenet.mlir \ + --dataset ../ILSVRC2012 \ + --input_num 100 \ + -o googlenet_cali_table +``` + +Example of successful operation + +![duo](/docs/duo/tpu/duo-tpu-googlenet_09.png) + +After the operation is completed, the `googlenet_cali_table` file will be generated, which is used for subsequent compilation of the INT8 model. + +![duo](/docs/duo/tpu/duo-tpu-googlenet_10.png) + +#### MLIR quantized into INT8 asymmetric cvimodel + +The command to convert MLIR model to INT8 model is as follows: +``` +model_deploy.py \ + --mlir googlenet.mlir \ + --quantize INT8 \ + --calibration_table googlenet_cali_table \ + --chip cv180x \ + --test_input ../image/cat.jpg \ + --test_reference googlenet_top_outputs.npz \ + --compare_all \ + --fuse_preprocess \ + --model googlenet_int8_fuse.cvimodel +``` + +:::tip +If the development board you are using is not Duo, please replace the fifth line `-- chip cv180x` in the above command with the corresponding chip model. +When using Duo 256M/Duo S , it should be changed to ` -- chip cv181x`. +::: + +Example of successful operation + +![duo](/docs/duo/tpu/duo-tpu-googlenet_11.png) + +After compilation is completed, the `googlenet_int8_fuse.cvimodel` file will be generated. + +![duo](/docs/duo/tpu/duo-tpu-googlenet_12.png) + +## 4. Validate on Development Board Duo + +### Connecting the Duo development board + +Complete the connection between the Duo development board and the computer according to the previous tutorial, and use tools such as `mobaxterm` or `Xshell` to open a terminal to operate the Duo development board. + +### Get tpu-sdk + +Switch to the `/workspace` directory in the Docker terminal +``` +cd /workspace +``` + +Download tpu sdk, if you are using Duo, execute +``` +git clone https://github.com/milkv-duo/tpu-sdk-cv180x.git +mv ./tpu-sdk-cv180x ./tpu-sdk +``` + +Else,if you are using Duo 256M/Duo S , execute +``` +git clone https://github.com/milkv-duo/tpu-sdk-sg200x.git +mv ./tpu-sdk-sg200x ./tpu-sdk +``` + +### Copy tpu-sdk and model files to Duo + +In the terminal of the Duo board, create a new directory `/mnt/tpu/` +``` +# mkdir -p /mnt/tpu && cd /mnt/tpu +``` + +In the Docker terminal, copy `tpu-sdk` and model files to the Duo +``` +# scp -r /workspace/tpu-sdk root@192.168.42.1:/mnt/tpu/ +# scp /workspace/googlenet/work/googlenet_bf16.cvimodel root@192.168.42.1:/mnt/tpu/tpu-sdk/ +# scp /workspace/googlenet/work/googlenet_int8_fuse.cvimodel root@192.168.42.1:/mnt/tpu/tpu-sdk/ +``` + +### Set environment variables + +In the terminal of the Duo board, set the environment variables +``` +# cd /mnt/tpu/tpu-sdk +# source ./envs_tpu_sdk.sh +``` + +### Perform Image Classification + +On the Duo board, perform Image Classification on the image + +![duo](/docs/duo/tpu/duo-tpu-cat.jpg) + +Image classification using `googlenet_bf16.cvimodel` model +``` +./samples/bin/cvi_sample_classifier_bf16 \ + ./googlenet_bf16.cvimodel \ + ./samples/data/cat.jpg \ + ./samples/data/synset_words.txt +``` + +Example of successful classification results + +![duo](/docs/duo/tpu/duo-tpu-googlenet_13.png) + +Image classification using `googlenet_int8_fuse.cvimodel` model +``` +./samples/bin/cvi_sample_classifier_fused_preprocess \ + ./googlenet_int8_fuse.cvimodel \ + ./samples/data/cat.jpg \ + ./samples/data/synset_words.txt +``` + +Example of successful classification results + +![duo](/docs/duo/tpu/duo-tpu-googlenet_14.png) diff --git a/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tpu/tpu-introduction.md b/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tpu/tpu-introduction.md new file mode 100644 index 00000000..01f773d7 --- /dev/null +++ b/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tpu/tpu-introduction.md @@ -0,0 +1,18 @@ +--- +sidebar_label: 'Introduction' +sidebar_position: 10 +--- + +# Introduction + +Duo’s CPU CV1800B integrates CVITEK TPU for intelligent detection. + +TPU is an AI acceleration engine for deep learning neural networks, which can be used to accelerate image classification, object detection, face detection and recognition, segmentation, LSTM, and more. The main function of TPU is to offload CPU work and accelerate computer vision and voice-related operations. + +CV1800B TPU supported models: + +![duo](/docs/duo/tpu/duo-cv1800b-tpu-model_202307.png) + +:::tip +The Duo development board is equipped with the CV1800B chip, which supports the **ONNX series** and **Caffe models**. Currently, it does not support TFLite models. In terms of quantized data types, it supports **quantization in BF16 format** and **asymmetric quantization in INT8 format**. +::: diff --git a/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tpu/tpu-mobilenetv2.md b/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tpu/tpu-mobilenetv2.md new file mode 100644 index 00000000..8f0a8cb8 --- /dev/null +++ b/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tpu/tpu-mobilenetv2.md @@ -0,0 +1,206 @@ +--- +sidebar_label: 'MobileNetV2 Image Classification' +sidebar_position: 35 +--- + +# Image Classification Based on MobileNetV2 + +## 1. Configure Docker development environment + +Refer to [here](https://milkv.io/docs/duo/application-development/tpu/tpu-docker). After configuring the Docker development environment, return here to continue the next step. + +:::warning +If you are using a configured Docker development environment, please make sure to follow the Docker configuration tutorial to execute command `source ./tpu-mlir/envsetup.sh` after starting Docker, otherwise errors may occur in subsequent steps. +::: + +## 2. Prepare the working directory in Docker + +Create and enter the `mobilenet_v2` working directory, note that it is a directory at the same level as `tpu-mlir`. +``` +# mkdir mobilenet_v2 && cd mobilenet_v2 +``` + +Download the MobileNet model from the official website: +``` +git clone https://github.com/shicai/MobileNet-Caffe.git +``` + +Place the model files in the cloned `MobileNet-Caffe` directory and the image files in the `tpu-mlir` tool chain directory into the current directory. +``` +# cp MobileNet-Caffe/mobilenet_v2_deploy.prototxt . +# cp MobileNet-Caffe/mobilenet_v2.caffemodel . +# cp -rf ${TPUC_ROOT}/regression/dataset/ILSVRC2012/ . +# cp -rf ${TPUC_ROOT}/regression/image/ . +``` +`${TPUC_ROOT}` here is an environment variable, corresponding to the `tpu-mlir` directory, which is loaded in the `source ./tpu-mlir/envsetup.sh` step in the previous configuration of the Docker development environment. + +Create and enter the `work` working directory to store compiled files such as `MLIR` and `cvimodel` +``` +# mkdir work && cd work +``` + +## 3. MobileNet-Caffe Model Conversion + +:::tip +The Duo development board is equipped with the CV1800B chip, which supports the **ONNX series** and **Caffe models**. Currently, it does not support TFLite models. In terms of quantized data types, it supports **quantization in BF16 format** and **asymmetric quantization in INT8 format**. +::: + +The steps for model conversion are as follows: +- Convert Caffe model to MLIR +- Generate calibration tables required for quantification +- MLIR quantization into INT8 asymmetric cvimodel + +### Caffe model converted to MLIR + +The model input are pictures. Before converting the model, we need to understand the preprocessing of the model. If the model uses preprocessed npz files as input, there is no need to consider preprocessing. The preprocessing process is expressed as follows ($x$ represents the input): $$ y = (x-mean)\times scale $$ + +The model in this example is BGR input, `mean` and `scale` are `103.94`, `116.78`, `123.68` and `0.017`, `0.017`, `0.017` respectively. The model conversion command is as follows: +``` +model_transform.py \ + --model_name mobilenet_v2 \ + --model_def ../mobilenet_v2_deploy.prototxt \ + --model_data ../mobilenet_v2.caffemodel \ + --input_shapes [[1,3,224,224]] \ + --resize_dims=256,256 \ + --mean 103.94,116.78,123.68 \ + --scale 0.017,0.017,0.017 \ + --pixel_format bgr \ + --test_input ../image/cat.jpg \ + --test_result mobilenet_v2_top_outputs.npz \ + --mlir mobilenet_v2.mlir +``` + +Example of successful operation + +![duo](/docs/duo/tpu/duo-tpu-mobilenetv2_05.png) + +After converting to the MLIR model, a `mobilenet_v2.mlir` file will be generated, which is the MLIR model file. A `mobilenet_v2_in_f32.npz` file and a `mobilenet_v2_top_outputs.npz` file will also be generated, which are the input files for subsequent model conversion. + +![duo](/docs/duo/tpu/duo-tpu-mobilenetv2_06.png) + +### MLIR to INT8 model + +#### Generate calibration tables required for quantification + +Run `run_calibration.py` to get the calibration table. The number of input data should be about 100~1000 pieces depending on the situation. Here we use the existing 100 images from ILSVRC2012 as an example and execute the calibration command: + +``` +run_calibration.py mobilenet_v2.mlir \ + --dataset ../ILSVRC2012 \ + --input_num 100 \ + -o mobilenet_v2_cali_table +``` + +Example of successful operation + +![duo](/docs/duo/tpu/duo-tpu-mobilenetv2_07.png) + +After the operation is completed, the `mobilenet_v2_cali_table` file will be generated, which is used for subsequent compilation of the INT8 model. + +![duo](/docs/duo/tpu/duo-tpu-mobilenetv2_08.png) + +#### MLIR quantized into INT8 asymmetric cvimodel + +Use the `model_deploy.py` script parameter to use `asymmetric` for asymmetric quantization and convert the MLIR file into an INT8 asymmetric quantization model: +``` +model_deploy.py \ + --mlir mobilenet_v2.mlir \ + --asymmetric \ + --calibration_table mobilenet_v2_cali_table \ + --fuse_preprocess \ + --customization_format BGR_PLANAR \ + --chip cv180x \ + --quantize INT8 \ + --test_input ../image/cat.jpg \ + --model mobilenet_v2_int8_asym.cvimodel +``` + +:::tip +If the development board you are using is not Duo, please replace the seventh line `-- chip cv180x` in the above command with the corresponding chip model. +When using Duo 256M/Duo S , it should be changed to ` -- chip cv181x`. +::: + +Example of successful operation + +![duo](/docs/duo/tpu/duo-tpu-mobilenetv2_09.png) + +After compilation is completed, the `mobilenet_v2_int8_asym.cvimodel` file will be generated. + +![duo](/docs/duo/tpu/duo-tpu-mobilenetv2_10.png) + +## 4. Validate on Development Board Duo + +### Connecting the Duo development board + +Complete the connection between the Duo development board and the computer according to the previous tutorial, and use tools such as `mobaxterm` or `Xshell` to open a terminal to operate the Duo development board. + +### Get tpu-sdk + +Switch to the `/workspace` directory in the Docker terminal +``` +cd /workspace +``` + +Download tpu sdk, if you are using Duo, execute +``` +git clone https://github.com/milkv-duo/tpu-sdk-cv180x.git +mv ./tpu-sdk-cv180x ./tpu-sdk +``` + +Else,if you are using Duo 256M/Duo S , execute +``` +git clone https://github.com/milkv-duo/tpu-sdk-sg200x.git +mv ./tpu-sdk-sg200x ./tpu-sdk +``` + +### Copy tpu-sdk and model files to Duo + +In the terminal of the Duo board, create a new directory `/mnt/tpu/` +``` +# mkdir -p /mnt/tpu && cd /mnt/tpu +``` + +In the Docker terminal, copy `tpu-sdk` and model files to the Duo +``` +# scp -r /workspace/tpu-sdk root@192.168.42.1:/mnt/tpu/ +# scp /workspace/mobilenet_v2/work/mobilenet_v2_int8_asym.cvimodel root@192.168.42.1:/mnt/tpu/tpu-sdk/ +``` + +### Set environment variables + +In the terminal of the Duo board, set the environment variables +``` +# cd /mnt/tpu/tpu-sdk +# source ./envs_tpu_sdk.sh +``` + +### Perform Image Classification + +On the Duo board, perform Image Classification on the image + +![duo](/docs/duo/tpu/duo-tpu-cat.jpg) + +Enter the samples directory + +``` +# cd samples +``` + +View cvimodel info +``` +./bin/cvi_sample_model_info ../mobilenet_v2_int8_asym.cvimodel +``` + +![duo](/docs/duo/tpu/duo-tpu-mobilenetv2_11.png) + +Perform image classification test +``` +./bin/cvi_sample_classifier_fused_preprocess \ + ../mobilenet_v2_int8_asym.cvimodel \ + ./data/cat.jpg \ + ./data/synset_words.txt +``` + +Example of successful classification results + +![duo](/docs/duo/tpu/duo-tpu-mobilenetv2_12.png) diff --git a/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tpu/tpu-resnet18.md b/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tpu/tpu-resnet18.md new file mode 100644 index 00000000..a695f6f5 --- /dev/null +++ b/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tpu/tpu-resnet18.md @@ -0,0 +1,194 @@ +--- +sidebar_label: 'Resnet18 Image Classification' +sidebar_position: 40 +--- + +# Image Classification Based on Resnet18 + +## 1. Configure Docker development environment + +Refer to [here](https://milkv.io/docs/duo/application-development/tpu/tpu-docker). After configuring the Docker development environment, return here to continue the next step. + +:::warning +If you are using a configured Docker development environment, please make sure to follow the Docker configuration tutorial to execute command `source ./tpu-mlir/envsetup.sh` after starting Docker, otherwise errors may occur in subsequent steps. +::: + +## 2. Prepare the working directory in Docker + +Create and enter the `resnet18` working directory, note that it is a directory at the same level as `tpu-mlir`. +``` +# mkdir resnet18 && cd resnet18 +``` + +Get the original model +``` +# wget https://github.com/onnx/models/raw/main/validated/vision/classification/resnet/model/resnet18-v1-7.tar.gz +``` +Extract `resnet18-v1-7.tar.gz` +``` +# tar -zxvf resnet18-v1-7.tar.gz +``` +After extraction is complete, the `resnet18-v1-7` folder will be generated in the current directory, which contains the `resnet18-v1-7.onnx` model file. + +Copy test image: +``` +# cp -rf ${TPUC_ROOT}/regression/dataset/ILSVRC2012/ . +# cp -rf ${TPUC_ROOT}/regression/image/ . +``` +`${TPUC_ROOT}` here is an environment variable, corresponding to the `tpu-mlir` directory, which is loaded in the `source ./tpu-mlir/envsetup.sh` step in the previous configuration of the Docker development environment. + +Create and enter the `work` working directory to store compiled files such as `MLIR` and `cvimodel` +``` +# mkdir work && cd work +``` + +## 3. ONNX Model Conversion + +:::tip +The Duo development board is equipped with the CV1800B chip, which supports the **ONNX series** and **Caffe models**. Currently, it does not support TFLite models. In terms of quantized data types, it supports **quantization in BF16 format** and **asymmetric quantization in INT8 format**. +::: + +The steps for model conversion are as follows: +- Convert ONNX model to MLIR +- Generate calibration tables required for quantification +- MLIR quantization into INT8 asymmetric cvimodel + +### ONNX model converted to MLIR + +The model in this example is RGB input, `mean` and `scale` are `123.675`,`116.28`,`103.53` and `0.0171`,`0.0175`,`0.0174` respectively. + +The command to convert an ONNX model to an MLIR model is as follows: +``` +model_transform.py \ + --model_name resnet18 \ + --model_def ../resnet18-v1-7/resnet18-v1-7.onnx \ + --test_input ../image/cat.jpg \ + --input_shapes [[1,3,224,224]] \ + --resize_dims 256,256 \ + --mean 123.675,116.28,103.53 \ + --scale 0.0171,0.0175,0.0174 \ + --pixel_format rgb \ + --test_result resnet18_top_outputs.npz \ + --mlir resnet18.mlir +``` + +Example of successful operation + +![duo](/docs/duo/tpu/duo-tpu-resnet18_05.png) + +After converting to the MLIR model, a `resnet18.mlir` file will be generated, which is the MLIR model file. A `resnet18_in_f32.npz` file and a `resnet18_top_outputs.npz` file will also be generated, which are the input files for subsequent model conversion. + +![duo](/docs/duo/tpu/duo-tpu-resnet18_06.png) + +### MLIR to INT8 model + +#### Generate calibration tables required for quantification + +Before converting to the INT8 model, you need to generate a calibration table. Here we use the existing 100 pictures from ILSVRC2012 as an example and execute the calibration command: +``` +run_calibration.py resnet18.mlir \ + --dataset ../ILSVRC2012 \ + --input_num 100 \ + -o resnet18_cali_table +``` + +Example of successful operation + +![duo](/docs/duo/tpu/duo-tpu-resnet18_07.png) + +After the operation is completed, the `resnet18_cali_table` file will be generated, which is used for subsequent compilation of the INT8 model. + +![duo](/docs/duo/tpu/duo-tpu-resnet18_08.png) + +#### MLIR quantized into INT8 asymmetric cvimodel + +The command to convert MLIR model to INT8 model is as follows: +``` +model_deploy.py \ + --mlir resnet18.mlir \ + --quantize INT8 \ + --calibration_table resnet18_cali_table \ + --chip cv180x \ + --test_input ../image/cat.jpg \ + --test_reference resnet18_top_outputs.npz \ + --compare_all \ + --fuse_preprocess \ + --model resnet18_int8_fuse.cvimodel +``` + +:::tip +If the development board you are using is not Duo, please replace the fifth line `-- chip cv180x` in the above command with the corresponding chip model. +When using Duo 256M/Duo S , it should be changed to ` -- chip cv181x`. +::: + +Example of successful operation + +![duo](/docs/duo/tpu/duo-tpu-resnet18_09.png) + +After compilation is completed, the `resnet18_int8_fuse.cvimodel` file will be generated. + +![duo](/docs/duo/tpu/duo-tpu-resnet18_10.png) + +## 4. Validate on Development Board Duo + +### Connecting the Duo development board + +Complete the connection between the Duo development board and the computer according to the previous tutorial, and use tools such as `mobaxterm` or `Xshell` to open a terminal to operate the Duo development board. + +### Get tpu-sdk + +Switch to the `/workspace` directory in the Docker terminal +``` +cd /workspace +``` + +Download tpu sdk, if you are using Duo, execute +``` +git clone https://github.com/milkv-duo/tpu-sdk-cv180x.git +mv ./tpu-sdk-cv180x ./tpu-sdk +``` + +Else,if you are using Duo 256M/Duo S , execute +``` +git clone https://github.com/milkv-duo/tpu-sdk-sg200x.git +mv ./tpu-sdk-sg200x ./tpu-sdk +``` + +### Copy tpu-sdk and model files to Duo + +In the terminal of the Duo board, create a new directory `/mnt/tpu/` +``` +# mkdir -p /mnt/tpu && cd /mnt/tpu +``` + +In the Docker terminal, copy `tpu-sdk` and model files to the Duo +``` +# scp -r /workspace/tpu-sdk root@192.168.42.1:/mnt/tpu/ +# scp /workspace/resnet18/work/resnet18_int8_fuse.cvimodel root@192.168.42.1:/mnt/tpu/tpu-sdk/ +``` + +### Set environment variables + +In the terminal of the Duo board, set the environment variables +``` +# cd /mnt/tpu/tpu-sdk +# source ./envs_tpu_sdk.sh +``` + +### Perform Image Classification + +On the Duo board, perform Image Classification on the image + +![duo](/docs/duo/tpu/duo-tpu-cat.jpg) + +Image classification using `resnet18_int8_fuse.cvimodel` model: +``` +./samples/bin/cvi_sample_classifier_fused_preprocess \ + ./resnet18_int8_fuse.cvimodel \ + ./samples/data/cat.jpg \ + ./samples/data/synset_words.txt +``` + +Example of successful classification results + +![duo](/docs/duo/tpu/duo-tpu-resnet18_11.png) diff --git a/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tpu/tpu-shufflenetv2.md b/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tpu/tpu-shufflenetv2.md new file mode 100644 index 00000000..7505d14d --- /dev/null +++ b/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tpu/tpu-shufflenetv2.md @@ -0,0 +1,219 @@ +--- +sidebar_label: 'ShuffleNetV2 Image Classification' +sidebar_position: 36 +--- + +# Image Classification Based on ShuffleNetV2 + +## 1. Configure Docker development environment + +Refer to [here](https://milkv.io/docs/duo/application-development/tpu/tpu-docker). After configuring the Docker development environment, return here to continue the next step. + +:::warning +If you are using a configured Docker development environment, please make sure to follow the Docker configuration tutorial to execute command `source ./tpu-mlir/envsetup.sh` after starting Docker, otherwise errors may occur in subsequent steps. +::: + +## 2. Prepare the working directory in Docker + +Create and enter the `shufflenet_v2` working directory, note that it is a directory at the same level as `tpu-mlir`. +``` +# mkdir shufflenet_v2 && cd shufflenet_v2 +``` + +Copy test image: +``` +# cp -rf ${TPUC_ROOT}/regression/dataset/ILSVRC2012/ . +# cp -rf ${TPUC_ROOT}/regression/image/ . +``` +`${TPUC_ROOT}` here is an environment variable, corresponding to the `tpu-mlir` directory, which is loaded in the `source ./tpu-mlir/envsetup.sh` step in the previous configuration of the Docker development environment. + +Create a new `export.py` file and write the following code in the file: +``` +import torch +from torchvision.models.shufflenetv2 import shufflenet_v2_x1_0 +model = shufflenet_v2_x1_0(pretrained=True) +model.eval() +torch.jit.trace(model, torch.randn(1, 3, 640, 640)).save("./shufflenetv2_jit.pt") +``` + +Run the `export.py` file: +``` +python export.py +``` + +Example of successful operation + +![duo](/docs/duo/tpu/duo-tpu-shufflenetv2_05.png) + +The `shufflenetv2_jit.pt` file will be generated in the current directory, which is the required original model file. + +Create and enter the `work` working directory to store compiled files such as `MLIR` and `cvimodel` +``` +# mkdir work && cd work +``` + +## 3. ShuffleNetV2-PyTorch Model Conversion + +:::tip +The Duo development board is equipped with the CV1800B chip, which supports the **ONNX series** and **Caffe models**. Currently, it does not support TFLite models. In terms of quantized data types, it supports **quantization in BF16 format** and **asymmetric quantization in INT8 format**. +::: + +The steps for model conversion are as follows: +- Convert PyTorch model to MLIR +- Generate calibration tables required for quantification +- MLIR quantization into INT8 asymmetric cvimodel + + +### PyTorch model converted to MLIR + +The model input are pictures. Before converting the model, we need to understand the preprocessing of the model. If the model uses preprocessed npz files as input, there is no need to consider preprocessing. The preprocessing process is expressed as follows ($x$ represents the input): $$ y = (x-mean)\times scale $$ + +The model in this example is BGR input, `mean` and `scale` are `103.94`, `116.78`, `123.68` and `0.017`, `0.017`, `0.017` respectively. The model conversion command is as follows: +``` +model_transform.py \ + --model_name shufflenet_v2 \ + --model_def ../shufflenetv2_jit.pt \ + --input_shapes [[1,3,224,224]] \ + --resize_dims=256,256 \ + --mean 103.94,116.78,123.68 \ + --scale 0.017,0.017,0.017 \ + --pixel_format bgr \ + --test_input ../image/cat.jpg \ + --test_result shufflenet_v2_top_outputs.npz \ + --mlir shufflenet_v2.mlir +``` + +Example of successful operation + +![duo](/docs/duo/tpu/duo-tpu-shufflenetv2_06.png) + +After converting to the MLIR model, a `shufflenet_v2.mlir` file will be generated, which is the MLIR model file. A `shufflenet_v2_in_f32.npz` file and a `shufflenet_v2_top_outputs.npz` file will also be generated, which are the input files for subsequent model conversion. + +![duo](/docs/duo/tpu/duo-tpu-shufflenetv2_07.png) + +### MLIR to INT8 model + +#### Generate calibration tables required for quantification + +Run `run_calibration.py` to get the calibration table. The number of input data should be about 100~1000 pieces depending on the situation. Here we use the existing 100 images from ILSVRC2012 as an example and execute the calibration command: +``` +run_calibration.py shufflenet_v2.mlir \ + --dataset ../ILSVRC2012 \ + --input_num 100 \ + -o shufflenet_v2_cali_table +``` + +Example of successful operation + +![duo](/docs/duo/tpu/duo-tpu-shufflenetv2_08.png) + +After the operation is completed, the `shufflenet_v2_cali_table` file will be generated, which is used for subsequent compilation of the INT8 model. + +![duo](/docs/duo/tpu/duo-tpu-shufflenetv2_09.png) + +#### MLIR quantized into INT8 asymmetric cvimodel + +Use the `model_deploy.py` script parameter to use `asymmetric` for asymmetric quantization and convert the MLIR file into an INT8 asymmetric quantization model: +``` +model_deploy.py \ + --mlir shufflenet_v2.mlir \ + --asymmetric \ + --calibration_table shufflenet_v2_cali_table \ + --fuse_preprocess \ + --customization_format BGR_PLANAR \ + --chip cv180x \ + --quantize INT8 \ + --test_input ../image/cat.jpg \ + --tolerance 0.96,0.72 \ + --model shufflenet_v2_int8_asym.cvimodel +``` + +:::tip +If the development board you are using is not Duo, please replace the seventh line `-- chip cv180x` in the above command with the corresponding chip model. +When using Duo 256M/Duo S , it should be changed to ` -- chip cv181x`. +::: + +Example of successful operation + +![duo](/docs/duo/tpu/duo-tpu-shufflenetv2_10.png) + +After compilation is completed, the `shufflenet_v2_int8_asym.cvimodel` file will be generated. + +![duo](/docs/duo/tpu/duo-tpu-shufflenetv2_11.png) + +## 4. Validate on Development Board Duo + +### Connecting the Duo development board + +Complete the connection between the Duo development board and the computer according to the previous tutorial, and use tools such as `mobaxterm` or `Xshell` to open a terminal to operate the Duo development board. + +### Get tpu-sdk + +Switch to the `/workspace` directory in the Docker terminal +``` +cd /workspace +``` + +Download tpu sdk, if you are using Duo, execute +``` +git clone https://github.com/milkv-duo/tpu-sdk-cv180x.git +mv ./tpu-sdk-cv180x ./tpu-sdk +``` + +Else,if you are using Duo 256M/Duo S , execute +``` +git clone https://github.com/milkv-duo/tpu-sdk-sg200x.git +mv ./tpu-sdk-sg200x ./tpu-sdk +``` + +### Copy tpu-sdk and model files to Duo + +In the terminal of the Duo board, create a new directory `/mnt/tpu/` +``` +# mkdir -p /mnt/tpu && cd /mnt/tpu +``` + +In the Docker terminal, copy `tpu-sdk` and model files to the Duo +``` +# scp -r /workspace/tpu-sdk root@192.168.42.1:/mnt/tpu/ +# scp /workspace/shufflenet_v2/work/shufflenet_v2_int8_asym.cvimodel root@192.168.42.1:/mnt/tpu/tpu-sdk/ +``` + +### Set environment variables + +In the terminal of the Duo board, set the environment variables +``` +# cd /mnt/tpu/tpu-sdk +# source ./envs_tpu_sdk.sh +``` + +### Perform Image Classification + +On the Duo board, perform Image Classification on the image + +![duo](/docs/duo/tpu/duo-tpu-cat.jpg) + +Enter the samples directory + +``` +# cd samples +``` + +View cvimodel info +``` +./bin/cvi_sample_model_info ../shufflenet_v2_int8_asym.cvimodel +``` + +![duo](/docs/duo/tpu/duo-tpu-shufflenetv2_12.png) + +Perform image classification test +``` +./bin/cvi_sample_classifier_fused_preprocess \ + ../shufflenet_v2_int8_asym.cvimodel \ + ./data/cat.jpg \ + ./data/synset_words.txt +``` + +Example of successful classification results + +![duo](/docs/duo/tpu/duo-tpu-shufflenetv2_13.png) diff --git a/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tpu/tpu-squeezenet.md b/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tpu/tpu-squeezenet.md new file mode 100644 index 00000000..9c8f05fa --- /dev/null +++ b/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tpu/tpu-squeezenet.md @@ -0,0 +1,194 @@ +--- +sidebar_label: 'Squeezenet Image Classification' +sidebar_position: 38 +--- + +# Image Classification Based on Squeezenet + +## 1. Configure Docker development environment + +Refer to [here](https://milkv.io/docs/duo/application-development/tpu/tpu-docker). After configuring the Docker development environment, return here to continue the next step. + +:::warning +If you are using a configured Docker development environment, please make sure to follow the Docker configuration tutorial to execute command `source ./tpu-mlir/envsetup.sh` after starting Docker, otherwise errors may occur in subsequent steps. +::: + +## 2. Prepare the working directory in Docker + +Create and enter the `squeezenet1.1` working directory, note that it is a directory at the same level as `tpu-mlir`. +``` +# mkdir squeezenet1.1 && cd squeezenet1.1 +``` + +Get the original model +``` +# wget https://media.githubusercontent.com/media/onnx/models/main/validated/vision/classification/squeezenet/model/squeezenet1.1-7.tar.gz +``` +Extract `squeezenet1.1-7.tar.gz` +``` +# tar -zxvf squeezenet1.1-7.tar.gz +``` +After extraction is complete, the `squeezenet1.1` folder will be generated in the current directory, which contains the `squeezenet1.1.onnx` model file. + +Copy test image: +``` +# cp -rf ${TPUC_ROOT}/regression/dataset/ILSVRC2012/ . +# cp -rf ${TPUC_ROOT}/regression/image/ . +``` +`${TPUC_ROOT}` here is an environment variable, corresponding to the `tpu-mlir` directory, which is loaded in the `source ./tpu-mlir/envsetup.sh` step in the previous configuration of the Docker development environment. + +Create and enter the `work` working directory to store compiled files such as `MLIR` and `cvimodel` +``` +# mkdir work && cd work +``` + +## 3. ONNX Model Conversion + +:::tip +The Duo development board is equipped with the CV1800B chip, which supports the **ONNX series** and **Caffe models**. Currently, it does not support TFLite models. In terms of quantized data types, it supports **quantization in BF16 format** and **asymmetric quantization in INT8 format**. +::: + +The steps for model conversion are as follows: +- Convert ONNX model to MLIR +- Generate calibration tables required for quantification +- MLIR quantization into INT8 asymmetric cvimodel + +### ONNX model converted to MLIR + +The model in this example is RGB input, `mean` and `scale` are `123.675`,`116.28`,`103.53` and `0.0171`,`0.0175`,`0.0174` respectively. + +The command to convert an ONNX model to an MLIR model is as follows: +``` +model_transform.py \ + --model_name squeezenet1.1 \ + --model_def ../squeezenet1.1/squeezenet1.1.onnx \ + --test_input ../image/cat.jpg \ + --input_shapes [[1,3,224,224]] \ + --resize_dims 256,256 \ + --mean 123.675,116.28,103.53 \ + --scale 0.0171,0.0175,0.0174 \ + --pixel_format rgb \ + --test_result squeezenet1.1_top_outputs.npz \ + --mlir squeezenet1.1.mlir +``` + +Example of successful operation + +![duo](/docs/duo/tpu/duo-tpu-squeezenet_05.png) + +After converting to the MLIR model, a `squeezenet1.1.mlir` file will be generated, which is the MLIR model file. A `squeezenet1.1_in_f32.npz` file and a `squeezenet1.1_top_outputs.npz` file will also be generated, which are the input files for subsequent model conversion. + +![duo](/docs/duo/tpu/duo-tpu-squeezenet_06.png) + +### MLIR to INT8 model + +#### Generate calibration tables required for quantification + +Before converting to the INT8 model, you need to generate a calibration table. Here we use the existing 100 pictures from ILSVRC2012 as an example and execute the calibration command: +``` +run_calibration.py squeezenet1.1.mlir \ + --dataset ../ILSVRC2012 \ + --input_num 100 \ + -o squeezenet1.1_cali_table +``` + +Example of successful operation + +![duo](/docs/duo/tpu/duo-tpu-squeezenet_07.png) + +After the operation is completed, the `squeezenet1.1_cali_table` file will be generated, which is used for subsequent compilation of the INT8 model. + +![duo](/docs/duo/tpu/duo-tpu-squeezenet_08.png) + +#### MLIR quantized into INT8 asymmetric cvimodel + +The command to convert MLIR model to INT8 model is as follows: +``` +model_deploy.py \ + --mlir squeezenet1.1.mlir \ + --quantize INT8 \ + --calibration_table squeezenet1.1_cali_table \ + --chip cv180x \ + --test_input ../image/cat.jpg \ + --test_reference squeezenet1.1_top_outputs.npz \ + --compare_all \ + --fuse_preprocess \ + --model squeezenet1.1_int8_fuse.cvimodel +``` + +:::tip +If the development board you are using is not Duo, please replace the fifth line `-- chip cv180x` in the above command with the corresponding chip model. +When using Duo 256M/Duo S , it should be changed to ` -- chip cv181x`. +::: + +Example of successful operation + +![duo](/docs/duo/tpu/duo-tpu-squeezenet_09.png) + +After compilation is completed, the `squeezenet1.1_int8_fuse.cvimodel` file will be generated. + +![duo](/docs/duo/tpu/duo-tpu-squeezenet_10.png) + +## 4. Validate on Development Board Duo + +### Connecting the Duo development board + +Complete the connection between the Duo development board and the computer according to the previous tutorial, and use tools such as `mobaxterm` or `Xshell` to open a terminal to operate the Duo development board. + +### Get tpu-sdk + +Switch to the `/workspace` directory in the Docker terminal +``` +cd /workspace +``` + +Download tpu sdk, if you are using Duo, execute +``` +git clone https://github.com/milkv-duo/tpu-sdk-cv180x.git +mv ./tpu-sdk-cv180x ./tpu-sdk +``` + +Else,if you are using Duo 256M/Duo S , execute +``` +git clone https://github.com/milkv-duo/tpu-sdk-sg200x.git +mv ./tpu-sdk-sg200x ./tpu-sdk +``` + +### Copy tpu-sdk and model files to Duo + +In the terminal of the Duo board, create a new directory `/mnt/tpu/` +``` +# mkdir -p /mnt/tpu && cd /mnt/tpu +``` + +In the Docker terminal, copy `tpu-sdk` and model files to the Duo +``` +# scp -r /workspace/tpu-sdk root@192.168.42.1:/mnt/tpu/ +# scp /workspace/squeezenet1.1/work/squeezenet1.1_int8_fuse.cvimodel root@192.168.42.1:/mnt/tpu/tpu-sdk/ +``` + +### Set environment variables + +In the terminal of the Duo board, set the environment variables +``` +# cd /mnt/tpu/tpu-sdk +# source ./envs_tpu_sdk.sh +``` + +### Perform Image Classification + +On the Duo board, perform Image Classification on the image + +![duo](/docs/duo/tpu/duo-tpu-cat.jpg) + +Image classification using `squeezenet1.1_int8_fuse.cvimodel` model: +``` +./samples/bin/cvi_sample_classifier_fused_preprocess \ + ./squeezenet1.1_int8_fuse.cvimodel \ + ./samples/data/cat.jpg \ + ./samples/data/synset_words.txt +``` + +Example of successful classification results + +![duo](/docs/duo/tpu/duo-tpu-squeezenet_11.png) diff --git a/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tpu/tpu-yolov5.md b/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tpu/tpu-yolov5.md new file mode 100644 index 00000000..5f867340 --- /dev/null +++ b/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/tpu/tpu-yolov5.md @@ -0,0 +1,321 @@ +--- +sidebar_label: 'YOLOv5 Object Detection' +sidebar_position: 30 +--- + +# Object Detection Based on YOLOv5 + +## 1. Prepare original model files under windows + +### Prepare the YOLOv5 development kit and yolov5n.pt file + +Download the [YOLOv5 development toolkit](https://codeload.github.com/ultralytics/yolov5/zip/refs/heads/master) and the [yolov5n.pt](https://github.com/ultralytics/yolov5/releases/download/v6.2/yolov5n.pt) file. Once the download is complete, extract the toolkit and place the `yolov5n.pt` file in the `yolov5-master` directory. + +### Configure the conda environment + +[Anaconda](https://www.anaconda.com/) needs to be installed in advance. + +Open a new `Anaconda Prompt` terminal and execute `conda env list` to view the current environment. +``` +(base) C:\Users\Carbon> conda env list +# conda environments: +# +base * C:\Users\Carbon\anaconda3 +``` + +Create a new conda virtual environment and install version 3.9.0 of python. `duotpu` is the name you chose. +``` +(base) C:\Users\Carbon> conda create --name duotpu python=3.9.0 +``` + +Check the current environment again after success. +``` +(base) C:\Users\Carbon> conda env list +# conda environments: +# +base * C:\Users\Carbon\anaconda3 +duotpu C:\Users\Carbon\anaconda3\envs\duotpu +``` + +Activate the newly installed 3.9.0 environment. +``` +(base) C:\Users\Carbon> conda activate duotpu +``` + +Confirm that the activation is successful. +``` +(duotpu) C:\Users\Carbon> conda env list +# conda environments: +# +base C:\Users\Carbon\anaconda3 +duotpu * C:\Users\Carbon\anaconda3\envs\duotpu +``` + +Then, you can use the following command to install PyTorch version 1.12.1. Please choose the specific installation command based on your requirements. The subsequent process only requires the use of CPU. +``` +# CUDA 10.2 +conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=10.2 -c pytorch + +# CUDA 11.3 +conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=11.3 -c pytorch + +# CUDA 11.6 +conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=11.6 -c pytorch + +# CPU Only +conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cpuonly -c pytorch +``` + +Then `cd` the terminal path to the `yolov5-master` path of the development kit and enter `pip install -r requirements.txt` to install other dependencies. +``` +(duotpu) C:\Users\Carbon> cd Duo-TPU\yolov5-master + +(duotpu) C:\Users\Carbon\Duo-TPU\yolov5-master> pip install -r requirements.txt +``` + +### Generate original model file + +Create a new `main.py` file in the `yolov5-master` directory and write the following code in the file: +``` +import torch +from models.experimental import attempt_download +model = torch.load(attempt_download("./yolov5n.pt"), +map_location=torch.device('cpu'))['model'].float() +model.eval() +model.model[-1].export = True +torch.jit.trace(model, torch.rand(1, 3, 640, 640), strict=False).save('./yolov5n_jit.pt') +``` + +Then find the `yolov5-master/models/yolo.py` file, comment the code from lines 99 to 115, and add the code `return x` on line 116, as shown below: + +![duo](/docs/duo/tpu/duo-tpu-yolo5_01.png) + +In addition, this file also needs to be modified: +``` +C:\Users\Carbon\anaconda3\envs\duotpu\Lib\site-packages\torch\nn\modules\upsampling.py +``` +When using conda on linux the file is located at: +``` +~/anaconda3/envs/duotpu/lib/python3.9/site-packages/torch/nn/modules/upsampling.py +``` +Make the following changes around line 153 + +![duo](/docs/duo/tpu/duo-tpu-yolo5_02.png) + +After the modification is completed, run the `python main.py` file and the `yolov5n_jit.pt` file will be generated in the `yolov5-master` directory. This file is the required original model file. +``` +(duotpu) C:\Users\Carbon\Duo-TPU\yolov5-master> python main.py +``` + +### Exit the conda environment (optional) + +The model files we need have been generated above. You can use the `conda deactivate` command to exit the conda environment: +``` +(duotpu) C:\Users\Carbon\Duo-TPU\yolov5-master> conda deactivate +``` + +If you no longer need this conda virtual environment (duotpu), you can delete it with the following command: +``` +conda env remove --name +``` + +## 2. Configure Docker development environment + +Refer to [here](https://milkv.io/docs/duo/application-development/tpu/tpu-docker). After configuring the Docker development environment, return here to continue the next step. + +:::warning +If you are using a configured Docker development environment, please make sure to follow the Docker configuration tutorial to execute command `source ./tpu-mlir/envsetup.sh` after starting Docker, otherwise errors may occur in subsequent steps. +::: + +## 3. Prepare the working directory in Docker + +Create and enter the `yolov5n_torch` working directory, note that it is a directory at the same level as `tpu-mlir`, and put the model files and image files into this directory +``` +# mkdir yolov5n_torch && cd yolov5n_torch +``` + +Create a new Windows terminal and copy `yolov5n_jit.pt` from windows to Docker +``` +docker cp /yolov5-master/yolov5n_jit.pt :/workspace/yolov5n_torch/yolov5n_jit.pt +``` + +`` is the file directory where the yolov5 development kit is located in the windows system, and `` is the container name, such as +``` +docker cp C:\Users\Carbon\Duo-TPU\yolov5-master\yolov5n_jit.pt DuoTPU:/workspace/yolov5n_torch/yolov5n_jit.pt +``` + +Go back to the Docker terminal and put the image file into the current directory (`yolov5n_torch`) +``` +# cp -rf ${TPUC_ROOT}/regression/dataset/COCO2017 . +# cp -rf ${TPUC_ROOT}/regression/image . +``` +`${TPUC_ROOT}` here is an environment variable, corresponding to the `tpu-mlir` directory, which is loaded in the `source ./tpu-mlir/envsetup.sh` step in the previous configuration of the Docker development environment. + +Create and enter the `work` working directory to store compiled files such as `MLIR` and `cvimodel` +``` +# mkdir work && cd work +``` + +## 4. YOLOv5n-TORCH Model conversion + +:::tip +The Duo development board is equipped with the CV1800B chip, which supports the **ONNX series** and **Caffe models**. Currently, it does not support TFLite models. In terms of quantized data types, it supports **quantization in BF16 format** and **asymmetric quantization in INT8 format**. +::: + +The steps for model conversion are as follows: +- Convert TORCH model to MLIR +- Generate calibration tables required for quantification +- MLIR quantization into INT8 asymmetric cvimodel + +### TORCH model converted to MLIR + +In this example, the model is RGB input, `mean` and `scale` are `0,0,0` and `0.0039216`, `0.0039216`, `0.0039216` respectively +The command to convert TORCH model to MLIR model is as follows + ``` +# model_transform.py \ + --model_name yolov5n \ + --model_def ../yolov5n_jit.pt \ + --input_shapes [[1,3,640,640]] \ + --pixel_format "rgb" \ + --keep_aspect_ratio \ + --mean 0,0,0 \ + --scale 0.0039216,0.0039216,0.0039216 \ + --test_input ../image/dog.jpg \ + --test_result yolov5n_top_outputs.npz \ + --output_names 1219,1234,1249 \ + --mlir yolov5n.mlir + ``` + +Example of successful operation + +![duo](/docs/duo/tpu/duo-tpu-yolo5_06.png) + +After converting to the MLIR model, a `yolov5n.mlir` file will be generated, which is the MLIR model file. A `yolov5n_in_f32.npz` file and a `yolov5n_top_outputs.npz` file will also be generated, which are the input files for subsequent model conversion. + +![duo](/docs/duo/tpu/duo-tpu-yolo5_07.png) + +### MLIR to INT8 model + +#### Generate calibration tables required for quantification + +Before converting to the INT8 model, you need to generate a calibration table. Here we use the existing 100 pictures from COCO2017 as an example to execute calibration. +``` +# run_calibration.py yolov5n.mlir \ + --dataset ../COCO2017 \ + --input_num 100 \ + -o ./yolov5n_cali_table + ``` + +Example of successful operation + +![duo](/docs/duo/tpu/duo-tpu-yolo5_08.png) + +After the operation is completed, the `yolov5n_cali_table` file will be generated, which is used for subsequent compilation of the INT8 model. + +![duo](/docs/duo/tpu/duo-tpu-yolo5_09.png) + +#### MLIR quantized into INT8 asymmetric cvimodel + +The command to convert MLIR model to INT8 model is as follows +``` +# model_deploy.py \ + --mlir yolov5n.mlir \ + --quantize INT8 \ + --calibration_table ./yolov5n_cali_table \ + --chip cv180x \ + --test_input ../image/dog.jpg \ + --test_reference yolov5n_top_outputs.npz \ + --compare_all \ + --tolerance 0.96,0.72 \ + --fuse_preprocess \ + --debug \ + --model yolov5n_int8_fuse.cvimodel + ``` + +:::tip +If the development board you are using is not Duo, please replace the fifth line `-- chip cv180x` in the above command with the corresponding chip model. +When using Duo 256M/Duo S , it should be changed to ` -- chip cv181x`. +::: + +Example of successful operation + +![duo](/docs/duo/tpu/duo-tpu-yolo5_10.png) + +After compilation is completed, the `yolov5n_int8_fuse.cvimodel` file will be generated. + +![duo](/docs/duo/tpu/duo-tpu-yolo5_11.png) + +## 5. Validate on Development Board Duo + +### Connecting the Duo development board + +Complete the connection between the Duo development board and the computer according to the previous tutorial, and use tools such as `mobaxterm` or `Xshell` to open a terminal to operate the Duo development board. + +### Get tpu-sdk + +Switch to the `/workspace` directory in the Docker terminal +``` +cd /workspace +``` + +Download tpu sdk, if you are using Duo, execute +``` +git clone https://github.com/milkv-duo/tpu-sdk-cv180x.git +mv ./tpu-sdk-cv180x ./tpu-sdk +``` + +Else,if you are using Duo 256M/Duo S , execute +``` +git clone https://github.com/milkv-duo/tpu-sdk-sg200x.git +mv ./tpu-sdk-sg200x ./tpu-sdk +``` + +### Copy tpu-sdk and model files to Duo + +In the terminal of the Duo board, create a new directory `/mnt/tpu/` +``` +# mkdir -p /mnt/tpu && cd /mnt/tpu +``` + +In the Docker terminal, copy `tpu-sdk` and model files to the Duo +``` +# scp -r /workspace/tpu-sdk root@192.168.42.1:/mnt/tpu/ +# scp /workspace/yolov5n_torch/work/yolov5n_int8_fuse.cvimodel root@192.168.42.1:/mnt/tpu/tpu-sdk/ +``` + +### Set environment variables + +In the terminal of the Duo board, set the environment variables +``` +# cd /mnt/tpu/tpu-sdk +# source ./envs_tpu_sdk.sh +``` + +### Perform Object Detection + +On the Duo board, perform object detection on the image + +![duo](/docs/duo/tpu/duo-tpu-dog.jpg) + +In the terminal of the Duo board, use the `yolov5n_int8_fuse.cvimodel` model for object detection +``` +# ./samples/samples_extra/bin/cvi_sample_detector_yolo_v5_fused_preprocess \ + ./yolov5n_int8_fuse.cvimodel \ + ./samples/samples_extra/data/dog.jpg \ + yolov5n_out.jpg + ``` + +Example of successful detection result + +![duo](/docs/duo/tpu/duo-tpu-yolo5_12.png) + +After successful operation, the detection result file `yolov5n_out.jpg` will be generated, which can be pulled to the PC through the scp command in the Windows terminal. +``` +scp root@192.168.42.1:/mnt/tpu/tpu-sdk/yolov5n_out.jpg . +``` + +![duo](/docs/duo/tpu/duo-tpu-yolo5_13.png) + +View test result files on a Windows PC + +![duo](/docs/duo/tpu/duo-tpu-yolo5_14.jpg) diff --git a/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/wiringx.md b/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/wiringx.md new file mode 100644 index 00000000..b5f573b0 --- /dev/null +++ b/i18n/ja/docusaurus-plugin-content-docs/current/duo/application-development/wiringx.md @@ -0,0 +1,902 @@ +--- +sidebar_label: 'wiringX' +sidebar_position: 10 +--- + +# Introduction + +wiringX is a library that allows developers to control the GPIO of various platforms with generic and uniform functions. By using wiringX, the same code will run on all platforms supported by wiringX, natively. + +This article will be divided into the following four parts to introduce how to develop applications on Duo using wiringX: + +1. wiringX APIs +2. Basic usage code demonstration +3. Configuration of the application compilation environment based on wiringX +4. Introduction to some demos and projects implemented using wiringX + +If you are already familiar with the usage of wiringX, you can directly refer to our sample code: [duo-examples](https://github.com/milkv-duo/duo-examples) + +Please note that many pin functions of the Duo series are multiplexed. When using `wiringX` to control the functions of each pin, it is important to confirm the current state of the pin to ensure it matches the desired functionality. If it doesn't, you can use the `duo-pinmux` command to switch it to the desired function. + +Please refer to the detailed usage instructions for more information:[pinmux](https://milkv.io/docs/duo/application-development/pinmux). + +### Duo/Duo256M wiringX numbers + +The wiringX pin numbers of Duo and Duo256M are consistent with the pin name numbers. However, the blue LED control pin is not available on the 40-pin physical pinout, and its wiringX pin number is `25`. + + + +
+ +| wiringX | PIN NAME | Pin# | Pin# | PIN NAME | wiringX | +| ------- | -------- | :-----------------------------: | :------------------------------: | -------- | ------- | +| 0 | GP0 |
1
|
40
| VBUS | | +| 1 | GP1 |
2
|
39
| VSYS | | +| | GND |
3
|
38
| GND | | +| 2 | GP2 |
4
|
37
| 3V3_EN | | +| 3 | GP3 |
5
|
36
| 3V3(OUT) | | +| 4 | GP4 |
6
|
35
| | | +| 5 | GP5 |
7
|
34
| | | +| | GND |
8
|
33
| GND | | +| 6 | GP6 |
9
|
32
| GP27 | 27 | +| 7 | GP7 |
10
|
31
| GP26 | 26 | +| 8 | GP8 |
11
|
30
| RUN | | +| 9 | GP9 |
12
|
29
| GP22 | 22 | +| | GND |
13
|
28
| GND | | +| 10 | GP10 |
14
|
27
| GP21 | 21 | +| 11 | GP11 |
15
|
26
| GP20 | 20 | +| 12 | GP12 |
16
|
25
| GP19 | 19 | +| 13 | GP13 |
17
|
24
| GP18 | 18 | +| | GND |
18
|
23
| GND | | +| 14 | GP14 |
19
|
22
| GP17 | 17 | +| 15 | GP15 |
20
|
21
| GP16 | 16 | +| | |   | | | | +| 25 | GP25 |
LED
| | | | + +
+ +### DuoS wiringX numbers + +The wiringX pin numbers of DuoS are consistent with the physical pin numbers. The blue LED control pin is not on the 40PIN physical pins, and its wiringX number is `0`. + + + +#### Header J3 + +GPIO on `Header J3` use 3.3V logic levels. + +
+ +| wiringX | PIN NAME | PIN# | PIN# | PIN NAME | wiringX | +|:-------:|:---------|:--------------------------------:|:-------------------------------:|:---------|:-------:| +| | 3V3 |
1
|
2
| VSYS(5V) | | +| 3 | B20 |
3
|
4
| VSYS(5V) | | +| 5 | B21 |
5
|
6
| GND | | +| 7 | B18 |
7
|
8
| A16 | 8 | +| | GND\* |
9
|
10
| A17 | 10 | +| 11 | B11 |
11
|
12
| B19 | 12 | +| 13 | B12 |
13
|
14
| GND | | +| 15 | B22 |
15
|
16
| A20 | 16 | +| | 3V3 |
17
|
18
| A19 | 18 | +| 19 | B13 |
19
|
20
| GND | | +| 21 | B14 |
21
|
22
| A18 | 22 | +| 23 | B15 |
23
|
24
| B16 | 24 | +| | GND |
25
|
26
| A28 | 26 | + +
+ +*GND\*: Pin 9 is a low-level GPIO in the V1.1 version of the hardware, and is GND in the V1.2 version and later.* + +#### Header J4 + +GPIO on `Header J4` use 1.8V logic levels. + +Most of the pins on this header have dedicated functions, such as MIPI DSI signals, Touch Screen signals, and audio signals. If there is no special requirement, it is not recommended to use the pins on this header as GPIO. + +
+ +| wiringX | PIN NAME | PIN# | PIN# | PIN NAME | wiringX | +|:-------:|----------|:-------------------------------:|:--------------------------------:|:------------|:-------:| +| | VSYS(5V) |
52
|
51
| AUDIO_OUT_R | | +| 50 | B1 |
50
|
49
| AUDIO_OUT_L | | +| 48 | B2 |
48
|
47
| AUDIO_IN_R | | +| 46 | B3 |
46
|
45
| AUDIO_IN_L | | +| 44 | E2 |
44
|
43
| 3V3 | | +| 42 | E1 |
42
|
41
| C18 | 41 | +| 40 | E0 |
40
|
39
| C19 | 39 | +| | GND |
38
|
37
| GND | | +| 36 | C20 |
36
|
35
| C16 | 35 | +| 34 | C21 |
34
|
33
| C17 | 33 | +| | GND |
32
|
31
| GND | | +| 30 | C14 |
30
|
29
| C12 | 29 | +| 28 | C15 |
28
|
27
| C13 | 27 | + +
+ +## 1. Code example + +### GPIO Usage Example + +Here is an example of working with GPIO. It will toggle pin 20 on Duo every 1 second, pulling it high and then low. The physical pin number for pin 20 is `15` in the WiringX numbering system. + +```c +#include +#include + +#include + +int main() { + int DUO_GPIO = 15; + + // Duo: milkv_duo + // Duo256M: milkv_duo256m + // DuoS: milkv_duos + if(wiringXSetup("milkv_duo", NULL) == -1) { + wiringXGC(); + return -1; + } + + if(wiringXValidGPIO(DUO_GPIO) != 0) { + printf("Invalid GPIO %d\n", DUO_GPIO); + } + + pinMode(DUO_GPIO, PINMODE_OUTPUT); + + while(1) { + printf("Duo GPIO (wiringX) %d: High\n", DUO_GPIO); + digitalWrite(DUO_GPIO, HIGH); + sleep(1); + printf("Duo GPIO (wiringX) %d: Low\n", DUO_GPIO); + digitalWrite(DUO_GPIO, LOW); + sleep(1); + } + + return 0; +} +``` +After compiling and running it on Duo, you can use a multimeter or an oscilloscope to measure the state of pin 20 and verify if it matches the expected behavior. + +You can also use the onboard LED pin to verify the behavior. By observing the on/off state of the LED, you can intuitively determine if the program is executing correctly. The WiringX pin number for the LED is `25`. Simply modify the code mentioned above by replacing pin `15` with pin `25`. However, please note that the default firmware has a script to control LED blinking on startup, which needs to be disabled. You can refer to the example explanation for [blink](#blink) below for instructions on how to disable it. + +### I2C Usage Example + +Here is an example of I2C communication: + +```c +#include +#include +#include + +#include + +#define I2C_DEV "/dev/i2c-1" + +#define I2C_ADDR 0x04 + +int main(void) +{ + int fd_i2c; + int data = 0; + + // Duo: milkv_duo + // Duo256M: milkv_duo256m + // DuoS: milkv_duos + if(wiringXSetup("milkv_duo", NULL) == -1) { + wiringXGC(); + return -1; + } + + if ((fd_i2c = wiringXI2CSetup(I2C_DEV, I2C_ADDR)) <0) { + printf("I2C Setup failed: %d\n", fd_i2c); + wiringXGC(); + return -1; + } + + // TODO +} +``` + +### SPI Usage Example + +Here is an example of SPI communication: + +```c +#include +#include +#include + +#include + +int main(void) +{ + int fd_spi; + + // Duo: milkv_duo + // Duo256M: milkv_duo256m + // DuoS: milkv_duos + if(wiringXSetup("milkv_duo", NULL) == -1) { + wiringXGC(); + return -1; + } + + if ((fd_spi = wiringXSPISetup(0, 500000)) <0) { + printf("SPI Setup failed: %d\n", fd_spi); + wiringXGC(); + return -1; + } + + // TODO +} +``` + +### UART Usage Example + +Here is an example of UART communication using UART4 on pins 4/5: + +```c +#include +#include + +#include + +int main() { + struct wiringXSerial_t wiringXSerial = {115200, 8, 'n', 1, 'n'}; + char buf[1024]; + int str_len = 0; + int i; + int fd; + + // Duo: milkv_duo + // Duo256M: milkv_duo256m + // DuoS: milkv_duos + if(wiringXSetup("milkv_duo", NULL) == -1) { + wiringXGC(); + return -1; + } + + if ((fd = wiringXSerialOpen("/dev/ttyS4", wiringXSerial)) < 0) { + printf("Open serial device failed: %d\n", fd); + wiringXGC(); + return -1; + } + + wiringXSerialPuts(fd, "Duo Serial Test\n"); + + while(1) + { + str_len = wiringXSerialDataAvail(fd); + if (str_len > 0) { + i = 0; + while (str_len--) + { + buf[i++] = wiringXSerialGetChar(fd); + } + printf("Duo UART receive: %s\n", buf); + } + } + + wiringXSerialClose(fd); + + return 0; +} +``` +Testing Method: + +The RX of the USB to serial converter cable is connected to pin 4 (UART4_TX) of Duo, the TX of the serial cable is connected to pin 5 (UART4_RX) of Duo, and the GND of the serial cable is connected to the GND of Duo. On the computer, configure the COM port and parameters using a serial debugging tool. + +The compiled executable of the above program is named `uart_test`. After uploading it to Duo via SSH and running it, you should be able to see the string `Duo Serial Test` received in the serial tool on your computer. If you send the string `Hello World` from the serial tool, you will also see the corresponding string received on the Duo's terminal. This confirms that the serial communication is functioning correctly. + +![duo](/docs/duo/duo-wiringx-uart-test.png) + + +## 2. Development Environment Setup + +### Build environment on Ubuntu20.04 + +You can also use Ubuntu installed in a virtual machine, Ubuntu installed via WSL on Windows, or Ubuntu-based systems using Docker. + +- Install the tools that compile dependencies + ``` + sudo apt-get install wget git make + ``` +- Get example source code + ``` + git clone https://github.com/milkv-duo/duo-examples.git + ``` + +- Prepare compilation environment + ``` + cd duo-examples + source envsetup.sh + ``` + The first time you source it, the required SDK package will be automatically downloaded, which is approximately 180MB in size. Once downloaded, it will be automatically extracted to the `duo-examples` directory with the name `duo-sdk`. When source it next time, if the directory already exists, it will not be downloaded again. + +- Compile testing + + Take hello-world as an example, enter the hello-world directory and execute make: + ``` + cd hello-world + make + ``` + After the compilation is successful, send the generated `helloworld` executable program to the Duo device through the network port or the RNDIS network. For example, the RNDIS method supported by the [default firmware](https://github.com/milkv-duo/duo-buildroot-sdk/releases), Duo’s IP is 192.168.42.1, the user name is `root`, and the password is `milkv`. + ``` + scp helloworld root@192.168.42.1:/root/ + ``` + After sending successfully, run `./helloworld` in the terminal logged in via ssh or serial port, and it will print `Hello, World!` + ``` + [root@milkv]~# ./helloworld + Hello, World! + ``` + **At this point, our compilation and development environment is ready for use.** + +### How to create your own project + +You can simply copy existing examples and make necessary modifications. For instance, if you need to manipulate a GPIO, you can refer to the `blink` example. LED blinking is achieved by controlling the GPIO's voltage level. The current SDK utilizes the WiringX library for GPIO operations, which has been adapted specifically for Duo. You can find the platform initialization and GPIO control methods in the `blink.c` code for reference. + +- Create your own project directory called `my-project`. +- Copy the `blink.c` and `Makefile` files from the `blink` example to the `my-project` directory. +- Rename `blink.c` to your desired name, such as `gpio_test.c`. +- Modify the `Makefile` by changing `TARGET=blink` to `TARGET=gpio_test`. +- Modify `gpio_test.c` to implement your own code logic. +- Execute the `make` command to compile. +- Send the generated `gpio_test` executable program to Duo for execution. + +Note: + +- Creating a new project directory is not mandatory to be placed within the `duo-examples` directory. You can choose any location based on your preference. Before executing the `make` compilation command, it is sufficient to load the compilation environment from the `duo-examples` directory (source /PATH/TO/duo-examples/envsetup.sh). +- Within the terminal where the compilation environment (envsetup.sh) is loaded, avoid compiling Makefile projects for other platforms such as ARM or X86. If you need to compile projects for other platforms, open a new terminal. + +## 3. Explanation of each example + +### hello-world + +Source code: [https://github.com/milkv-duo/duo-examples/tree/main/hello-world](https://github.com/milkv-duo/duo-examples/tree/main/hello-world) + +A simple example that doesn't interact with Duo peripherals, only prints the output "Hello, World!" to verify the development environment. + +### blink + +Source code: [https://github.com/milkv-duo/duo-examples/tree/main/blink](https://github.com/milkv-duo/duo-examples/tree/main/blink) + +This example demonstrates how to control an LED connected to a GPIO pin. It uses the WiringX library to toggle the GPIO pin's voltage level, resulting in the LED blinking. + +The `blink.c` code includes platform initialization and GPIO manipulation methods from the WiringX library. + +To test the `blink` example, which involves LED blinking, you need to disable the script responsible for the automatic LED blinking on the default firmware of Duo. In the Duo terminal, execute the following command: +``` +mv /mnt/system/blink.sh /mnt/system/blink.sh_backup && sync +``` +This command renames the LED blinking script. After restarting Duo, the LED will no longer blink. + +Once you have finished testing the `blink` program implemented in C, if you want to restore the LED blinking script, you can rename it back using the following command and then restart Duo: +``` +mv /mnt/system/blink.sh_backup /mnt/system/blink.sh && sync +``` + +### ADC + +#### adcRead reads the voltage value + +Source code: [https://github.com/milkv-duo/duo-examples/tree/main/adc](https://github.com/milkv-duo/duo-examples/tree/main/adc) + +Reading the measured value of the ADC is divided into two versions: shell script and C language. After starting, select the ADC to be read according to the output prompts. After selection, the voltage value measured by the ADC will be printed in a loop. + +### I2C + +I2C source code directory: [https://github.com/milkv-duo/duo-examples/tree/main/i2c](https://github.com/milkv-duo/duo-examples/tree/main/i2c) + +#### BMP280 Temperature Barometer Sensor + +Source code: [https://github.com/milkv-duo/duo-examples/tree/main/i2c/bmp280_i2c](https://github.com/milkv-duo/duo-examples/tree/main/i2c/bmp280_i2c) + +This example code shows how to interface the Milk-V Duo with the popular BMP280 temperature and air pressure sensor manufactured by Bosch. + +#### VL53l0X Time of Flight distance sensor + +Source code: [https://github.com/milkv-duo/duo-examples/tree/main/i2c/vl53l0x_i2c](https://github.com/milkv-duo/duo-examples/tree/main/i2c/vl53l0x_i2c) + +Use the TOF distance sensor VL53L0X module via the I2C interface to read the measured distance. + +#### SSD1306 OLEDs + +Source code: [https://github.com/milkv-duo/duo-examples/tree/main/i2c/ssd1306_i2c](https://github.com/milkv-duo/duo-examples/tree/main/i2c/ssd1306_i2c) + +Display strings on SSD1306 OLED display via I2C interface. + +#### ADXL345 Three-axis acceleration sensor + +Source code: [https://github.com/milkv-duo/duo-examples/blob/main/i2c/adxl345_i2c](https://github.com/milkv-duo/duo-examples/blob/main/i2c/adxl345_i2c) + +Read the acceleration data obtained by ADXL345 through the I2C interface, read it every 1 second, and print the result on the screen. + +#### LCM1602 Display Moudle + +Source code: [https://github.com/milkv-duo/duo-examples/blob/main/i2c/lcm1602_i2c](https://github.com/milkv-duo/duo-examples/blob/main/i2c/lcm1602_i2c) + +Display strings on the 1602 LCD screen via the I2C interface. + +#### LCM2004 Display Moudle + +Source code: [https://github.com/milkv-duo/duo-examples/blob/main/i2c/lcm2004_i2c](https://github.com/milkv-duo/duo-examples/blob/main/i2c/lcm2004_i2c) + +Display string on 2004 LCD screen via I2C interface. + +#### TCS34725 Color sensor + +Source code: [https://github.com/milkv-duo/duo-examples/blob/main/i2c/tcs34725_i2c](https://github.com/milkv-duo/duo-examples/blob/main/i2c/tcs34725_i2c) + +Read the TCS34725 color sensor through the I2C interface and output the obtained data. + +### SPI + +SPI source code directory: [https://github.com/milkv-duo/duo-examples/tree/main/spi](https://github.com/milkv-duo/duo-examples/tree/main/spi) + +#### MAX6675 Temperature Sensor + +Source code: [https://github.com/milkv-duo/duo-examples/tree/main/spi/max6675_spi](https://github.com/milkv-duo/duo-examples/tree/main/spi/max6675_spi) + +Connect the K-type thermocouple measurement module MAX6675 through the SPI interface to measure the current temperature on the sensor. + +#### RC522 Radio Frequency Identification Module + +Source code: [https://github.com/milkv-duo/duo-examples/tree/main/spi/rc522_spi](https://github.com/milkv-duo/duo-examples/tree/main/spi/rc522_spi) + +Connect the RC522 RFID read-write module via the SPI interface to read the card ID and type and output them to the screen. + +## 4. Compile wiringX + +Duo firmware already contains the compiled wiringX library (/usr/lib/libwiringx.so) and can be used directly. If you need to compile the source code of wiringX to generate the library, you can compile it as follows. + +We compile it on an Ubuntu host or other Linux distribution. + +*Note: Part of Duo's wiringX code has not yet been integrated into the upstream wiringX repo. In actual use, please give priority to using the wiringX library in Duo firmware. + +### Download wiringX source code + +``` +git clone https://github.com/wiringX/wiringX.git +``` + +### Modify CMakeLists.txt + +Enter the code directory: +``` +cd wiringX +``` + +The wiringX project is compiled using cmake. You need to modify CMakeLists.txt through `vi` or other editors to add the cross-compilation toolchain and compilation parameters: + +```diff {9-12} +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 8909393..6918181 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -17,6 +17,11 @@ set(CMAKE_EXE_LINKER_FLAGS " -Wl,-rpath=/usr/local/lib/,-rpath=/usr/lib/,-rpath= + set(CMAKE_SHARED_LINKER_FLAGS " -Wl,-rpath=/usr/local/lib/,-rpath=/usr/lib/,-rpath=/lib/") + set(CMAKE_MODULE_LINKER_FLAGS " -Wl,-rpath=/usr/local/lib/,-rpath=/usr/lib/,-rpath=/lib/") + ++set(CMAKE_C_COMPILER "${CMAKE_CURRENT_SOURCE_DIR}/host-tools/gcc/riscv64-linux-musl-x86_64/bin/riscv64-unknown-linux-musl-gcc") ++set(CMAKE_CXX_COMPILER "${CMAKE_CURRENT_SOURCE_DIR}/host-tools/gcc/riscv64-linux-musl-x86_64/bin/riscv64-unknown-linux-musl-g++") ++set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mcpu=c906fdv -march=rv64imafdcv0p7xthead -mcmodel=medany -mabi=lp64d") ++set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64") ++ + # Start uninstaller generator + function(WRITE_UNINSTALL_TARGET_SCRIPT) + # Create uninstall target template file, if it doesn't exist... +``` + +There are two variables that need to be noted and configured according to your own file path: +- **CMAKE_C_COMPILER**: The path to gcc in the cross-compilation toolchain +- **CMAKE_CXX_COMPILER**: path to g++ in the cross-compilation toolchain + +Download link for cross-compilation toolchain: [host-tools.tar.gz](https://sophon-file.sophon.cn/sophon-prod-s3/drive/23/03/07/16/host-tools.tar.gz). You can download and unzip it through the wget command: +```bash +wget https://sophon-file.sophon.cn/sophon-prod-s3/drive/23/03/07/16/host-tools.tar.gz +tar -xf host-tools.tar.gz +``` + +If you have ever compiled [duo-buildroot-sdk](https://github.com/milkv-duo/duo-buildroot-sdk), the `host-tools` directory in its root directory is the directory of the cross toolchain. There is no need to re-download, you can directly modify the `CMAKE_CURRENT_SOURCE_DIR` field to specify the directory. Or create a soft link pointing to the directory. + +### Modify code + +Since the time-related definitions in the cross toolchain are slightly different from those in wiringX, add the following two lines of modification: + +```diff {9,10} +diff --git a/src/wiringx.c b/src/wiringx.c +index 034674a..4171a75 100644 +--- a/src/wiringx.c ++++ b/src/wiringx.c +@@ -113,6 +113,9 @@ static struct spi_t spi[2] = { + } while(0) + #endif + ++typedef time_t __time_t; ++typedef suseconds_t __suseconds_t; ++ + /* Both the delayMicroseconds and the delayMicrosecondsHard + are taken from wiringPi */ + static void delayMicrosecondsHard(unsigned int howLong) { +``` + +### Compile + +Compiling in cmake will create some intermediate directories and files, so we create a new build directory and enter this directory to complete the compilation: + +```bash +mkdir build +cd build +cmake .. +make +``` + +After compilation is completed, the `libwiringx.so` generated in the current `build` directory is the wiringX library we need. + +### Points to Consider + +If you encounter compilation errors, you can try to change the version of `cmake`. For example, you can manually install the latest `3.27.6` version: + +```bash +wget https://github.com/Kitware/CMake/releases/download/v3.27.6/cmake-3.27.6-linux-x86_64.sh +chmod +x cmake-3.27.6-linux-x86_64.sh +sudo sh cmake-3.27.6-linux-x86_64.sh --skip-license --prefix=/usr/local/ +``` +The manually installed `cmake` is in `/usr/local/bin`. At this time, use the `cmake --version` command to check its version number, which should be: + +``` +cmake version 3.27.6 +``` + +## 5. wiringX APIs + +### General + +
+ +int wiringXSetup(char *name, ...) + + To initialize the WiringX library for configuring and managing GPIO pins: + - Duo + ``` + wiringXSetup("milkv_duo", NULL) + ``` + - Duo256M + ``` + wiringXSetup("milkv_duo256m", NULL) + ``` + - DuoS + ``` + wiringXSetup("milkv_duos", NULL) + ``` + +
+ + +
+ +int wiringXValidGPIO(int pin) + + To check if a GPIO pin is available. + +
+ + +
+ +void delayMicroseconds(unsigned int ms) + + Delay for how many milliseconds. + +
+ + +
+ +int wiringXGC(void) + + To release resources. + +
+ + +
+ +char *wiringXPlatform(void) + + Return platform information. + +
+ + +### GPIO + +
+ +int pinMode(int pin, pinmode_t mode) + + Set the working mode for the specified pin, where pin is the pin number, and mode can be: + - PINMODE_INPUT input mode + - PINMODE_OUTPUT output mode + - PINMODE_INTERRUPT interrupt mode + +
+ + +
+ +int digitalRead(int pin) + + Read the input value of the specified pin, and the return value is HIGH or LOW. + +
+ + +
+ +int digitalWrite(int pin, enum digital_value_t value) + + Set the output value for the specified pin, where value can be: + - HIGH high level + - LOW low level + +
+ + +
+ +int waitForInterrupt(int pin, int ms) + + Wait for an interrupt to occur on pin, with a timeout of ms milliseconds. + *This function has been deprecated. It is recommended to use wiringXISR* + +
+ + +
+ +int wiringXISR(int pin, enum isr_mode_t mode) + +Configure pin as an interrupt mode, with several modes for mode: +- ISR_MODE_RISING +- ISR_MODE_FALLING +- ISR_MODE_BOTH + +
+ + +### I2C + +
+ +int wiringXI2CSetup(const char *dev, int addr) + + Configure the I2C node and I2C address. + +
+ + +
+ +int wiringXI2CRead(int fd) + + Read 1 byte of data. + +
+ + +
+ +int wiringXI2CReadReg8(int fd, int reg) + + Read 1 byte of data from the reg register. + +
+ + +
+ +int wiringXI2CReadReg16(int fd, int reg) + + Read 2 bytes of data from the reg register. + +
+ + +
+ +int wiringXI2CWrite(int fd, int reg) + + Write the address of the register reg. + +
+ + +
+ +int wiringXI2CWriteReg8(int fd, int reg, int value8) + + Write the 8-bit data value8 to the register reg. + +
+ + +
+ +int wiringXI2CWriteReg16(int fd, int reg, int value16) + + Write the 16-bit data value16 to the register reg. + +
+ +### SPI + +
+ +int wiringXSPISetup(int channel, int speed) + + Configure the channel (0 on Duo) and speed (default to 500000) of the SPI device. + +
+ +
+ +int wiringXSPIDataRW(int channel, unsigned char *data, int len) + + The SPI bus writes data on the rising edge and reads data on the falling edge. Therefore, this function performs both read and write operations simultaneously, resulting in the read data overwriting the written data. Please be cautious when using it. + +
+ +
+ +int wiringXSPIGetFd(int channel) + + Get the file descriptor of the SPI device, with the channel defaulting to 0 on Duo. + +
+ +### UART + +
+ +int wiringXSerialOpen(const char *dev, struct wiringXSerial_t serial) + + Open the serial port device, where `dev` is the device descriptor and `serial` is a structure that needs to be filled with serial port-related parameters. For more details, please refer to the [UART Usage Example](#UART-Usage-Example). + + ```c + typedef struct wiringXSerial_t { + unsigned int baud; // baudrate + unsigned int databits; // 7/8 + unsigned int parity; // o/e/n + unsigned int stopbits; // 1/2 + unsigned int flowcontrol; // x/n + } wiringXSerial_t; + ``` + +
+ +
+ +void wiringXSerialClose(int fd) + + Close the serial port. + +
+ +
+ +void wiringXSerialFlush(int fd) + + Flush the buffer. + +
+ +
+ +void wiringXSerialPutChar(int fd, unsigned char c) + + Output a character. + +
+ +
+ +void wiringXSerialPuts(int fd, const char *s) + + Output a string. + +
+ +
+ +void wiringXSerialPrintf(int fd, const char *message, ...) + + Format output. + +
+ +
+ +int wiringXSerialDataAvail(int fd) + + Return the number of data received in the buffer. + +
+ +
+ +int wiringXSerialGetChar(int fd) + + Read a character from the serial port device. + +
+ +### PWM + +The current version of wiringX only supports Duo's PWM. Duo256M and DuoS will add PWM support later. + +- Duo PWM Pin Number + +
+ +| PWM | PIN NAME | Pin# | Pin# | PIN NAME | +|:---:|:---------|:-------------------------------:|:--------------------------------:|----------| +| | GP0 |
1
|
40
| VBUS | +| | GP1 |
2
|
39
| VSYS | +| | GND |
3
|
38
| GND | +| 10 | GP2 |
4
|
37
| 3V3_EN | +| 11 | GP3 |
5
|
36
| 3V3(OUT) | +| 5 | GP4 |
6
|
35
| | +| 6 | GP5 |
7
|
34
| | +| | GND |
8
|
33
| GND | +| 9 | GP6 |
9
|
32
| GP27 | +| 8 | GP7 |
10
|
31
| GP26 | +| 7 | GP8 |
11
|
30
| RUN | +| 4 | GP9 |
12
|
29
| GP22 | +| | GND |
13
|
28
| GND | +| | GP10 |
14
|
27
| GP21 | +| | GP11 |
15
|
26
| GP20 | +| 4 | GP12 |
16
|
25
| GP19 | +| 5 | GP13 |
17
|
24
| GP18 | +| | GND |
18
|
23
| GND | +| | GP14 |
19
|
22
| GP17 | +| | GP15 |
20
|
21
| GP16 | + +
+ +
+ +wiringXPWMSetPeriod(int pin, long period) + + Set the period of the PWM pin, pin is the PWM pin number, period is in nanoseconds. + +
+ + +
+ +int wiringXPWMSetDuty(int pin, long duty_cycle) + + Set the high level time of the PWM pin in one cycle, duty_cycle is in nanoseconds. + +
+ + +
+ +int wiringXPWMSetPolarity(int pin, int polarity) + + Set the PWM pin polarity, the polarity is 0 or 1: + - 0 normal + - 1 inversed + +
+ + +
+ +int wiringXPWMEnable(int pin, int enable) + + Enable or disable PWM pin output, enable is 0 or 1: + - 0: disable + - 1: enable + +
diff --git a/i18n/ja/docusaurus-plugin-content-docs/current/duo/camera/_category_.json b/i18n/ja/docusaurus-plugin-content-docs/current/duo/camera/_category_.json new file mode 100644 index 00000000..3c9ece4f --- /dev/null +++ b/i18n/ja/docusaurus-plugin-content-docs/current/duo/camera/_category_.json @@ -0,0 +1,9 @@ +{ + "label": "📷 Camera", + "position": 200, + "link": { + "type": "generated-index", + "slug": "/duo/camera", + "description": "Camera for Milk-V Duo" + } +} diff --git a/i18n/ja/docusaurus-plugin-content-docs/current/duo/camera/gc2083.md b/i18n/ja/docusaurus-plugin-content-docs/current/duo/camera/gc2083.md new file mode 100644 index 00000000..3f54717b --- /dev/null +++ b/i18n/ja/docusaurus-plugin-content-docs/current/duo/camera/gc2083.md @@ -0,0 +1,149 @@ +--- +sidebar_label: 'CAM-GC2083 ' +sidebar_position: 10 +--- +# CAM-GC2083 +## Introduction +CAM-GC2083 is equipped with GLAXYCORE's GC2083 CMOS Image Sensor, providing up to 2MP resolution. It is compatible with the 16P MIPI CSI interface on the Milk-V Duo board. + +## Specification +### Sensor Fectures +- Optical size: + 1/3 inch + +- Pixel size: +2.7μm×2.7μm FSI + +- Active image size: +1920× 1080 + +- Color Filter: +RGB Bayer + +- Output formats: +Raw Bayer 10bit/8bit + +- Power supply requirement: +AVDD28:2.7~2.9V(Typ.2.8V) +DVDD:Generated by the intemalregulator (Typ.1.2V) +IOVDD: 1.7~1.9V(Typ. 1.8V) + +- Power Consumption: +128mW@Full Size @30fps + +- Frame rate: +30fps@Full Size + +- PLL support + +- Frame sync support (master/slave) + +- Windowing support + +- Mirror and Flip support + +- Analog Gain: +64X(Max) + +- Sensitivity: +3.24V/lux.s + +- Dynamic range: +74dB + +- MAX SNR: +37dB + +### FPC Interface Definition + +| **Pin NO.** | **Definition** | **Pin NO.** | **Definition** | +|:-----------:|:--------------:|:-----------:|:--------------:| +| 1 | GND | 9 | MIPI0_CKP | +| 2 | MIPI0_DN0 | 10 | GND | +| 3 | MIPI0_DP0 | 11 | SENSOR_RSTN | +| 4 | GND | 12 | SENSOR_CLK | +| 5 | MIPI0_DN1 | 13 | I2C_SCL | +| 6 | MIPI0_DP1 | 14 | I2C_SDA | +| 7 | GND | 15 | / | +| 8 | MIPI0_CKN | 16 | 3V3 | + +## Hardware connection + +FFC/FPC A-Type(SAME Side) Ribbon Flexible Flat Cable + +![duo-camera](/docs/duo/duo-camera-connection_01.jpg) + +The direction of the metal contact surface of the Ribbon Cable + +![duo-camera](/docs/duo/duo-camera-connection_02.jpg) + +## Software testing + +This test is only used to verify if the camera is functioning properly. It runs a test program on Duo to stream video, and then using VLC media player on a PC to receive the video stream. + +First, make sure you can SSH into the Duo device using USB networking (RNDIS). The default firmware SSH username and password are root/milkv. + +The latest firmware has integrated test program, please use [V1.1.0](https://github.com/milkv-duo/duo-buildroot-sdk/releases/tag/Duo-V1.1.0) or [Latest Firmware](https://github.com/milkv-duo/duo-buildroot-sdk/releases). + +The Test program added face detection demo while pushing the stream. + +Log in to the Duo terminal: +```bash +ssh root@192.168.42.1 +``` + +Execute the test program to start streaming: +```bash +camera-test.sh +``` + +In normal circumstances, the terminal will display the following log at the end: +``` {8} +Bind VI with VPSS Grp(0), Chn(0) +Attach VBPool(0) to VPSS Grp(0) Chn(0) +Attach VBPool(1) to VPSS Grp(0) Chn(1) +Initialize VENC +venc codec: h264 +venc frame size: 1280x720 +Initialize RTSP +rtsp://127.0.1.1/h264 +prio:0 +anchor:-8,-8,8,8 +anchor:-16,-16,16,16 +bbox:bbox_8_Conv_dequant +landmark:kps_8_Conv_dequant +score:score_8_Sigmoid_dequant +anchor:-32,-32,32,32 +anchor:-64,-64,64,64 +bbox:bbox_16_Conv_dequant +landmark:kps_16_Conv_dequant +score:score_16_Sigmoid_dequant +anchor:-128,-128,128,128 +anchor:-256,-256,256,256 +bbox:bbox_32_Conv_dequant +landmark:kps_32_Conv_dequant +score:score_32_Sigmoid_dequant +Enter TDL thread +Enter encoder thread +0 R:1165 B:3087 CT:2688 +1 R:1464 B:2327 CT:3937 +2 R:1974 B:1613 CT:7225 +Golden 1464 1024 2327 +``` + +Note the link starting with 'rtsp:', replace the IP with the IP address of Duo, and that will be the streaming address to use in VLC media player. + +On your PC, open VLC media player. Go to the 'Media' menu and select 'Open Network Stream' In the 'Network' tab, enter the following URL in the 'Please enter a network URL' field. + +``` +rtsp://192.168.42.1/h264 +``` + +Click the `Show more options` in the lower left corner, and you can set the `Caching` option to adjust the delay. The default is 1000 milliseconds, which is 1 second. When the network environment is good, such as in a LAN, you can turn it down to reduce latency. You can set it to 100 to 300. If the network environment is poor or the screen freezes, you can try to increase it. + +Click 'Play' and you will be able to see the streaming video from the camera. + +![duo-camera](/docs/duo/duo-camera-vlc-stream.jpg) + +## Downloads +- [Hardware schematics](https://github.com/milkv-duo/Accessories/blob/master/CAM-GC2083/Hardware_schematics/DUO_CAM_GC2083.pdf) diff --git a/i18n/ja/docusaurus-plugin-content-docs/current/duo/camera/tuning.md b/i18n/ja/docusaurus-plugin-content-docs/current/duo/camera/tuning.md new file mode 100644 index 00000000..2338c7c2 --- /dev/null +++ b/i18n/ja/docusaurus-plugin-content-docs/current/duo/camera/tuning.md @@ -0,0 +1,16 @@ +--- +sidebar_label: 'Tuning Guide' +sidebar_position: 50 +--- + +## Introduction + +ISP Development Reference: [html](https://doc.sophgo.com/cvitek-develop-docs/master/docs_latest_release/CV180x_CV181x/en/01.software/ISP/ISP_Development_Reference/build/html/index.html) | [pdf](https://doc.sophgo.com/cvitek-develop-docs/master/docs_latest_release/CV180x_CV181x/en/01.software/ISP/ISP_Development_Reference/build/ISPDevelopmentReference_en.pdf) + +ISP Tuning Guide: [html](https://doc.sophgo.com/cvitek-develop-docs/master/docs_latest_release/CV180x_CV181x/en/01.software/ISP/ISP_Tuning_Guide/build/html/index.html) | [pdf](https://doc.sophgo.com/cvitek-develop-docs/master/docs_latest_release/CV180x_CV181x/en/01.software/ISP/ISP_Tuning_Guide/build/ISPTuningGuide_en.pdf) + +PQ Tools User Guide: [html](https://doc.sophgo.com/cvitek-develop-docs/master/docs_latest_release/CV180x_CV181x/en/01.software/ISP/PQ_Tools_User_Guide/build/html/3_Interface_and_Function_Description.html) | [pdf](https://doc.sophgo.com/cvitek-develop-docs/master/docs_latest_release/CV180x_CV181x/en/01.software/ISP/PQ_Tools_User_Guide/build/PQToolsUserGuide_en.pdf) + +## Downloads +- [PQ Tools](https://github.com/milkv-duo/accessories/blob/master/CAM-GC2083/Software/CviPQtool_20230306.zip?raw=true) +- [isp_tool_daemon.tar.gz](https://github.com/milkv-duo/accessories/blob/master/CAM-GC2083/Software/isp_tool_daemon.tar.gz?raw=true) diff --git a/i18n/ja/docusaurus-plugin-content-docs/current/duo/getting-started/8051core.md b/i18n/ja/docusaurus-plugin-content-docs/current/duo/getting-started/8051core.md new file mode 100644 index 00000000..a9c82997 --- /dev/null +++ b/i18n/ja/docusaurus-plugin-content-docs/current/duo/getting-started/8051core.md @@ -0,0 +1,314 @@ +--- +sidebar_label: '8051 core' +sidebar_position: 55 +--- + +# 8051 Core + +## Introduction + +The CPU used by Duo contains an 8051 core. The 8051 subsystem is located in a module that is independently powered by the RTC. The subsystem is configured with an 8051, an I2C/UART/SPI NOR/SD controller, a Timer/WDT, interrupt management, and a Mailbox IP. The system software can use the 8051 to manage wake-up conditions and wake up the system while it is in sleep mode, and communicate with external devices through peripheral controllers. + +## Quick Start + +### 8051 core compilation guide + +Source Code: [github](https://github.com/milkv-duo/duo-8051.git). + +run: +```bash +git clone https://github.com/milkv-duo/duo-8051.git +cd duo-8051/sdcc/mars/project/base_project +make clean && make +``` +After successful compilation, the compiled firmware `mars_mcu_fw.bin` can be found in `sdcc/mars/project/base_project/output`. + + +### How to load firmware + +First download the firmware and tools and unzip the zip package:[firmware.zip](https://github.com/milkv-duo/duo-8051/releases/download/Duo-8051-V1.0/firmware.zip). + +Ⅰ. Load firmware in 8051-SRAM: + +1. Copy `8051_up`, `mars_mcu_fw.bin`, and `blink.sh` into `/mnt/data`, and grant execution and read permissions. + +2. Execute `8051_up` to automatically update the firmware and start the 8051 core. + +3. Execute `blink.sh`. This script will send data to the 8051 core and cause the blue LED to flash (please confirm that /mnt/system/blink.sh has been removed before executing this script). + +:::tip +The 8051 kernel firmware cannot exceed 8KB when running this method. Exceeding the limit may cause it to not run. +::: + +Ⅱ.Load firmware in DDR memory: + 1. Change the memory allocation in the SDK and modify `build/boards/[chip model]/[board config]/memmap.py` . + + Add the following content in MemoryMap: +```python +# ============== +# 8051 +# ============== +CHIP8051_SIZE = 512 * SIZE_1K +CHIP8051_ADDR = DRAM_BASE + DRAM_SIZE - CHIP8051_SIZE +``` + + Modify the following content: +```python +# ============== +# C906L FreeRTOS +# ============== +FREERTOS_SIZE = 768 * SIZE_1K +# FreeRTOS is after 8051 +FREERTOS_ADDR = CHIP8051_ADDR - FREERTOS_SIZE +FSBL_C906L_START_ADDR = FREERTOS_ADDR +``` + + + +2. Recompile the firmware and burn it to the Duo board. + +3. Copy `8051_up`, `mars_mcu_fw.bin`, `blink.sh`, and `8051_boot_cfg.ini` into `/mnt/data`, and grant execution and read permissions. + +4. Execute `8051_up` to automatically update the firmware and start the 8051 core. + +5. Execute `blink.sh`. This script will send information to the 8051 core and cause the blue LED to flash (please confirm that /mnt/system/blink.sh has been removed before executing this script). + +:::tip +If you want to customize the DDR memory size of 8051 to store firmware, please modify: +```python +CHIP8051_SIZE = 512 * SIZE_1K +``` +in which 512 is the custom size, and modify the address in `8051_boot_cfg.ini` to be the custom address. + +The Duo address calculation formula is "2147483648+ 64*1048576-[custom size]*1024". + +The Duo-256M address calculation formula is "2147483648+256*1048576-[custom size]*1024". + +(note that when filling the address to config file, it must be converted into a hexadecimal address 0xXXXXXXX.) +::: + +## 8051 SDCC + +### Introduction +`SDCC` is a cross-compiler whose target CPU is 8051. It is used in Duo to compile 8051 core related code. + +### 8051 on-chip resources + +#### Peripheral resources + +##### 8051 comes with peripherals + +1. Three 16bit Timers. + +2. One uart, multiplexed `PWR_UART_RX`/`PWR_UART_TX`. + +##### rtc domain peripherals + +8051 is generally used in low-power scenarios. The rtc domain will not lose power during poweroff/suspend, which is a no die domain. Therefore, the peripherals used by 8051 in most cases are on the rtc domain. The peripheral table of rtc domain is as follows: + + +##### AP on-chip peripherals + +8051 can access `0x0` ~ `0xFFFFFFFF` when the AP is powered on. In theory, all peripherals on the AP side can be accessed. However, whether the interrupt signal of the corresponding peripheral device can be transmitted to 8051, you need to check the aptortc interrupt table. + +#### interrupt controller + +##### Hardware structure + +The interrupt control of 8051 is divided into three parts: + +1. 8051 on-chip interrupt. + +2. Peripheral interrupt signal on rtc. + +3. The AP side interrupt. + +The interrupt numbers and supported interrupt types defined by 8051 are used as shown in the following table: + + +The peripheral interrupt signal on the rtc can be packaged and connected to the 8051 through `external interrupt 0` and `external interrupt 1`, which can be understood as sharing the `int0_n` and `int1_n` interrupt lines. As shown in the figure below, `irq_ap2rtc[1:0]` handles interrupt events on the AP. + + +The interrupt event on the AP side is ORed through `0x3000250` and `0x3000254`, and the interrupt on the AP side is packaged and transmitted to `irq_ap2rtc[0]`. The interrupt event on the AP side is packaged and transmitted to `irq_ap2rtc[1]` through `0x3000260` and `0x3000264`. + +:::tip +Please refer to "reg_top_misc.xlsx" for AP side interrupt event enable and view status. For supported interrupt types and corresponding ap interrupt number, please refer to sheet "toptortc" in "cv180x_interrupt.xlsx". +::: + +##### Interrupt the configuration process + +1. Configure interrupt events and enable corresponding interrupts. + +2. `0x3000248 = 0x01` enables rtc2ap bus conversion. + +3. Check the bit corresponding to the interrupt number enable `rtcsys_ap2rtc_irq0_sigen0`/`rtcsys_ap2rtc_irq0_sigen1` or `rtcsys_ap2rtc_irq1_sigen0`/`rtcsys_ap2rtc_irq1_sigen1`. + +4. enable `irq_ap2rtc[0]` or enable `irq_ap2rtc[1]`. + +5. enable `int0_n` or enable `int1_n` . + +6. After the interrupt response enters the external interrupt processing function, check dw_ictl or reg `0x502507c` status to see if it is due to the `irq_ap2rtc[0]` or `irq_ap2rtc[1]` event response. If so, check `rtcsys_ap2rtc_irq0_status0`/`crtcsys_ap2rtc_irq0_status1` or `rtcsys_ap2rtc_irq1_status0`/rtc `sys_ap2rtc_irq1_status1` View the responding AP interrupt event which one. + +Interrupt control example: +```C +#if TEST_APTORTC_ICTL + +static int __xdata aptortc_count = 0; +int test_aptortc_gpioa_isr(char irqn, int *priv) +{ + write_robot(0x0302004c, 0x8000); + printf("gpio0 interrupt\n"); + aptortc_count++; +} + +void test_aptortc_irq() +{ + printf("test aptortc irq\n"); + write_robot(0x03020004, 0x100c0020); //Set gpioA gpio15 as output + write_robot(0x03001908, 0x44); //Switch pinmux to pull-up + write_robot(0x03020030, 0xa000); //Enable interrupts + write_robot(0x03020038, 0x8000); //Set up edge triggering + + ap2rtc_irq_init(); + ap2rtc_request_irq(17, test_aptortc_gpioa_isr, NULL); + + ap2rtc_irq_unmask(17); + dw_ictl_unmask(IRQ_AP2RTC0_INTR); + irq_enable(); + + printf("REG_51_INT1_SRC_MASK: 0x%081x\n", read_robot(REG_51_INT1_SRC_MASK)); + EX0 = 1; + EX1 = 1; + EA = 1; + while(aptortc_count == 0) + printf("gpioA irq 0x3020040 = %x, aptortc_irq status = %x\n",read_robot(0x3020040),read_robot(0x3000258)); + + printf("aptortc_count = %d\n",aptortc_count); + irq_disable(); +} +#endif +``` + +### 8051 address mapping and startup method + +The 8051 core address space is divided into the following three parts: + +1. `Program memory`:Internal rom(64K)+External rom(64K~4M by code banking). + +2. `Data memory`:Internal ram(256byte)+External ram(64K~4G). + +3. `Special register`(128byte). + + + +:::tip +8051 itself does not come with externel rom and externel ram. What is expressed here is the bus addressability. In the system, externel rom and externel rom are mapped to the memory on the chip through `0x5025020` and `0x5025024` or `sfr (0xfd, 0xfc)`, such as AHB SRAM, TPU SRAM, DDR, SPINOR address space. +::: + +#### 8051 module responsible for address mapping + +1. `u_mcu_8051_iram`. + +2. `u_mcu_8051_sfr_wp`(Responsible for the conversion of SFR to AHB bus). + +3. `u_mcu_8051_xdata_wp`(Responsible for mapping externel rom and externel ram). + + + +The conversion from SFR to AHB bus is mainly used to read and write registers. In the code, `robot_read` and `robot_write` are through this interface. + +The 8051 address line has a bit width of 16 bits and the data line has a bit width of 8 bits. The `XDATA` interface maps externel rom and externel ram to 32-bit address space such as AHB SRAM, TPU SRAM, DDR and SPINOR. + +#### Notes on address mapping and startup methods + +1. cv181x and cv180x need to configure `reg_51_rom_addr_def = 1` in `0x5025020`. + +2. 8051 irom can only be mapped to AHB SRAM by default. You can modify `reg_51irom_ioffset[4:0]` in `0x5025024` to configure the offset of the first address on AHB SRAM.The first address is `0x5200000 + reg_51irom_ioffset[4:0] * 2KB`. Only when `reg_51_mem_ea_n = 1` (the configured externel rom does not exist), the mcu will start from the irom. If the irom address is exceeded, it will go to the externel rom to fetch address.When `reg_51_mem_ea_n = 0`, it starts from externel rom and does not use irom. + +3. The first address of externel rom can be mapped to AHB SRAM, TPU SRAM, DDR and SPINOR address space. The `reg_51xdata_ioffset0[20:0]` of `0x5025020` can be configured to determine the mapping address. The first address of externel rom is `reg_51xdata_ioffset0[20:0] * 2KB`. + +4. The first address of Externel ram can be mapped to AHB SRAM, TPU SRAM, DDR, and can be configured with `reg_51xdata_doffset0[20:0]` or `SFR(0xfd, 0xfc)`. + +5. If `reg_51xdata_doffset0[20:0]` is configured, the first address of the external ram is `reg_51xdata_doffset0[20:0] * 2KB`. At this time, sfr `0xfc = 0`, `0xfd = 0` must be set, and the address of `reg_51xdata_doffset0[20:0]` and `SFR` must be configured at the same time. It is the superimposed effect of the two. + +6. When `reg_51xdata_doffset0[20:0] = 0`, configure `SFR{0xfd,0xfc}`, then the first address of externel ram is `SFR{0xfd,0xfc} * 64KB` . + +:::tip +Since most 8051 are used in low-power consumption scenarios, most of the startup methods are that both program memory and data memory are mapped to AHB SRAM. +::: + +#### Modify the division of external rom and external ram + +Modify the `MakeFile` in the SDCC code directory `sdcc/mars/project/base_project`: +```makefile +# ------------------------------------------------------ +# Memory Layout + +# PRG Size = 4K Bytes +CODE_SIZE = --code-loc 0x0000 --code-size 0x1F00 + +# INT-MEM Size = 256 Bytes +#IRAM_SIZE = --idata-loc 0x0000 --iram-size 256 + +# EXT-MEM Size = 32K Bytes +XRAM_SIZE = --xram-loc 0x1900 --xram-size 0x400 + +# ------------------------------------------------------ +# MCS51 Options +``` +Modify `CODE_SIZE`, `XRAM_SIZE` to change the size of external rom and external ram. + +:::tip +AHB SRAM register size is 8KB. When using AHB SRAM as external rom, be careful not to allocate more than 8KB memory. +::: + +### SFR register + +The SFR (Special Function Register) is located at 80H~FFH. SFR registers are divided into two categories, one is the SFR register that comes with the 8051, and the other is the extended SFR register. The complete SFR register can be found at [d8051_db.pdf](https://github.com/milkv-duo/duo-8051/blob/main/doc/d8051_db.pdf) 。 + +:::tip +For more information on 8051 basic knowledge, please refer to the website [link](https://www.keil.com/support/man/docs/is51/) and datasheet [d8051_db.pdf](https://github.com/milkv-duo/duo-8051/blob/main/doc/d8051_db.pdf) 。 +::: + +#### Implementation of robot_write and robot_read + +The following figure shows the relevant SFR registers that implement `robot_write` and `robot_read` : + + +`robot_write` : + +1. Set `reg_51robot_size` 、 `reg_51robot_adr` 、 `reg_51robot_wd` 、`reg_51robot_we = 1` 。 + +2. `reg_51robot_fire` is set to 1 during writing, please poll this register until `reg_51robot_fire == 0`. + +`robot_read` : + +1. Set `reg_51robot_size` 、 `reg_51robot_adr` 、`reg_51robot_we = 0` 。 + +2. `reg_51robot_fire` is set to 1 during reading, please poll this register until `reg_51robot_fire == 0`. + +3. Read data from `reg_51robot_rd`. + +### Firmware loading tool 8051_UP + +This tool is used to load the bin firmware into memory and start the 8051 core. + +Source Code: [github](https://github.com/milkv-duo/duo-8051/tree/main/tools/8051_up)。 + +#### Compilation method + +run: +```bash +git clone https://github.com/milkv-duo/duo-examples.git +git clone https://github.com/milkv-duo/duo-8051.git +cp -r ./duo-8051/tools/8051_up ./duo-examples +cd ./duo-examples/8051_up +source ../envsetup.sh +make +``` + +After successful compilation, the executable file `8051_up` will be generated in the `duo-examples/8051_up` directory. + +:::tip +The compiled software can be found in [firmware.zip](https://github.com/milkv-duo/duo-8051/releases/download/Duo-8051-V1.0/firmware.zip) . For the compilation method, please refer to the Demo in [duo-examples](https://github.com/milkv-duo/duo-examples) . +::: diff --git a/i18n/ja/docusaurus-plugin-content-docs/current/duo/getting-started/_category_.json b/i18n/ja/docusaurus-plugin-content-docs/current/duo/getting-started/_category_.json new file mode 100644 index 00000000..22b2c714 --- /dev/null +++ b/i18n/ja/docusaurus-plugin-content-docs/current/duo/getting-started/_category_.json @@ -0,0 +1,9 @@ +{ + "label": "🚀 Getting Started", + "position": 10, + "link": { + "type": "generated-index", + "slug": "/duo/getting-started", + "description": "Getting Started with Duo" + } +} diff --git a/i18n/ja/docusaurus-plugin-content-docs/current/duo/getting-started/arduino.md b/i18n/ja/docusaurus-plugin-content-docs/current/duo/getting-started/arduino.md new file mode 100644 index 00000000..b6a39674 --- /dev/null +++ b/i18n/ja/docusaurus-plugin-content-docs/current/duo/getting-started/arduino.md @@ -0,0 +1,789 @@ +--- +sidebar_label: 'Arduino' +sidebar_position: 51 +--- + +# Introduction + +Arduino is a popular open-source hardware platform known for its simplicity, ease of use, and openness. It provides a rich collection of library functions and example code, making it accessible even for individuals without programming experience. Additionally, the Arduino community is highly active, allowing easy access to a wide range of project tutorials, documentation, and support. + +Milk-V Duo series now supports Arduino development. You can directly use the Arduino IDE and, after a simple configuration, start using it. + +The Duo series CPU adopts a big-little core design, where the Arduino firmware runs on the little core, while the big core is responsible for communication with the Arduino IDE. It receives the Arduino firmware and loads it onto the little core for execution. At the same time, the Linux system in the big core also operates normally. + +## 1. Development Environment Setup + +### Install Arduino IDE + +Arduino IDE supports three operating systems: Windows, Linux, and macOS. According to the system you are using, go to [Arduino official website](https://www.arduino.cc/en/software) to download the corresponding installation package for installation. The current latest version is 2.3.2, and it is recommended to use the latest version. + +### Add Duo to Arduino IDE + +Open Arduino IDE, select ``Preferences`` in the ``File`` menu, and add the Duo configuration file address in the ``Additional boards manager URLs`` in the ``Settings`` tab: + +``` +https://github.com/milkv-duo/duo-arduino/releases/download/V1.0.0/package_sg200x_index.json +``` + + + +Please download the latest json file address from [Releases](https://github.com/milkv-duo/duo-arduino/releases). + +If you have configured other development board addresses before, separate them with commas, or click the icon on the right side of the address bar to bring up the window, and follow the prompts to add them. + +After configuring, select ``Board`` in the ``Tools`` menu, open the ``Boards Manager``, search for *SG200X*, and click ``Install``. + + + +At this point, the Duo development environment in Arduino IDE has been installed. Now you can write and test the code. + +### Test blinking the onboard LED + +Currently, Duo's SD card system needs to burn firmware that supports Arduino. Please download the firmware with the prefix `arduino` from [Latest Release](https://github.com/milkv-duo/duo-buildroot-sdk/releases) firmware. + +Refer to [Boot the Duo](https://milkv.io/docs/duo/getting-started/boot) in the previous chapter to install the SD card system. + +Use a USB cable to connect Duo to your computer, and Duo will automatically power on. + +Duo's default firmware, the large-core Linux system, will control the on-board LED flashing. This is achieved through the boot script. Now we are going to use the little-core Arduino to light up the LED. We need to disable the LED flashing script in the large-core Linux. In Duo's Execute in terminal: +``` +mv /mnt/system/blink.sh /mnt/system/blink.sh_backup && sync +``` +That is to say, rename the LED flashing script. After restarting Duo, the LED will no longer flash: +``` +reboot +``` + +At this time, there will be an additional serial device in the "Port" of the "Device Manager" of the computer. + + + +On the main interface of Arduino IDE, click ``Select Board``, and then click ``Select other board and port...`` + + + +Search for "duo", select ``Duo Dev Module`` for Duo, select ``Duo256 Dev Module`` for Duo256M, select the corresponding serial port in the port and click OK. + + + +Open the ``Examples`` > ``01.Basics`` > ``Blink`` test program in the ``File`` menu of the Arduino IDE. The function of this program is to blink the onboard LED of the Arduino device. In Duo It is also supported. You may need to install pyserial in order to upload, and then let’s just click the ``Upload`` button to test: + + + +At this time, you can see the LED on the Duo board blinking at intervals of 1 second. + +## 2. Duo Arduino pin resource + +### Duo + +
+ +| SPI | PWM | I2C | UART | GPIO | NAME | PIN | PIN | NAME | GPIO | ADC | +|-----------|-------|----------|----------|:----:|-----:|:-------------------------------:|:--------------------------------:|----------|:----:|------| +| | | I2C0_SCL | | 1 | GP0 |
1
|
40
| VBUS | | | +| | | I2C0_SDA | | 2 | GP1 |
2
|
39
| VSYS | | | +| | | | | | GND |
3
|
38
| GND | | | +| | PWM10 | | | | GP2 |
4
|
37
| 3V3_EN | | | +| | PWM11 | | | | GP3 |
5
|
36
| 3V3(OUT) | | | +| | | | UART3_TX | | GP4 |
6
|
35
| | | | +| | | | UART3_RX | | GP5 |
7
|
34
| | | | +| | | | | | GND |
8
|
33
| GND | | | +| SPI2_SCK | | | | | GP6 |
9
|
32
| GP27 | | | +| SPI2_MOSI | | | | | GP7 |
10
|
31
| GP26 | | ADC1 | +| SPI2_MISO | | I2C1_SDA | | | GP8 |
11
|
30
| RUN | | | +| SPI2_CSn | | I2C1_SCL | | | GP9 |
12
|
29
| GP22 | | | +| | | | | | GND |
13
|
28
| GND | | | +| | | | | 14 | GP10 |
14
|
27
| GP21 | 27 | | +| | | | | 15 | GP11 |
15
|
26
| GP20 | 26 | | +| | | | | | GP12 |
16
|
25
| GP19 | 25 | | +| | | | | | GP13 |
17
|
24
| GP18 | 24 | | +| | | | | | GND |
18
|
23
| GND | | | +| | | | | 19 | GP14 |
19
|
22
| GP17 | 22 | | +| | | | | 20 | GP15 |
20
|
21
| GP16 | 21 | | +| | | | | | |   | | | | | +| | | | | 0 | |
LED
| | | | | + +
+ +### Duo256M + +
+ +| SPI | PWM | I2C | UART | GPIO | NAME | PIN | PIN | NAME | GPIO | ADC | +|-----------|------|----------|----------|:----:|-----:|:-------------------------------:|:--------------------------------:|----------|:----:|------| +| | | | | 1 | GP0 |
1
|
40
| VBUS | | | +| | | | | 2 | GP1 |
2
|
39
| VSYS | | | +| | | | | | GND |
3
|
38
| GND | | | +| | PWM7 | | | | GP2 |
4
|
37
| 3V3_EN | | | +| | PWM6 | | | | GP3 |
5
|
36
| 3V3(OUT) | | | +| | | | UART3_TX | | GP4 |
6
|
35
| | | | +| | | | UART3_RX | | GP5 |
7
|
34
| | | | +| | | | | | GND |
8
|
33
| GND | | | +| SPI2_SCK | | I2C3_SDA | | | GP6 |
9
|
32
| GP27 | | | +| SPI2_MOSI | | I2C3_SCL | | | GP7 |
10
|
31
| GP26 | | ADC1 | +| SPI2_MISO | | I2C1_SDA | | | GP8 |
11
|
30
| RUN | | | +| SPI2_CSn | | I2C1_SCL | | | GP9 |
12
|
29
| GP22 | | | +| | | | | | GND |
13
|
28
| GND | | | +| | | I2C2_SDA | | 14 | GP10 |
14
|
27
| GP21 | 27 | | +| | | I2C2_SCL | | 15 | GP11 |
15
|
26
| GP20 | 26 | | +| | | | | | GP12 |
16
|
25
| GP19 | 25 | | +| | | | | | GP13 |
17
|
24
| GP18 | 24 | | +| | | | | | GND |
18
|
23
| GND | | | +| | | | | 19 | GP14 |
19
|
22
| GP17 | 22 | | +| | | | | 20 | GP15 |
20
|
21
| GP16 | 21 | | +| | | | | | |   | | | | | +| | | | | 0 | |
LED
| | | | | + +
+ +## 3. Code example + +### GPIO Usage Example + +This program implements Duo physical pin 20 to output high and low levels cyclically with an interval of 1 second, and observe the phenomenon through an external LED. + +The connection method is as follows. The negative pole of the LED is connected to the ground of the Duo (for example, pin 18), and the positive pole is connected in series with a 1K resistor and then connected to pin 20: + + + +test code: +```C +#define TEST_PIN 20 //0,1,2,14,15,19,20,21,22,24,25,26,27 + +// the setup function runs once when you press reset or power the board +void setup() { + pinMode(TEST_PIN, OUTPUT); +} + +// the loop function runs over and over again forever +void loop() { + digitalWrite(TEST_PIN, HIGH); // turn the TEST_PIN on (HIGH is the voltage level) + delay(1000); // wait for a second + digitalWrite(TEST_PIN, LOW); // turn the TEST_PIN off by making the voltage LOW + delay(1000); // wait for a second +} +``` + +:::tip +- If the LED is not connected, you can observe the status changes of the pin through a multimeter or oscilloscope. +- Configuring TEST_PIN to 0 enables testing of the Duo onboard LED. +::: + +### UART Usage Example + +#### UART Serial port + +The UART serial port uses `UART3` on physical pin `6/7` by default. When debugging the Arduino program, you can print debugging information through this serial port. + +The connection method is as follows. The computer can use a USB to TTL serial port cable. The logic level is 3.3V and the baud rate is 115200. The RX of the serial port cable is connected to the PIN 6 UART3_TX of the Duo. The TX of the serial port cable is connected to the PIN 7 UART3_RX of the Duo. The serial port The GND of the line is connected to any GND of the Duo, such as pin 3: + + + +test code: +```C +void setup() { + Serial.begin(115200); +} + +void loop() { + Serial.printf("hello world\r\n"); + delay(1000); +} +``` + +After running, you can see the "hello world" string printed every 1 second in the computer serial port tool: +``` +hello world +hello world +``` + +In addition, the default serial port uses Duo's UART3 interface, so `Serial3` can also be used in the program: +```C +void setup() { + Serial3.begin(115200); +} + +void loop() { + Serial3.printf("hello world\r\n"); + delay(1000); +} +``` + +### I2C Usage Example + +:::caution +The I2C interface resources of Duo and Duo256M are different and need to be used according to the previous pin resource diagram. +::: + +#### I2C0 sends data to I2C1 (Duo) + +The hardware connection is as follows. Connect the SDA and SCL pins of I2C0 and I2C1 correspondingly, and then connect the serial port to the computer to view the printing information according to the method in the UART example above. + + + +The `Wire` function in Duo is mapped to I2C0 by default, that is, `Wire` is equivalent to `Wire0`. + +Test code: +```C +#include + +void receive(int a) { + Serial.printf("receive %d bytes\n\r", a); + while(a--) { + Serial.printf("%d \n\r", Wire1.read()); + } +} + +void setup() { + Serial.begin(115200); + Wire1.begin(0x50); + Wire1.onReceive(receive); + Wire.begin(); + Serial.printf("test slave\n\r"); + Wire1.print(); +} + +byte val = 0; + +void loop() { + Wire.beginTransmission(0x50); // Transmit to device number 0x50 + Serial.printf("send %d \n\r", ++val); + Wire.write(val); // Sends value byte + Wire.endTransmission(); // Stop transmitting + Wire1.onService(); + delay(1000); +} +``` + +Test Results: +``` +test slave +Wire1: 1 +[iic_dump_register]: ===dump start +IC_CON = 0x22 +IC_TAR = 0x55 +IC_SAR = 0x50 +IC_SS_SCL_HCNT = 0x1ab +IC_SS_SCL_LCNT = 0x1f3 +IC_ENABLE = 0x1 +IC_STATUS = 0x6 +IC_INTR_MASK = 0x224 +IC_INTR_STAT = 0 +IC_RAW_INTR_STAT = 0x10 +[iic_dump_register]: ===dump end +send 1 +receive 1 bytes +1 +send 2 +receive 1 bytes +2 +send 3 +receive 1 bytes +3 +send 4 +receive 1 bytes +4 +``` + +#### I2C1 sends data to I2C2 (Duo256M) + +:::tip +Note that Duo256M does not have I2C0. +::: + +The hardware connection is as follows. Connect the SDA and SCL pins of I2C1 and I2C2 correspondingly, and then connect the serial port to the computer to view the printing information according to the method in the UART example above. + + + +The `Wire` function in Duo256M is mapped to I2C1 by default, that is, `Wire` is equivalent to `Wire1`. + +Test code: +```C +#include + +void receive(int a) { + Serial.printf("receive %d bytes\n\r", a); + while(a--) { + Serial.printf("%d \n\r", Wire2.read()); + } +} + +void setup() { + Serial.begin(115200); + + Wire2.begin(0x50); + Wire2.onReceive(receive); + + Wire.begin(); + Serial.printf("test slave\n\r"); + Wire2.print(); +} + +byte val = 0; + +void loop() { + Wire.beginTransmission(0x50); // Transmit to device number 0x50 + Serial.printf("send %d \n\r", ++val); + Wire.write(val); // Sends value byte + Wire.endTransmission(); // Stop transmitting + Wire2.onService(); + delay(1000); +} +``` + +Test Results: +``` +test slave +Wire2: 1 +[iic_dump_register]: ===dump start +IC_CON = 0x22 +IC_TAR = 0x55 +IC_SAR = 0x50 +IC_SS_SCL_HCNT = 0x1ab +IC_SS_SCL_LCNT = 0x1f3 +IC_ENABLE = 0x1 +IC_STATUS = 0x6 +IC_INTR_MASK = 0x224 +IC_INTR_STAT = 0 +IC_RAW_INTR_STAT = 0x10 +[iic_dump_register]: ===dump end +send 1 +receive 1 bytes +1 +send 2 +receive 1 bytes +2 +send 3 +receive 1 bytes +3 +send 4 +receive 1 bytes +4 +``` + +### SPI Usage Example + +#### SPI loopback test + +The hardware connection is as follows. Short-circuit the MOSI and MISO of the SPI, that is, pin 10 and pin 11, and then connect the serial port to the computer according to the method in the UART example above to view the printing information. + + + +Test code: +```C +#include + +char str[]="hello world\n"; +void setup() { + // put your setup code here, to run once: + Serial.begin(115200); + SPI.begin(); +} + +byte i = 0; + +void loop() { + // put your main code here, to run repeatedly: + // digitalWrite(12, 1); + SPI.beginTransaction(SPISettings()); + Serial.printf("transfer %c\n\r", str[i]); + char out = SPI.transfer(str[i++]); // spi loop back + SPI.endTransaction(); + Serial.printf("receive %x \n\r", out); + i %= 12; +} +``` + +Test Results: +``` +receive a +transfer h +receive 68 +transfer e +receive 65 +transfer l +receive 6c +transfer l +receive 6c +transfer o +receive 6f +transfer +receive 20 +transfer w +receive 77 +transfer o +receive 6f +transfer r +receive 72 +transfer l +receive 6c +transfer d +receive 64 +transfer +``` + +### PWM Usage Example + +The hardware connection is as follows. Connect the DUO's GP4 to the negative lead of the LED. + + + +Test code: +```C +void setup() { + pinMode(6, OUTPUT); +} + +void loop() { + for(int i = 128; i < 255; i++) + { + analogWrite(6,i); + delay(50); + } + for(int i = 255; i > 128; i--) + { + analogWrite(6,i); + delay(50); + } +} +``` + +After compiling and burning, you can observe the LED light breathing effect. + +### ADC Usage Example + +The hardware connection is as follows. Connect the GP26 of DUO to the signal pin of the potentiometer, and connect the other two pins to the positive and negative poles of the power supply respectively. + + + +Test code: +```C +int adc_get_val = 0; + +void setup() { + pinMode(0,OUTPUT); +} + +void loop() { + adc_get_val = analogRead(31); + + digitalWrite(0,HIGH); + delay(adc_get_val); + digitalWrite(0,LOW); + delay(adc_get_val); +} +``` + +After compiling and burning, you can observe that the flashing frequency of the onboard LED changes as the position of the potentiometer changes. + +### MailBox Usage Example + +Compile and burn the following code into the small core Arduino. This program can read the information sent by the large core from the MailBox and print it to the serial port, for serial port wiring, please refer to the [UART Usage Example](#uart-usage-example) in this chapter. + +```C + +#include "mailbox.h" + +struct valid_t { + uint8_t linux_valid; + uint8_t rtos_valid; +} __attribute__((packed)); + +typedef union resv_t { + struct valid_t valid; + unsigned short mstime; // 0 : noblock, -1 : block infinite +} resv_t; + +typedef struct cmdqu_t cmdqu_t; +/* cmdqu size should be 8 bytes because of mailbox buffer size */ +struct cmdqu_t { + uint8_t ip_id; + uint8_t cmd_id : 7; + uint8_t block : 1; + union resv_t resv; + unsigned int param_ptr; +} __attribute__((packed)) __attribute__((aligned(0x8))); + +void showmsg(MailboxMsg msg) { + cmdqu_t *cmdq; + Serial.print("Get Msg: "); + Serial.println(*(msg.data), HEX); + cmdq = (cmdqu_t *)msg.data; + Serial.printf("cmdq->ip_id = %d\r\n", cmdq->ip_id); + Serial.printf("cmdq->cmd_id = %x\r\n", cmdq->cmd_id); + Serial.printf("cmdq->block = %d\r\n", cmdq->block); + Serial.printf("cmdq->para_ptr = %x\r\n", cmdq->param_ptr); + *(msg.data) = 0; +} + +void setup() { + Serial.begin(115200); + mailbox_init(false); + mailbox_register(0, showmsg); + mailbox_enable_receive(0); + Serial.println("Mailbox Start"); +} + +void loop() { + +} + +``` + +Compile the test program [mailbox_test](https://github.com/milkv-duo/duo-examples/tree/main/mailbox-test) and run it on large-core Linux. The test program has been stored in the [duo-examples](https://github.com/milkv-duo/duo-examples) warehouse. You can refer to [README](https://github.com/milkv-duo/duo-examples/blob/main/README.md) for compilation. + +After running, the big core Linux output: + +``` + +C906B: cmd.param_ptr = 0x2 +C906B: cmd.param_ptr = 0x3 + +``` + +Small core serial port printing: + +``` + +Mailbox Start +Get Msg: 19300 +cmdq->ip_id = 0 +cmdq->cmd_id = 13 +cmdq->block = 1 +cmdq->para_ptr = 2 +Get Msg: 19300 +cmdq->ip_id = 0 +cmdq->cmd_id = 13 +cmdq->block = 1 +cmdq->para_ptr = 3 + +``` + +## 4. Sensor examples + +### L9110H_test + +L9110H_test source:[https://github.com/milkv-duo/duo-arduino-examples/tree/master/L9110H_test](https://github.com/milkv-duo/duo-arduino-examples/tree/master/L9110H_test) + +For the example code of the DC motor driver chip L9110H, connect the wires according to the code comments and then burn and run. The motor will run in cycles of gradual acceleration and deceleration, and reverse gradual acceleration and deceleration. + +### LCD1602 + +LCD1602_test source:[https://github.com/milkv-duo/duo-arduino-examples/tree/master/LCD1602_test](https://github.com/milkv-duo/duo-arduino-examples/tree/master/LCD1602_test) + +Example code for the LCD1602 I2C interface screen. Connect the wires according to the code comments and then burn and run. The screen will display a string. + +### LCD2004 + +LCD2004_test source:[https://github.com/milkv-duo/duo-arduino-examples/tree/master/LCD2004_test](https://github.com/milkv-duo/duo-arduino-examples/tree/master/LCD2004_test) + +Example code for the LCD2004 I2C interface screen. Connect the wires according to the code comments and then burn and run. The screen will display a string. + +### Buzzer + +buzzer_test source:[https://github.com/milkv-duo/duo-arduino-examples/tree/master/buzzer_test](https://github.com/milkv-duo/duo-arduino-examples/tree/master/buzzer_test) + +Example code for the buzzer module, wired according to the code comments and burned to run. The buzzer plays three different frequencies of beeps in a loop. + +### HC-SR04 + +hc_sr04_test source:[https://github.com/milkv-duo/duo-arduino-examples/tree/master/hc_sr04_test](https://github.com/milkv-duo/duo-arduino-examples/tree/master/hc_sr04_test) + +Example code for HC-SR04 ultrasonic distance measurement sensor module. After burning and running the example code, the board will print the measured distance data to the serial port. + +### RC522 + +rc522_test source:[https://github.com/milkv-duo/duo-arduino-examples/tree/master/rc522_test](https://github.com/milkv-duo/duo-arduino-examples/tree/master/rc522_test) + +Example code for RC522 RFID read-write module. After burning and running the code, the board will loop to check if the ID card is read. If the ID card is detected, it will print the card type and card number information to the serial port. + +### SSD1306 + +ssd1306_test source:[https://github.com/milkv-duo/duo-arduino-examples/tree/master/ssd1306_test](https://github.com/milkv-duo/duo-arduino-examples/tree/master/ssd1306_test) + +Example code for SSD1306 OLED screen module. After wiring according to comments and burning the code, the screen displays a dynamic animation of the eyes. + +## 5. Arduino APIs + +### Digital I/O + +
+ +digitalWrite() + +``` +void digitalWrite(uint8_t pinNumber, uint8_t status) +``` +Write a HIGH or a LOW value to a digital pin. + +
+ +
+ +digitalRead() + +``` +int digitalRead(uint8_t pinNumber) +``` +Reads the value from a specified digital pin, either HIGH or LOW. + +
+ +
+ +pinMode() + +``` +void pinMode(uint8_t pinNumber, uint8_t pinMode) +``` +Configures the specified pin to behave either as an input or an output + +
+ +### Analog I/O + +
+ +analogRead() + +``` +uint32_t analogRead(uint32_t pinNumber) +``` +Reads the value from the specified analog pin. + +
+ +
+ +analogReadResolution() + +``` +void analogReadResolution(int bits) +``` +Sets the size (in bits) of the value returned by analogRead(). + +
+ +
+ +analogWrite() + +``` +void analogWrite(uint8_t pinNumber, uint32_t val) +``` +Writes an analog value (PWM wave) to a pin. + +
+ +
+ +analogWriteResolution() + +``` +void analogWriteResolution(int bits) +``` +analogWriteResolution() sets the resolution of the analogWrite() function. + +
+ +### Wire(I2C) + +
+ +begin() + +``` +void begin(csi_iic_addr_mode_t addr_mode = IIC_ADDRESS_7BIT); +void begin(uint16_t address, csi_iic_addr_mode_t addr_mode = IIC_ADDRESS_7BIT); +``` + + +
+ +
+ +beginTransmission() + +``` +void beginTransmission(uint16_t); +``` + +
+ +
+ +endTransmission() + +``` +uint8_t endTransmission(bool stopBit); +uint8_t endTransmission(void); +``` + +
+ +
+ +requestFrom() + +``` +size_t requestFrom(uint16_t address, size_t quantity, bool stopBit); +size_t requestFrom(uint16_t address, size_t quantity); +``` + +
+ +
+ +write() + +``` +size_t write(uint8_t data); +size_t write(const uint8_t * data, size_t quantity); +``` + +
+ +
+ +available() + +``` +virtual int available(void); +``` + + +
+ +
+ +read() + +``` +virtual int read(void); +``` + +
+ +
+ +onReceive() + +``` +void onReceive(void(*)(int)); +``` + +
+ +
+ +onRequest() + +``` +void onRequest(void(*)(void)); +``` + +
+ +
+ +Other functional interfaces and their usage in Duo will be updated in the future. You can also refer to [Arduino official documentation](https://www.arduino.cc/reference/en/) first. diff --git a/i18n/ja/docusaurus-plugin-content-docs/current/duo/getting-started/boot.md b/i18n/ja/docusaurus-plugin-content-docs/current/duo/getting-started/boot.md new file mode 100644 index 00000000..689c0359 --- /dev/null +++ b/i18n/ja/docusaurus-plugin-content-docs/current/duo/getting-started/boot.md @@ -0,0 +1,50 @@ +--- +sidebar_label: 'Boot the Duo' +sidebar_position: 10 +--- + +# Boot Duo from microSD card + +## Prepare + +- Necessary + - Duo, Duo256M or DuoS + - microSD card, larger than 1GB + - Type-C cable +- Optional + - USB to TTL serial cable + +## Download images and tools + +- Download the system image from [Official Image and SDK](https://milkv.io/docs/duo/resources/image-sdk). +- Download the flash tool, [balenaEtcher](https://etcher.balena.io/) or [Rufus](https://rufus.ie/en/). + +## Burn image + +Here are the steps for using balenaEtcher. + +- Click **Flash from file** + +![etcher-step1](/docs/duo/etcher-step1.png) + +- Click **Select target** + +![etcher-step2](/docs/duo/etcher-step2.png) + +- Click **Flash!** + +![etcher-step3](/docs/duo/etcher-step3.png) + +## Power on + +Connect the Duo with a Type-C cable using an adapter (5V) or computer USB. + +The blue LED on the Duo will blink. + +:::tip +If the blue LED does not blink after booting, it means the system is not running properly, and there may be a problem with the image burned to the microSD. You can try to re-burn the image with other burning software, such as balenaEtcher, Rufus, Win32DiskImager, etc. If it still cannot boot normally, you can connect a serial cable and send the log after booting to us for analysis. +::: + +## Troubleshooting + +If you have a problem, go to our [community](https://community.milkv.io/) and post to let us know. diff --git a/i18n/ja/docusaurus-plugin-content-docs/current/duo/getting-started/buildroot-sdk.md b/i18n/ja/docusaurus-plugin-content-docs/current/duo/getting-started/buildroot-sdk.md new file mode 100644 index 00000000..c1f0749d --- /dev/null +++ b/i18n/ja/docusaurus-plugin-content-docs/current/duo/getting-started/buildroot-sdk.md @@ -0,0 +1,485 @@ +--- +sidebar_label: 'Buildroot SDK' +sidebar_position: 40 +--- + +# Introduction + +Duo's default SDK is built based on buildroot and is used to generate Duo's firmware. The SDK mainly contains the following parts: + +- u-boot: 2021.10 +- linux kernel: 5.10.4 +- buildroot: 2021.05 +- opensbi: 89182b2 + +Source code: [github](https://github.com/milkv-duo/duo-buildroot-sdk) + +SDK Directory Structure + +```text +├── build // compilation scripts and board configs +├── build.sh // one-click compilation script +├── buildroot-2021.05 // buildroot source code +├── freertos // freertos system +├── fsbl // fsbl firmware in prebuilt form +├── install // temporary images stored here +├── isp_tuning // camera effect parameters +├── linux_5.10 // linux kernel +├── middleware // self-developed multimedia framework +├── device // configuration files for milkv +├── opensbi // opensbi library +├── out // final image for SD card +├── ramdisk // prebuilt ramdisk +└── u-boot-2021.10 // u-boot source code +``` + +:::tip +The current SDK does not support the ARM core of Duo256M and DuoS. If you need to use the ARM core, you can temporarily refer to this repositories: + +duo-build: [https://github.com/milkv-duo/duo-build](https://github.com/milkv-duo/duo-build) +::: + +# Build image + +Prepare the Compilation Environment. Using a local Ubuntu system, the officially supported compilation environment is `Ubuntu Jammy 22.04.x amd64` only! + +If you are using other Linux distributions, we strongly recommend that you use the Docker environment to compile to reduce the probability of compilation errors. + +The following describes the compilation methods in the two environments. + +## 1. Compiled using Ubuntu 22.04 + +### Packages to be installed + +Install the packages that compile dependencies: + +```bash +sudo apt install -y pkg-config build-essential ninja-build automake autoconf libtool wget curl git gcc libssl-dev bc slib squashfs-tools android-sdk-libsparse-utils jq python3-distutils scons parallel tree python3-dev python3-pip device-tree-compiler ssh cpio fakeroot libncurses5 flex bison libncurses5-dev genext2fs rsync unzip dosfstools mtools tcl openssh-client cmake expect +``` + +### Get SDK Source Code + +```bash +git clone https://github.com/milkv-duo/duo-buildroot-sdk.git --depth=1 +``` + +### 1). One-click Compilation + +Execute one-click compilation script `build.sh`: +```bash +cd duo-buildroot-sdk/ +./build.sh +``` + +You will see tips on how to use the compiled script: +```bash +# ./build.sh +Usage: +./build.sh - Show this menu +./build.sh lunch - Select a board to build +./build.sh [board] - Build [board] directly, supported boards asfollows: +milkv-duo +milkv-duo256m +``` +Listed at the bottom is the list of currently supported target versions. + +As shown in the prompt, there are two ways to compile the target version. + +The first method is to execute `./build.sh lunch` to bring up the interactive menu, select the version number to be compiled, and press Enter: +```bash +# ./build.sh lunch +Select a target to build: +1. milkv-duo +2. milkv-duo256m +Which would you like: +``` + +The second method is to put the name of the target version after the script and compile it directly. For example, if you need to compile the image of `milkv-duo`, the command is as follows: +```bash +# ./build.sh milkv-duo +``` + +After a successful compilation, you can find the generated SD card burning image `milkv-duo-*-*.img` in the `out` directory. + +*Note: The first compilation will automatically download the required toolchain, which is approximately 840MB in size. Once downloaded, it will be automatically extracted to the `host-tools` directory in the SDK directory. For subsequent compilations, if the `host-tools` directory is detected, the download will not be performed again*. + +### 2). Step-by-step Compilation + +If you have not executed the one-click compilation script, you need to manually download the toolchain [host-tools](https://sophon-file.sophon.cn/sophon-prod-s3/drive/23/03/07/16/host-tools.tar.gz) and extract it to the SDK root directory: + +```bash +tar -xf host-tools.tar.gz -C /your/sdk/path/ +``` + +Then enter the following commands in sequence to complete the step-by-step compilation. Replace `[board]` and `[config]` in the command with the version that needs to be compiled. The currently supported `board` and corresponding `config` are as follows: +``` +milkv-duo cv1800b_milkv_duo_sd +milkv-duo256m cv1812cp_milkv_duo256m_sd +``` + +```bash +source device/[board]/boardconfig.sh + +source build/milkvsetup.sh +defconfig [config] +clean_all +build_all +pack_sd_image +``` + +For example, if you need to compile the image of `milkv-duo`, the step-by-step compilation command is as follows: +```bash +source device/milkv-duo/boardconfig.sh + +source build/milkvsetup.sh +defconfig cv1800b_milkv_duo_sd +clean_all +build_all +pack_sd_image +``` + +Generated firmware location: +``` +Duo: install/soc_cv1800b_milkv_duo_sd/[board].img +Duo256M: install/soc_cv1812cp_milkv_duo256m_sd/[board].img +``` + +## 2. Compiled using Docker + +Docker support is required on hosts running Linux systems. For how to use Docker, please refer to the [official documentation](https://docs.docker.com/) or other tutorials. + +We put the SDK source code on the Linux host system and call the Docker image environment provided by Milk-V to compile it. + +### Pull SDK code on Linux host + +```bash +git clone https://github.com/milkv-duo/duo-buildroot-sdk.git --depth=1 +``` + +### Enter the SDK code directory + +```bash +cd duo-buildroot-sdk +``` + +### Pull the Docker image and run + +```bash +docker run -itd --name duodocker -v $(pwd):/home/work milkvtech/milkv-duo:latest /bin/bash +``` + +Description of some parameters in the command: +- `duodocker` Docker name, you can use the name you want to use. +- `$(pwd)` The current directory, here is the duo-buildroot-sdk directory that was 'cd' to in the previous step. +- `-v $(pwd):/home/work` Bind the current code directory to the /home/work directory in the Docker image. +- `milkvtech/milkv-duo:latest` The Docker image provided by Milk-V will be automatically downloaded from hub.docker.com for the first time. + +After Docker runs successfully, you can use the `docker ps -a` command to view the running status: +```bash +$ docker ps -a +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +8edea33c2239 milkvtech/milkv-duo:latest "/bin/bash" 2 hours ago Up 2 hours duodocker +``` + +### 1). One-click compilation using Docker + +```bash +docker exec -it duodocker /bin/bash -c "cd /home/work && cat /etc/issue && ./build.sh [board]" +``` + +Note that the `./build.sh [board]` at the end of the command is the same as the previous usage in the one-click compilation instructions in Ubuntu 22.04. Use `./build.sh` can see how to use the command, use `./ build.sh lunch` can bring up the interactive selection menu, use `./build.sh [board]` to directly compile the target version, `[board]` can be replaced with: +``` +milkv-duo +milkv-duo256m +``` + +Description of some parameters in the command: +- `duodocker` The name of the running Docker must be consistent with the name set in the previous step. +- `"*"` In quotes is the shell command to be run in the Docker image. +- `cd /home/work` Switch to the /home/work directory. Since this directory has been bound to the host's code directory during runtime, the /home/work directory in Docker is the source code directory of the SDK. +- `cat /etc/issue` Displays the version number of the image used by Docker. It is currently Ubuntu 22.04.3 LTS and is used for debugging. +- `./build.sh [board]` Execute one-click compilation script. + +For example, if you need to compile the image of `milkv-duo`, the command is as follows: +```bash +docker exec -it duodocker /bin/bash -c "cd /home/work && cat /etc/issue && ./build.sh milkv-duo" +``` + +After successful compilation, you can see the generated SD card burning image `[board]-*-*.img` in the `out` directory. + +### 2). Compile step by step using Docker + +If you have not executed the one-click compilation script, you need to manually download the toolchain [host-tools](https://sophon-file.sophon.cn/sophon-prod-s3/drive/23/03/07/16/host-tools.tar.gz) and extract it to the SDK root directory: + +```bash +tar -xf host-tools.tar.gz -C /your/sdk/path/ +``` + +Step-by-step compilation requires logging into Docker to operate. Use the command `docker ps -a` to view and record the ID number of the container, such as 8edea33c2239. + +Enter Docker: +```bash +docker exec -it 8edea33c2239 /bin/bash +``` + +Enter the code directory bound in Docker: +```bash +root@8edea33c2239:/# cd /home/work/ +``` + +Then enter the following commands in sequence to complete the step-by-step compilation. Replace `[board]` and `[config]` in the command with the version that needs to be compiled. The currently supported `board` and corresponding `config` are as follows: +``` +milkv-duo cv1800b_milkv_duo_sd +milkv-duo256m cv1812cp_milkv_duo256m_sd +``` + +```bash +source device/[board]/boardconfig.sh + +source build/milkvsetup.sh +defconfig [config] +clean_all +build_all +pack_sd_image +``` + +For example, if you need to compile the image of `milkv-duo`, the step-by-step compilation command is as follows: +```bash +source device/milkv-duo/boardconfig.sh + +source build/milkvsetup.sh +defconfig cv1800b_milkv_duo_sd +clean_all +build_all +pack_sd_image +``` + +Generated firmware location: +``` +Duo: install/soc_cv1800b_milkv_duo_sd/[board].img +Duo256M: install/soc_cv1812cp_milkv_duo256m_sd/[board].img +``` + +Generated firmware location: `install/soc_cv1800b_milkv_duo_sd/milkv-duo.img`. + +After compilation is completed, you can use the `exit` command to exit the Docker environment: +```bash +root@8edea33c2239:/home/work# exit +``` +The generated firmware can also be seen in the host code directory. + +### Stop Docker + +After compilation is completed, if the above Docker running environment is no longer needed, you can stop it first and then delete it: +```bash +docker stop 8edea33c2239 +docker rm 8edea33c2239 +``` + +## 3. Other compilation considerations + +If you want to try to compile this SDK in an environment other than the above two environments, the following are things you may need to pay attention to, for reference only. + +### cmake version + +Note:`cmake` minimum version requirement is `3.16.5`. + +Check the version of `cmake` in the system: + +```bash +cmake --version +``` + +For example, the version of `cmake` installed using apt in the `Ubuntu 20.04` is: + +``` +cmake version 3.16.3 +``` + +The minimum requirement of this SDK is not met. Manual installation of the latest version `3.27.6` is needed: + +```bash +wget https://github.com/Kitware/CMake/releases/download/v3.27.6/cmake-3.27.6-linux-x86_64.sh +chmod +x cmake-3.27.6-linux-x86_64.sh +sudo sh cmake-3.27.6-linux-x86_64.sh --skip-license --prefix=/usr/local/ +``` + +When manually installed, `cmake` is located in `/usr/local/bin`. To check its version, use the command `cmake --version`, which should display: + +``` +cmake version 3.27.6 +``` + +### Compiling with Windows Linux Subsystem (WSL) + +If you wish to perform the compilation with WSL, there's an small issue building the image. +The $PATH, due Windows interoperability, has Windows environment variables which include some spaces between the paths. + +To solve this problem you need to change the `/etc/wsl.conf` file and add the following lines: + +``` +[interop] +appendWindowsPath = false +``` + +After that, you need to reboot the WSL with `wsl.exe --reboot`. Then you able to run the `./build.sh` script or the `build_all` line in the step-by-step compilation method. +To rollback this change in `/etc/wsl.conf` file set `appendWindowsPath` as true. To reboot the WSL, can you use the Windows PowerShell command `wsl.exe --shutdown` then `wsl.exe`, after that the Windows environment variables become avaliable again in $PATH. + +## 4. Add application packages + +Buildroot is a lightweight embedded Linux system building tool. The system it generates does not have the apt package management tool like the Ubuntu system to download and use application packages. Duo's default SDK has added some commonly used tools or commands. If you need to add your own applications, you need to make some modifications to the SDK and recompile to generate the required system firmware. + +The following introduces several common methods for adding application packages in Buildroot. + +### Enable commands in Busybox + +In a system built using Buildroot, some basic commands are provided by busybox. You can check whether the configuration file of busybox contains the commands you need, enable it and recompile. The location of the configuration file of busybox is: + +``` +buildroot-2021.05/package/busybox/busybox.config +``` + +For example, the timeout command, how to enable it: + +```diff {9,10} +diff --git a/buildroot-2021.05/package/busybox/busybox.config b/buildroot-2021.05/package/busybox/busybox.config +index d7d58f064..b268cd6f8 100644 +--- a/buildroot-2021.05/package/busybox/busybox.config ++++ b/buildroot-2021.05/package/busybox/busybox.config +@@ -304,7 +304,7 @@ CONFIG_TEST=y + CONFIG_TEST1=y + CONFIG_TEST2=y + CONFIG_FEATURE_TEST_64=y +-# CONFIG_TIMEOUT is not set ++CONFIG_TIMEOUT=y + CONFIG_TOUCH=y + # CONFIG_FEATURE_TOUCH_NODEREF is not set + CONFIG_FEATURE_TOUCH_SUSV3=y +``` + +Refer to this commit: [busybox: add timeout command](https://github.com/milkv-duo/duo-buildroot-sdk/commit/2833c24f11bb48776094265b7b16cfde87f86083) + +### Configure application packages preset in Buildroot + +In addition, a large number of application packages are preset in Buildroot. The required programs are generated by downloading the source code and compiling them. The preset application packages of Buildroot can be viewed in the `buildroot-2021.05/package` directory. + +Configuring to enable or disable an application package is implemented in the target board's configuration file. Taking the `milkv-duo` target as an example, its buildroot configuration file is: +``` +buildroot-2021.05/configs/milkv-duo_musl_riscv64_defconfig +``` + +We can compile the SDK as a whole on the host (such as Ubuntu), and then go to the Buildroot compilation directory to configure the relevant application packages through command line menu interaction. + +1. Enter the Buildroot compilation directory + + ``` + cd buildroot-2021.05/output/milkv-duo_musl_riscv64 + ``` + + You can use the `make show-targets` command to view the currently used application packages: + + ``` + $ make show-targets + busybox coreutils dhcpcd dnsmasq dropbear duo-pinmux e2fsprogs evtest expat fio freetype gdb host-acl host-attr host-autoconf host-automake host-e2fsprogs host-fakeroot host-genimage host-libtool host-libzlib host-m4 host-makedevs host-mkpasswd host-patchelf host-pkgconf host-skeleton host-util-linux host-xz host-zlib htop ifupdown-scripts initscripts iperf3 json-c kmod libevent libffi libnl libopenssl libxml2 libxslt libzlib musl-compat-headers ncurses ntp openssl python-cffi python-evdev python-freetype python-lxml python-modbus-tk python-pillow python-pinpong python-pip python-psutil python-pycparser python-serial python-setuptools python-smbus-cffi python-spidev python3 skeleton skeleton-init-common skeleton-init-sysv spidev_test strace stress-ng tar toolchain toolchain-external toolchain-external-custom urandom-scripts util-linux wpa_supplicant zlib rootfs-ext2 rootfs-tar + ``` + +2. Configure Buildroot + + Execute the `make menuconfig` command to bring up the interactive menu: + + + + Find the required application package according to the classification in `Target packages`. If you don't know the specific location of the application package, you can press the `/` key to search for the package name. For example, if you want to install the `tar` command, since searching for `tar` will bring up too many other irrelevant content, you can search for `package_tar`. And see that `=n` is currently disabled. Its location is in the `System tools` category of `Target packages`. You can double-click the `ESC` key to return to the main page. Then enter the corresponding position on the interface, or you can directly enter the position according to the number prompted earlier: + + + + Press the space bar to enable: + + + + Double-click the `ESC` key continuously to exit the main interface. When prompted whether to save, the default is YES. Just press Enter to save and exit: + + + + Execute the `make savedefconfig` command to save the modified configuration to the original configuration file. Use the `git status` command to confirm. You can see that the original configuration file has been modified: + + + + At this point, go back to the SDK root directory and recompile. + + :::tip + Here you can also compare the differences between the old configuration file and the new configuration file in the compilation directory, and manually modify the parts that need to be changed directly into the original configuration file `milkv-duo_musl_riscv64_defconfig`: + ```diff + diff -u .config.old .config + ``` + ::: + + After starting with the newly compiled image, test the newly added command on the Duo device. If a `not found` error occurs, it may be that the `.mk` configuration file of the package needs to be supplemented with gcc parameters, mainly `TARGET_CFLAGS` and The two parameters of `TARGET_LDFLAGS` need to be added. You can refer to the following commits: + + 1. [buildroot: enable fio](https://github.com/milkv-duo/duo-buildroot-sdk/commit/6ebbd6e219d3efcd9b95086c75702f4f717e7f03#diff-1a84d28825d604f941100ff9b50ec8d63bf84535a3dd6f7e62c421a657e6556a) + 2. [buildroot: enable spidev_test](https://github.com/milkv-duo/duo-buildroot-sdk/commit/84d6b72eb6c9ff467410376fc982b5ee4f8e3d1f#diff-d0fb4ce2e7555c5cc5399aeaa75e4bf5fd429f034f4d00457f450a994204b97f) + 3. [buildroot: fix build parameter for coremark package](https://github.com/milkv-duo/duo-buildroot-sdk/commit/cdd4fabb6100f87a61ca7560def558cd9e38f91a) + +### Add your own application package + +Compile and test your own application. The method of integrating it into the Buildroot project is not recommended. It is recommended to use method [duo-examples](https://github.com/milkv-duo/duo-examples). + +If you really need to compile your application in Buildroot package mode, you can refer to the configuration of the preset package in Buildroot to add it. Here are a few reference links: + +1. [buildroot: add python-evdev required by the pinpong library](https://github.com/milkv-duo/duo-buildroot-sdk/commit/11caee79c7a48f7f6fd4a5d352ccf8976857d522) +2. [buildroot: add python-freetype required by the pinpong library](https://github.com/milkv-duo/duo-buildroot-sdk/commit/165fc3c4c1adca1d1f635fd2069a5ad67d895c7c) + +Mainly refer to the content added in `buildroot-2021.05/package`. + +## 5. Delete application packages + +If you need to delete some unnecessary application packages to speed up compilation, or disable some unnecessary packages when compiling the firmware by yourself, you can use the `make menuconfig` method of opening the Buildroot application package mentioned above to disable related packages. + +You can also delete the corresponding package name in the Buildroot configuration file. Take the `milkv-duo` target as an example. For example, if you do not need to compile Python-related libraries, you can make the following modifications and recompile to generate firmware. + +```diff title="buildroot-2021.05/configs/milkv-duo_musl_riscv64_defconfig" +diff --git a/buildroot-2021.05/configs/milkv-duo_musl_riscv64_defconfig b/buildroot-2021.05/configs/milkv-duo_musl_riscv64_defconfig +index 2bc8cd5e3..e78901afb 100644 +--- a/buildroot-2021.05/configs/milkv-duo_musl_riscv64_defconfig ++++ b/buildroot-2021.05/configs/milkv-duo_musl_riscv64_defconfig +@@ -330,25 +330,6 @@ BR2_PACKAGE_EVTEST=y + # BR2_PACKAGE_FCONFIG is not set + BR2_PACKAGE_FLASHROM_ARCH_SUPPORTS=y + +-BR2_PACKAGE_PYTHON3=y +-BR2_PACKAGE_PYTHON3_PY_PYC=y +-BR2_PACKAGE_PYTHON_LXML=y +-BR2_PACKAGE_PYTHON_PIP=y +-BR2_PACKAGE_PYTHON_SETUPTOOLS=y +-BR2_PACKAGE_PYTHON3_SSL=y +- +-BR2_PACKAGE_PYTHON_SERIAL=y +-BR2_PACKAGE_PYTHON_PILLOW=y +-BR2_PACKAGE_PYTHON_SMBUS_CFFI=y +-BR2_PACKAGE_PYTHON_SPIDEV=y +-BR2_PACKAGE_PYTHON_MODBUS_TK=y +-BR2_PACKAGE_PYTHON_EVDEV=y +-BR2_PACKAGE_PYTHON_FREETYPE=y +- +-BR2_PACKAGE_PYTHON_PINPONG=y +- +-BR2_PACKAGE_PYTHON_PSUTIL=y +- + # + # Compression and decompression + # +``` + +## 6. Frequently Asked Questions + +### Buildroot troubleshooting method + +Buildroot in the SDK enables top-level parallel compilation by default to speed up compilation. However, when a compilation error occurs, it is inconvenient to analyze the error log, so we can delete it in the config file first, and then reopen it after the problem is solved. + +Taking the milkv-duo target as an example, delete the configuration in its configuration file and recompile: + +```bash title="buildroot-2021.05/configs/milkv-duo_musl_riscv64_defconfig" +BR2_PER_PACKAGE_DIRECTORIES=y +``` + +When a compilation error occurs, in addition to checking the error information of the compilation terminal, you can also check the complete log in `build/br.log` for troubleshooting. diff --git a/i18n/ja/docusaurus-plugin-content-docs/current/duo/getting-started/duo.md b/i18n/ja/docusaurus-plugin-content-docs/current/duo/getting-started/duo.md new file mode 100644 index 00000000..75978bbf --- /dev/null +++ b/i18n/ja/docusaurus-plugin-content-docs/current/duo/getting-started/duo.md @@ -0,0 +1,123 @@ +--- +sidebar_label: 'Duo(CV1800B)' +sidebar_position: 0 +--- + +# Duo + + + + Milk-V Duo is an ultra-compact embedded development platform based on the CV1800B chip. It can run Linux and RTOS, providing a reliable, low-cost, and high-performance platform for professionals, industrial ODMs, AIoT enthusiasts, DIY hobbyists, and creators. + +## Introduction of CV1800B + +CV1800B is a high-performance, low-power chip for residential consumer surveillance IP cameras, home intelligence and many other products, integrated with H.264/H.265 video compression encoder and ISP; supports digital broad dynamic, 3D noise reduction, defogging, lens distortion correction and other image enhancement and correction algorithms, providing customers with professional-grade video image quality. + +The chip integrates self-developed intelligent reference solutions (human detection, area detection, motion detection), built-in DDR and complete peripherals and peripherals, providing a highly integrated and simple solution to support customer product development and mass production. + +In addition, it also provides secure boot, secure update, secure encryption, etc., providing users with a series of security solutions from development, mass production, and product application with an 8-bit MCU subsystem integrated into the chip, which can replace the general external MCU to achieve the purpose of saving BOM cost and power consumption. + +## CV1800B Public Preliminary Datasheet + +We have open sourced the Public Preliminary Datasheet of CV1800B to GitHub. please [check it out](https://github.com/milkv-duo/duo-files/blob/main/duo/datasheet/CV1800B-CV1801B-Preliminary-Datasheet-full-en.pdf). + +## Buy the CV1800B Chips + +Milk-V is the Authorised Global Distributor of the CV1800B chips. You can buy samples of the CV1800B chip from our distributor [online store](https://arace.tech/products/sophon-cv1800b-5pcs) directly. For volume order, please contact [Milk-V Sales Team](mailto:sales@milkv.io) for the qoutation. + +## Duo GPIO Pinout + + + +### GPIO pin mapping + +
+ +| GROUP | ADDR | PORT | CHIP | NUM | NAME | START | +|:-----:|:-------------:|:-----:|:---------:|:-------:|:---------|:------------------| +| gpio0 | gpio@03020000 | porta | gpiochip0 | 480-511 | XGPIOA | 480 - XGPIOA[0] | +| gpio1 | gpio@03021000 | portb | gpiochip1 | 448-479 | XGPIOB | 448 - XGPIOB[0] | +| gpio2 | gpio@03022000 | portc | gpiochip2 | 416-447 | XGPIOC | 416 - XGPIOC[0] | +| gpio3 | gpio@03023000 | portd | gpiochip3 | 384-415 | | | +| gpio4 | gpio@05021000 | porte | gpiochip4 | 352-383 | PWR_GPIO | 352 - PWR_GPIO[0] | + +
+ +### GPIO Pinout + +
+ +| JTAG | SPI | SPI NOR | SD | PWM | I2C | UART | NUM | CV1800B | NAME | PIN | PIN | NAME | CV1800B | NUM | ADC | SPI NOR | SPI NAND | +|:---------|:----------|:---------------|:--------|:------|:---------|:-----------|:---:|:-------------|-----:|:-------------------------------:|:--------------------------------:|:---------|:------------|:---:|:-----------|:--------------|:-------------| +| JTAG_TDI | | | | | I2C0_SCL | UART1/2_TX | 508 | XGPIOA[28] | GP0 |
1
|
40
| VBUS(5V) | | | | | | +| JTAG_TDO | | | | | I2C0_SDA | UART1/2_RX | 509 | XGPIOA[29] | GP1 |
2
|
39
| VSYS(5V) | | | | | | +| | | | | | | | | | GND |
3
|
38
| GND | | | | | | +| | | | SD1_GP1 | PWM10 | | UART4_TX | 378 | PWR_GPIO[26] | GP2 |
4
|
37
| 3V3_EN | | | | | | +| | | | SD1_GP0 | PWM11 | | UART4_RX | 377 | PWR_GPIO[25] | GP3 |
5
|
36
| 3V3(OUT) | | | | | | +| | | SPINOR1_HOLD_X | SD1_D2 | PWM5 | I2C1_SCL | UART2/3_TX | 371 | PWR_GPIO[19] | GP4 |
6
|
35
| | | | | | | +| | | SPINOR1_WP_X | SD1_D1 | PWM6 | I2C1_SDA | UART2/3_RX | 372 | PWR_GPIO[20] | GP5 |
7
|
34
| | | | | | | +| | | | | | | | | | GND |
8
|
33
| GND | | | | | | +| | SPI2_SCK | SPINOR1_SCK | SD1_CLK | PWM9 | I2C3_SDA | | 375 | PWR_GPIO[23] | GP6 |
9
|
32
| GP27 | XGPIOB[6] | 454 | ADC2(1.8V) | | | +| | SPI2_SDO | SPINOR1_MOSI | SD1_CMD | PWM8 | I2C3_SCL | | 374 | PWR_GPIO[22] | GP7 |
10
|
31
| GP26 | XGPIOB[3] | 451 | ADC1(1.8V) | | | +| | SPI2_SDI | SPINOR1_MISO | SD1_D0 | PMW7 | I2C1_SDA | UART3_RTS | 373 | PWR_GPIO[21] | GP8 |
11
|
30
| RUN | | | | | | +| | SPI2_CS_X | SPINOR1_CS_X | SD1_D3 | PWM4 | I2C1_SCL | UART3_CTS | 370 | PWR_GPIO[18] | GP9 |
12
|
29
| GP22 | PWR_GPIO[4] | 356 | | | | +| | | | | | | | | | GND |
13
|
28
| GND | | | | | | +| | | | | | I2C1_SDA | | 425 | XGPIOC[9] | GP10 |
14
|
27
| GP21 | XGPIOA[26] | 506 | | SPINOR_HOLD_X | SPINAND_HOLD | +| | | | | | I2C1_SCL | | 426 | XGPIOC[10] | GP11 |
15
|
26
| GP20 | XGPIOA[27] | 507 | | SPINOR_WP_X | SPINAND_WP | +| JTAG_TMS | | | | PWM4 | | UART0/1_TX | 496 | XGPIOA[16] | GP12 |
16
|
25
| GP19 | XGPIOA[25] | 505 | | SPINOR_MOSI | SPINAND_MOSI | +| JTAG_TCK | | | | PWM5 | | UART0/1_RX | 497 | XGPIOA[17] | GP13 |
17
|
24
| GP18 | XGPIOA[22] | 502 | | SPINOR_SCK | SPINAND_SCK | +| | | | | | | | | | GND |
18
|
23
| GND | | | | | | +| | | | | | | | 494 | XGPIOA[14] | GP14 |
19
|
22
| GP17 | XGPIOA[24] | 504 | | SPINOR_CS_X | SPINAND_CS | +| | | | | | | | 495 | XGPIOA[15] | GP15 |
20
|
21
| GP16 | XGPIOA[23] | 503 | | SPINOR_MISO | SPINAND_MISO | +| | | | | | | | | | |   | | | | | | | | +| | | | | | | | 440 | XGPIOC[24] | |
LED
| | | | | | | | + +
+ +### Camera interface + +Duo camera uses a 16-pin connector with a distance of 0.5 mm, which can be directly used with the [CAM-GC2083](https://milkv.io/docs/duo/camera/gc2083) camera head. + +#### Connector FPC Definition + + + +
+ +| J1 | Description | +|:--:|:--------------------| +| 1 | GND | +| 2 | MIPI0_DN0 | +| 3 | MIPI0_DP0 | +| 4 | GND | +| 5 | MIPI0_DN1 | +| 6 | MIPI0_DP1 | +| 7 | GND | +| 8 | MIPI0_CKN | +| 9 | MIPI0_CKP | +| 10 | GND | +| 11 | SENSOR_RSTN (1.8V) | +| 12 | SENSOR_CLK (1.8V) | +| 13 | I2C1_SCL (1.8V) | +| 14 | I2C1_SDA (1.8V) | +| 15 | | +| 16 | 3V3 | + +
+ +## Hardware Docs + +### V1.2 + +- Schematic: [duo-schematic-v1.2.pdf](https://github.com/milkv-duo/duo-files/blob/main/duo/hardware/duo-schematic-v1.2.pdf?raw=true) +- SMD TOP: [duo-component-list-top-v1.2.pdf](https://github.com/milkv-duo/duo-files/blob/main/duo/hardware/duo-component-list-top-v1.2.pdf?raw=true) +- SMD BOTTOM: [duo-component-list-bottom-v1.2.pdf](https://github.com/milkv-duo/duo-files/blob/main/duo/hardware/duo-component-list-bottom-v1.2.pdf?raw=true) +- 2D dxf: [duo-mechanical-drawings-v1.1.zip](https://github.com/milkv-duo/duo-files/blob/main/duo/hardware/duo-mechanical-drawings-v1.1.zip?raw=true) + +### V1.1 + +- Schematic: [duo-schematic-v1.1.pdf](https://github.com/milkv-duo/duo-files/blob/main/duo/hardware/duo-schematic-v1.1.pdf?raw=true) + +### Others + +[https://github.com/milkv-duo/duo-files/tree/main/duo/hardware](https://github.com/milkv-duo/duo-files/tree/main/duo/hardware) diff --git a/i18n/ja/docusaurus-plugin-content-docs/current/duo/getting-started/duo256m.md b/i18n/ja/docusaurus-plugin-content-docs/current/duo/getting-started/duo256m.md new file mode 100644 index 00000000..0bb3203e --- /dev/null +++ b/i18n/ja/docusaurus-plugin-content-docs/current/duo/getting-started/duo256m.md @@ -0,0 +1,133 @@ +--- +sidebar_label: 'Duo256M(SG2002)' +sidebar_position: 1 +--- + +# Duo256M + + + +The Milk-V Duo 256M is an upgraded version of Duo with a memory boost to 256M, catering to applications demanding larger memory capacities. It features the SG2002 computing series chip, elevating computational power to 1.0TOPS@INT8. It enables seamless switching between RISC-V/ARM architectures and supports simultaneous operation of dual systems. Additionally, it includes an array of rich GPIO interfaces such as SPI, UART, suitable for a wide range of hardware development in edge intelligent monitoring, including IP cameras, smart peephole locks, visual doorbells, and more. + +## Introduction of SG2002 + +SG2002 is a high-performance, low-power chip designed for various product fields such as edge intelligent surveillance IP cameras, smart door locks, visual doorbells, and home intelligence. It integrates H.264 video compression and decoding, H.265 video compression encoding, and ISP capabilities. It supports multiple image enhancement and correction algorithms such as HDR wide dynamic range, 3D noise reduction, defogging, and lens distortion correction, providing customers with professional-grade video image quality. + +The chip also incorporates a self-developed TPU, delivering 1.0 TOPS of computing power under 8-bit integer operations. The specially designed TPU scheduling engine efficiently provides high-bandwidth data flow for all tensor processing unit cores. Additionally, it offers users a powerful deep learning model compiler and software SDK development kit. Leading deep learning frameworks like Caffe and Tensorflow can be easily ported to its platform. Furthermore, it includes security boot, secure updates, and encryption, providing a series of security solutions from development, mass production, to product applications. + +The chip integrates an 8-bit MCU subsystem, replacing the typical external MCU to achieve cost-saving and power efficiency goals. + +## SG2002 Public Preliminary Datasheet + +We have open sourced the Public Preliminary Datasheet and TRM of SG2002 to GitHub. please [check it out](https://github.com/milkv-duo/duo-files/tree/main/duo-256M/datasheet). + +## Buy the SG2002 Chips + +Milk-V is the Authorised Global Distributor of the SG2002 chips. You can buy samples of the SG2002 chip from our distributor [online store](https://arace.tech/products/sophon-cv1800b-5pcs) directly. For volume order, please contact [Milk-V Sales Team](mailto:sales@milkv.io) for the qoutation. + +## Duo256M GPIO Pinout + + + +### GPIO pin mapping + +
+ +| GROUP | ADDR | PORT | CHIP | NUM | NAME | START | +|:-----:|:-------------:|:-----:|:---------:|:-------:|:---------|:------------------| +| gpio0 | gpio@03020000 | porta | gpiochip0 | 480-511 | XGPIOA | 480 - XGPIOA[0] | +| gpio1 | gpio@03021000 | portb | gpiochip1 | 448-479 | XGPIOB | 448 - XGPIOB[0] | +| gpio2 | gpio@03022000 | portc | gpiochip2 | 416-447 | XGPIOC | 416 - XGPIOC[0] | +| gpio3 | gpio@03023000 | portd | gpiochip3 | 384-415 | | | +| gpio4 | gpio@05021000 | porte | gpiochip4 | 352-383 | PWR_GPIO | 352 - PWR_GPIO[0] | + +
+ +### GPIO Pinout + +
+ +| JTAG | SPI | SPI-NOR | SD | PWM | I2C | UART | NUM | SG2002 | NAME | PIN | PIN | NAME | SG2002 | NUM | ADC | SPI-NOR | SPI-NAND | EMMC | +|:---------|:---------|:----------|:--------|:------|:---------|:-----------|:---:|:-------------|-----:|:-------------------------------:|:--------------------------------:|:------------|:------------|:---:|:-----------|:---------|:----------|:----------| +| JTAG_TDI | | | | | | UART1/2_TX | 508 | XGPIOA[28] | GP0 |
1
|
40
| VBUS(5V) | | | | | | | +| JTAG_TDO | | | | | | UART1/2_RX | 509 | XGPIOA[29] | GP1 |
2
|
39
| VSYS(5V) | | | | | | | +| | | | | | | | | | GND |
3
|
38
| GND | | | | | | | +| JTAG_TMS | | | | PWM7 | | UART1_TX | 499 | XGPIOA[19] | GP2 |
4
|
37
| 3V3_EN | | | | | | | +| JTAG_TCK | | | | PWM6 | | UART1_RX | 498 | XGPIOA[18] | GP3 |
5
|
36
| 3V3(OUT) | | | | | | | +| | | NOR1_HOLD | SD1_D2 | PWM5 | I2C1_SCL | UART2/3_TX | 371 | PWR_GPIO[19] | GP4 |
6
|
35
| Boot-Switch | | | | | | | +| | | NOR1_WP | SD1_D1 | PWM6 | I2C1_SDA | UART2/3_RX | 372 | PWR_GPIO[20] | GP5 |
7
|
34
| Audio-Out | | | | | | | +| | | | | | | | | | GND |
8
|
33
| GND | | | | | | | +| | SPI2_SCK | NOR1_SCK | SD1_CLK | PWM9 | I2C3_SDA | | 375 | PWR_GPIO[23] | GP6 |
9
|
32
| GP27 | XGPIOB[6] | 454 | | | | | +| | SPI2_SDO | NOR1_MOSI | SD1_CMD | PWM8 | I2C3_SCL | | 374 | PWR_GPIO[22] | GP7 |
10
|
31
| GP26 | XGPIOB[3] | 451 | ADC1(1.8V) | | | | +| | SPI2_SDI | NOR1_MISO | SD1_D0 | PMW7 | I2C1_SDA | UART3_RTS | 373 | PWR_GPIO[21] | GP8 |
11
|
30
| RUN | | | | | | | +| | SPI2_CS | NOR1_CS | SD1_D3 | PWM4 | I2C1_SCL | UART3_CTS | 370 | PWR_GPIO[18] | GP9 |
12
|
29
| GP22 | PWR_GPIO[4] | 356 | | | | | +| | | | | | | | | | GND |
13
|
28
| GND | | | | | | | +| | | | | PWM10 | I2C2_SDA | | 430 | XGPIOC[14] | GP10 |
14
|
27
| GP21 | XGPIOA[26] | 506 | | NOR_HOLD | NAND_HOLD | EMMC_DAT2 | +| | | | | PWM11 | I2C2_SCL | | 431 | XGPIOC[15] | GP11 |
15
|
26
| GP20 | XGPIOA[27] | 507 | | NOR_WP | NAND_WP | EMMC_DAT3 | +| | | | | PWM4 | | UART0/1_TX | 496 | XGPIOA[16] | GP12 |
16
|
25
| GP19 | XGPIOA[25] | 505 | | NOR_MOSI | NAND_MOSI | EMMC_DAT0 | +| | | | | PWM5 | | UART0/1_RX | 497 | XGPIOA[17] | GP13 |
17
|
24
| GP18 | XGPIOA[22] | 502 | | NOR_SCK | NAND_SCK | EMMC_CLK | +| | | | | | | | | | GND |
18
|
23
| GND | | | | | | | +| | | | | | | | 494 | XGPIOA[14] | GP14 |
19
|
22
| GP17 | XGPIOA[24] | 504 | | NOR_CS | NAND_CS | EMMC_DAT1 | +| | | | | | | | 495 | XGPIOA[15] | GP15 |
20
|
21
| GP16 | XGPIOA[23] | 503 | | NOR_MISO | NAND_MISO | EMMC_CMD | +| | | | | | | | | | |   | | | | | | | | | +| | | | | | | | 354 | PWR_GPIO[2] | |
LED
| | | | | | | | | + +
+ +The logic level of `GP26` and `GP27` pins is 1.8V, and the logic level of other GPIO pins is 3.3V logic level. + +### Camera interface + +Duo256M camera uses a 16-pin connector with a distance of 0.5 mm, which can be directly used with the [CAM-GC2083](https://milkv.io/docs/duo/camera/gc2083) camera head. + +#### Connector FPC Definition + + + +
+ +| J1 | Description | +|:--:|:--------------------| +| 1 | GND | +| 2 | MIPI0_DN0 | +| 3 | MIPI0_DP0 | +| 4 | GND | +| 5 | MIPI0_DN1 | +| 6 | MIPI0_DP1 | +| 7 | GND | +| 8 | MIPI0_CKN | +| 9 | MIPI0_CKP | +| 10 | GND | +| 11 | SENSOR_RSTN (1.8V) | +| 12 | SENSOR_CLK (1.8V) | +| 13 | I2C2_SCL (1.8V) | +| 14 | I2C2_SDA (1.8V) | +| 15 | | +| 16 | 3V3 | + +
+ +## Duo256M User Guide + +### RISC-V and ARM switching + +The large core of Duo256M can choose to use RISC-V or ARM processor. The RISC-V core is used by default. You can switch to the ARM core by shorting physical pin 35 (Boot-Switch) and GND. If you find that Duo256M cannot start normally during use, please first check whether the core currently used is consistent with the firmware used. + + + +If the debug serial port is connected, you can see in the first line of the boot log that starting with `C` means starting from the RISC-V core, and starting with `B` means starting from the ARM core. + +- RISC-V: + ``` + C.SCS/0/0.C.SCS/0/0.WD.URPL.USBI.USBW + ``` +- ARM: + ``` + B.SCS/0/0.WD.URPL.B.SCS/0/0.WD.URPL.USBI.USBW + ``` + +## Hardware Docs + +### Others + +[https://github.com/milkv-duo/duo-files/tree/main/duo-256M](https://github.com/milkv-duo/duo-files/tree/main/duo-256M) diff --git a/i18n/ja/docusaurus-plugin-content-docs/current/duo/getting-started/duos.md b/i18n/ja/docusaurus-plugin-content-docs/current/duo/getting-started/duos.md new file mode 100644 index 00000000..2697b553 --- /dev/null +++ b/i18n/ja/docusaurus-plugin-content-docs/current/duo/getting-started/duos.md @@ -0,0 +1,380 @@ +--- +sidebar_label: 'Duo S(SG2000)' +sidebar_position: 3 +--- + +# Duo S + + + +Milk-V Duo S is an upgraded model of Duo, featuring an upgraded SG2000 main controller with a larger 512MB memory and expanded IO capabilities. It integrates wireless capabilities with WI-FI 6/BT 5, and comes equipped with a USB 2.0 HOST interface and a 100Mbps Ethernet port for user convenience. Supporting dual cameras (2x MIPI CSI 2-lane) and MIPI video output (MIPI DSI 4-lane), it allows for versatile applications. The device also supports switching between RISC-V and ARM boot through a switch. With enhanced functionality, Duo S is better suited for a variety of scenarios with more complex project development requirements. + +## Introduction of SG2000 + +SG2000 is a high-performance, low-power chip designed for various product fields such as edge intelligent surveillance IP cameras, local facial recognition attendance machines, and smart home devices. It integrates H.264/H.265 video compression and decoding and ISP capabilities. It supports various image enhancement and correction algorithms like HDR wide dynamic range, 3D noise reduction, defogging, and lens distortion correction, providing customers with professional-grade video image quality. + +The chip also integrates an in-house TPU, delivering approximately 0.5TOPS of computing power under INT8 operations. The specially designed TPU scheduling engine efficiently provides high-bandwidth data flow for tensor processing unit cores. It also offers users a powerful deep learning model compiler and software SDK development kit. Mainstream deep learning frameworks such as Caffe, Pytorch, ONNX, MXNet, and TensorFlow (Lite) can be easily ported to this platform. + +## SG2000 Public Preliminary Datasheet + +We have open sourced the Public Preliminary Datasheet and TRM of SG2000 to GitHub. please [check it out](https://github.com/milkv-duo/duo-files/tree/main/duo-s/datasheet). + +## Buy the SG2000 Chips + +Milk-V is the Authorised Global Distributor of the SG2002 chips. You can buy samples of the SG2002 chip from our distributor [online store](https://arace.tech/products/sophon-cv1800b-5pcs) directly. For volume order, please contact [Milk-V Sales Team](mailto:sales@milkv.io) for the qoutation. + +## DuoS GPIO Pinout + + + +### GPIO pin mapping + +
+ +| GROUP | ADDR | PORT | CHIP | NUM | NAME | START | +|:-----:|:-------------:|:-----:|:---------:|:-------:|:---------|:------------------| +| gpio0 | gpio@03020000 | porta | gpiochip0 | 480-511 | XGPIOA | 480 - XGPIOA[0] | +| gpio1 | gpio@03021000 | portb | gpiochip1 | 448-479 | XGPIOB | 448 - XGPIOB[0] | +| gpio2 | gpio@03022000 | portc | gpiochip2 | 416-447 | XGPIOC | 416 - XGPIOC[0] | +| gpio3 | gpio@03023000 | portd | gpiochip3 | 384-415 | | | +| gpio4 | gpio@05021000 | porte | gpiochip4 | 352-383 | PWR_GPIO | 352 - PWR_GPIO[0] | + +
+ +### Header J3 + +GPIO on `Header J3` use 3.3V logic levels. + +
+ +| SPI | PWM | I2C | UART | NUM | SG2000 | NAME | PIN | PIN | NAME | SG2000 | NUM | UART | PWM | SPI | JTAG | +|:---------|:-----|:---------|:---------|:---:|:-----------|------:|:--------------------------------:|:-------------------------------:|:---------|:-----------|:---:|:-------------------|:-----|:--------|:----------| +| | | | | | | 3V3 |
1
|
2
| VSYS(5V) | | | | | | | +| | PWM3 | I2C4_SCL | | 468 | XGPIOB[20] | B20 |
3
|
4
| VSYS(5V) | | | | | | | +| | | I2C4_SDA | | 469 | XGPIOB[21] | B21 |
5
|
6
| GND | | | | | | | +| | | I2C1_SCL | | 466 | XGPIOB[18] | B18 |
7
|
8
| A16 | XGPIOA[16] | 496 | UART0_TX/UART1_TX | PWM4 | | | +| | | | | | | GND\* |
9
|
10
| A17 | XGPIOA[17] | 497 | UART0_RX/UART1_RX | PWM5 | | | +| | PWM1 | I2C1_SDA | UART2_TX | 459 | XGPIOB[11] | B11 |
11
|
12
| B19 | XGPIOB[19] | 467 | UART2_TX | PWM2 | | | +| | PWM2 | I2C1_SCL | UART2_RX | 460 | XGPIOB[12] | B12 |
13
|
14
| GND | | | | | | | +| | | | UART2_RX | 470 | XGPIOB[22] | B22 |
15
|
16
| A20 | XGPIOA[20] | 500 | | | | JTAG_TRST | +| | | | | | | 3V3 |
17
|
18
| A19 | XGPIOA[19] | 499 | UART1_TX/UART1_RTS | PWM7 | | JTAG_TMS | +| SPI3_SDO | PWM3 | I2C2_SCL | | 461 | XGPIOB[13] | B13 |
19
|
20
| GND | | | | | | | +| SPI3_SDI | | I2C2_SDA | | 462 | XGPIOB[14] | B14 |
21
|
22
| A18 | XGPIOA[18] | 498 | UART1_RX/UART1_CTS | PWM6 | | JTAG_TCK | +| SPI3_SCK | | | UART2_TX | 463 | XGPIOB[15] | B15 |
23
|
24
| B16 | XGPIOB[16] | 464 | UART2_RX | | SPI3_CS | | +| | | | | | | GND |
25
|
26
| A28 | XGPIOA[28] | 508 | UART2_TX/UART1_TX | | | | + +
+ +*GND\*: Pin 9 is a low-level GPIO in the V1.1 version of the hardware, and is GND in the V1.2 version and later.* + +NOTE: The I2C on the CSI camera connector J2 is I2C2, so when using the CSI camera on J2, I2C2 in the J3 pin header is not available. + +### Header J4 + +GPIO on `Header J4` use 1.8V logic levels. + +
+ +| PWM | I2C | UART | MIPI DSI | NUM | SG2000 | NAME | PIN | PIN | NAME | SG2000 | NUM | MIPI DSI | +|:------|:---------|:---------|:-----------|:---:|:------------|---------:|:-------------------------------:|:--------------------------------:|:------------|:-----------|:---:|:-----------| +| | | | | | | VSYS(5V) |
52
|
51
| AUDIO_OUT_R | | | | +| PWM12 | I2C4_SCL | UART3_TX | | 499 | XGPIOB[1] | B1 |
50
|
49
| AUDIO_OUT_L | | | | +| PWM13 | I2C4_SDA | UART3_RX | | 450 | XGPIOB[2] | B2 |
48
|
47
| AUDIO_IN_R | | | | +| | | | | 451 | XGPIOB[3] | B3 |
46
|
45
| AUDIO_IN_L | | | | +| PWM10 | I2C2_SDA | | LCD_RST | 354 | PWR_GPIO[2] | E2 |
44
|
43
| 3V3 | | | | +| PWM9 | I2C2_SCL | UART2_RX | LCD_PWR_CT | 353 | PWR_GPIO[1] | E1 |
42
|
41
| C18 | XGPIOC[18] | 434 | MIPI_TX_3N | +| PWM8 | | UART2_TX | LCD_PWM | 352 | PWR_GPIO[0] | E0 |
40
|
39
| C19 | XGPIOC[19] | 435 | MIPI_TX_3P | +| | | | | | | GND |
38
|
37
| GND | | | | +| | | | MIPI_TX_2N | 436 | XGPIOC[20] | C20 |
36
|
35
| C16 | XGPIOC[16] | 432 | MIPI_TX_CN | +| | | | MIPI_TX_2P | 437 | XGPIOC[21] | C21 |
34
|
33
| C17 | XGPIOC[17] | 433 | MIPI_TX_CP | +| | | | | | | GND |
32
|
31
| GND | | | | +| | | | MIPI_TX_1N | 430 | XGPIOC[14] | C14 |
30
|
29
| C12 | XGPIOC[12] | 428 | MIPI_TX_0N | +| | | | MIPI_TX_1P | 431 | XGPIOC[15] | C15 |
28
|
27
| C13 | XGPIOC[13] | 429 | MIPI_TX_0P | + +
+ +### Blue LED PIN + +
+ +| NAME | SG2000 | NUM | +|:-------------------------------:|:----------:|:---:| +|
LED
| XGPIOA[29] | 509 | + +
+ +### Camera interface + +DuoS has two CSI camera connectors: + +- J1 is a 16 PIN 0.5mm pitch connector compatible with Duo and Duo256M cameras, and can directly use the [CAM-GC2083](https://milkv.io/docs/duo/camera/gc2083) camera. +- J2 is a 15-pin 1.0mm pitch connector compatible with the Raspberry Pi camera interface. It currently supports the OV5647 camera used on the Raspberry Pi. + + + +Note that the I2C used by the J1 interface is I2C3, and the I2C used by the J2 interface is I2C2. Please check the pin multiplexing configuration when using it. + +#### J1 Connector FPC Definition + +
+ +| J1 | Description | +|:--:|:--------------------| +| 1 | GND | +| 2 | MIPI0_DN0 | +| 3 | MIPI0_DP0 | +| 4 | GND | +| 5 | MIPI0_DN1 | +| 6 | MIPI0_DP1 | +| 7 | GND | +| 8 | MIPI0_CKN | +| 9 | MIPI0_CKP | +| 10 | GND | +| 11 | SENSOR_RSTN0 (1.8V) | +| 12 | SENSOR_CLK0 (1.8V) | +| 13 | I2C3_SCL (1.8V) | +| 14 | I2C3_SDA (1.8V) | +| 15 | | +| 16 | 3V3 | + +
+ +#### J2 Connector FPC Definition + +
+ +| J2 | Description | +|:--:|:---------------------| +| 1 | 3V3 | +| 2 | I2C2_SDA (3.3V) | +| 3 | I2C2_SCL (3.3V) | +| 4 | SENSOR_CLK1 (3.3V) | +| 5 | SENSOR_RSTN1 (3.3V) | +| 6 | GND | +| 7 | MIPI0_DP5 (CAM1_CP) | +| 8 | MIPI0_DN5 (CAM1_CN) | +| 9 | GND | +| 10 | MIPI0_DP4 (CAM1_DP1) | +| 11 | MIPI0_DN4 (CAM1_DN1) | +| 12 | GND | +| 13 | MIPI0_DP3 (CAM1_DP0) | +| 14 | MIPI0_DN3 (CAM1_DN0) | +| 15 | GND | + +
+ +### POE Header + + + +
+ +| POE Pin | Description | +|:-------:|:-----------:| +| 1 | VB- | +| 2 | VB+ | +| 3 | VA- | +| 4 | VA+ | + +
+ +## DuoS User Guide + +### RISC-V and ARM switching + +The large core of DuoS can choose to use RISC-V or ARM processor, which can be set through the switch on the board. If you find that DuoS cannot start normally during use, please first check whether the switch is consistent with the firmware used. + + + +If the debug serial port is connected, you can see in the first line of the boot log that starting with `C` means starting from the RISC-V core, and starting with `B` means starting from the ARM core. + +- RISC-V: + ``` + C.SCS/0/0.C.SCS/0/0.WD.URPL.USBI.USBW + ``` +- ARM: + ``` + B.SCS/0/0.WD.URPL.B.SCS/0/0.WD.URPL.USBI.USBW + ``` + +### Usage of USB Type A interface + +The USB functions of the DuoS USB Type A interface and Type C interface are optional and cannot be used at the same time. The default firmware is configured with the USB network port (RNDIS) function of the Type C port. If you need to switch to the USB 2.0 HOST port of the Type A port for use with USB flash drives and other devices, you need to execute the following command: + +~~~ +ln -sf /mnt/system/usb-host.sh /mnt/system/usb.sh +sync +~~~ +Then execute the `reboot` command or power on again to make it take effect. + +For example, after connecting a USB flash drive to the USB A port, you can use `ls /dev/sd*` to check whether the device is detected. + +Mount it to the system to view the contents of the USB flash drive (take /dev/sda1 as an example): +``` +mkdir /mnt/udisk +mount /dev/sda1 /mnt/udisk +``` +Check whether the contents of the `/mnt/udisk` directory are as expected: +``` +ls /mnt/udisk +``` + +Command to uninstall USB flash drive: +``` +umount /mnt/udisk +``` + +When you want to restore the USB network (RNDIS) function of the Type C port, execute: +~~~ +rm /mnt/system/usb.sh +ln -sf /mnt/system/usb-rndis.sh /mnt/system/usb.sh +sync +~~~ +Then execute the `reboot` command or power on again to make it take effect. + +:::tip +DuoS has an onboard Ethernet interface, so the USB network port (RNDIS) of the Type C port can be used without switching to the USB 2.0 Host function of the A port. +::: + +### UART Serial Console + +Connect USB to TTL serial cable as shown below. Do not connect the red wire. + +| Milk-V DouS | \<---> | USB to TTL | +| ----------- | ------ | ---------- | +| GND (pin 6) | \<---> | Black wire | +| TX (pin 8) | \<---> | White wire | +| RX (pin 10) | \<---> | Green wire | + + + +The default serial setting for Duo u-boot and kernel console is: + +``` +baudrate: 115200 +data bit: 8 +stop bit: 1 +parity : none +flow control: none +``` + +### WIFI configuration + +#### Method 1 + +Edit the following file and replace `ssid` and `psk` with the WIFI account and password to be connected: + +```python {6,7} title="/etc/wpa_supplicant.conf" +ctrl_interface=/var/run/wpa_supplicant +ap_scan=1 +update_config=1 + +network={ + ssid="wifi_test" + psk="12345678" + key_mgmt=WPA-PSK +} +``` + +Then execute the following command: + +```bash +wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.conf +``` +You can connect to WIFI. After connecting, you can view the assigned IP address through the `ifconfig` or `ip a` command. + +:::tip +If you need to automatically connect to the network at boot, you can put this command in the `/mnt/system/auto.sh` file. +::: + +### eMMC version firmware burning + +The DuoS eMMC version does not have firmware burned and needs to be burned using a PC through the USB interface. + +:::tip +Use the USB burning tool under Windows to support eMMC. The firmware version is [V1.1.0](https://github.com/milkv-duo/duo-buildroot-sdk/releases/tag/Duo-V1.1.0) or [latest version](https://github.com/milkv-duo/duo-buildroot-sdk/releases). +::: + +#### Burning in Windows + +1. Install driver + + Download the USB driver installation tool: [CviUsbDownloadInstallDriver.zip](https://github.com/milkv-duo/duo-buildroot-sdk/releases/download/Duo-V1.1.0/CviUsbDownloadInstallDriver.zip). After downloading, unzip and install. + +2. Download burning tool + + Download the command line burning tool under Windows [CviBurn_v2.0_cli_windows.zip](https://github.com/milkv-duo/duo-buildroot-sdk/releases/download/Duo-V1.1.0/CviBurn_v2.0_cli_windows.zip), unzip it after downloading. + +3. Download firmware + + Download the latest version of DuoS eMMC firmware, currently [milkv-duos-emmc-v1.1.0-2024-0410.zip](https://github.com/milkv-duo/duo-buildroot-sdk/releases/download/Duo-V1.1.0/milkv-duos-emmc-v1.1.0-2024-0410.zip), you can create a new rom folder in the burning tool `CviBurn_v2.0_cli_windows` directory, and extract the downloaded eMMC firmware compressed package to rom directory, the directory structure of the burning tool is as follows: + + ``` + └───CviBurn_v2.0_cli_windows + │ cv_dl_magic.bin + │ usb_dl.exe + └───rom + │ boot.emmc + │ fip.bin + │ partition_emmc.xml + │ rootfs_ext4.emmc + | ... + ``` + + In the Windows terminal, execute the burning command in the `CviBurn_v2.0_cli_windows` directory: + + ``` + .\usb_dl.exe -s linux -c cv181x -i .\rom + ``` + + *You can also put the firmware in other directories and specify the corresponding directory through the -i parameter in the command. * + + Displays message waiting for USB connection: + + + + Use **Type-C data cable** to connect DuoS and PC (note, if DuoS currently has an SD card inserted, please remove the SD card first), DuoS will automatically power on and enter the burning mode, and the PC will display the burning status in real time. Recording progress: + + ``` + [INFO] Waiting for USB device connection: --- + [INFO] found usb device vid=0x3346 pid=0x1000 + [INFO] downloading file: .\rom\boot.emmc + [INFO] CVI_USB_PROGRAM + [INFO] updated size: 3384664/213100824(1%) + [INFO] downloading file: .\rom\rootfs_ext4.emmc + [INFO] CVI_USB_PROGRAM + [INFO] updated size: 20161944/213100824(9%) + [INFO] CVI_USB_PROGRAM + [INFO] updated size: 36939224/213100824(17%) + [INFO] CVI_USB_PROGRAM + [INFO] updated size: 53716504/213100824(25%) + [INFO] CVI_USB_PROGRAM + [INFO] updated size: 70493784/213100824(33%) + [INFO] CVI_USB_PROGRAM + [INFO] updated size: 87271064/213100824(40%) + [INFO] CVI_USB_PROGRAM + [INFO] updated size: 104048344/213100824(48%) + [INFO] CVI_USB_PROGRAM + [INFO] updated size: 120825624/213100824(56%) + [INFO] CVI_USB_PROGRAM + [INFO] updated size: 137602904/213100824(64%) + [INFO] CVI_USB_PROGRAM + [INFO] updated size: 154380184/213100824(72%) + [INFO] CVI_USB_PROGRAM + [INFO] updated size: 171157464/213100824(80%) + [INFO] CVI_USB_PROGRAM + [INFO] updated size: 187934744/213100824(88%) + [INFO] CVI_USB_PROGRAM + [INFO] updated size: 204712024/213100824(96%) + [INFO] CVI_USB_PROGRAM + [INFO] updated size: 213100696/213100824(99%) + [INFO] USB download complete + ``` + + After the burning is completed, the DuoS will automatically restart. After booting, you will see the blue LED on the DuoS flashing, indicating that the system has started normally and the burning is successful. + +## Hardware Docs + +### Others + +[https://github.com/milkv-duo/duo-files/tree/main/duo-s](https://github.com/milkv-duo/duo-files/tree/main/duo-s) diff --git a/i18n/ja/docusaurus-plugin-content-docs/current/duo/getting-started/rtoscore.md b/i18n/ja/docusaurus-plugin-content-docs/current/duo/getting-started/rtoscore.md new file mode 100644 index 00000000..c96e0663 --- /dev/null +++ b/i18n/ja/docusaurus-plugin-content-docs/current/duo/getting-started/rtoscore.md @@ -0,0 +1,203 @@ +--- +sidebar_label: 'RTOS Core' +sidebar_position: 50 +--- + +# Introduction + +Duo's CPU adopts a dual-core design. The big core runs the Linux system, and the small core runs the real-time system. Currently, it is FreeRTOS. + +# How to use the small core + +## Inter-core communication example + +The communication between the Duo big core and the small core is realized through the mailbox module. The latest image has added the mailbox driver to the Linux kernel of the big core. Related functions are also implemented in the FreeRTOS code of the small core. Please use [V1.0.9]( https://github.com/milkv-duo/duo-buildroot-sdk/releases/tag/Duo-V1.0.9) or [latest image](https://github.com/milkv-duo/duo-buildroot-sdk/releases) test. + +### Big core controls small core to light up LED + +This example is a Linux application running on the big core, which use the mailbox driver in the Linux kernel to notify the small core FreeRTOS to control the blue LED on Duo. The LED is first light up, and after 3 seconds, it is turned off. + +```c +#include +#include +#include +#include +#include +#include +#include + +enum SYSTEM_CMD_TYPE { + CMDQU_SEND = 1, + CMDQU_SEND_WAIT, + CMDQU_SEND_WAKEUP, +}; + +#define RTOS_CMDQU_DEV_NAME "/dev/cvi-rtos-cmdqu" +#define RTOS_CMDQU_SEND _IOW('r', CMDQU_SEND, unsigned long) +#define RTOS_CMDQU_SEND_WAIT _IOW('r', CMDQU_SEND_WAIT, unsigned long) +#define RTOS_CMDQU_SEND_WAKEUP _IOW('r', CMDQU_SEND_WAKEUP, unsigned long) + +enum SYS_CMD_ID { + CMD_TEST_A = 0x10, + CMD_TEST_B, + CMD_TEST_C, + CMD_DUO_LED, + SYS_CMD_INFO_LIMIT, +}; + +enum DUO_LED_STATUS { + DUO_LED_ON = 0x02, + DUO_LED_OFF, + DUO_LED_DONE, +}; + +struct valid_t { + unsigned char linux_valid; + unsigned char rtos_valid; +} __attribute__((packed)); + +typedef union resv_t { + struct valid_t valid; + unsigned short mstime; // 0 : noblock, -1 : block infinite +} resv_t; + +typedef struct cmdqu_t cmdqu_t; +/* cmdqu size should be 8 bytes because of mailbox buffer size */ +struct cmdqu_t { + unsigned char ip_id; + unsigned char cmd_id : 7; + unsigned char block : 1; + union resv_t resv; + unsigned int param_ptr; +} __attribute__((packed)) __attribute__((aligned(0x8))); + +int main() +{ + int ret = 0; + int fd = open(RTOS_CMDQU_DEV_NAME, O_RDWR); + if(fd <= 0) + { + printf("open failed! fd = %d\n", fd); + return 0; + } + + struct cmdqu_t cmd = {0}; + cmd.ip_id = 0; + cmd.cmd_id = CMD_DUO_LED; + cmd.resv.mstime = 100; + cmd.param_ptr = DUO_LED_ON; + + ret = ioctl(fd , RTOS_CMDQU_SEND_WAIT, &cmd); + if(ret < 0) + { + printf("ioctl error!\n"); + close(fd); + } + sleep(1); + printf("C906B: cmd.param_ptr = 0x%x\n", cmd.param_ptr); + + sleep(3); + + cmd.cmd_id = CMD_DUO_LED; + cmd.param_ptr = DUO_LED_OFF; + ret = ioctl(fd , RTOS_CMDQU_SEND, &cmd); + if(ret < 0) + { + printf("ioctl error!\n"); + close(fd); + } + sleep(1); + printf("C906B: cmd.param_ptr = 0x%x\n", cmd.param_ptr); + + close(fd); + return 0; +} +``` + +The test program has been placed in the [duo-examples](https://github.com/milkv-duo/duo-examples/tree/main/mailbox-test) repository,If this is your first time using this repository,you can refer to [README](https://github.com/milkv-duo/duo-examples/blob/main/README.md) to configure the environment and complete the compilation: + +1. The recommended compilation environment is `Ubuntu 22.04 LTS` +2. Install the tools that compile dependencies: + ``` + sudo apt-get install wget git make + ``` +3. Get [duo-examples](https://github.com/milkv-duo/duo-examples) source code: + ``` + git clone https://github.com/milkv-duo/duo-examples.git --depth=1 + ``` +4. Prepare compilation environment: + ``` + cd duo-examples + source envsetup.sh + ``` +5. Enter the `mailbox-test` directory and execute make + ``` + cd mailbox-test + make + ``` + +After successful compilation, the generated `mailbox_test` test program should be transferred to Duo through the network port or USB network (RNDIS). For example, in USB network mode, the IP of Duo is `192.168.42.1`, and the user name is `root`, the password is `milkv`: +``` +$ scp mailbox_test root@192.168.42.1:/root/ +``` + +Add executable permissions to the `mailbox_test` program on Duo: +``` +chmod +x mailbox_test +``` + +The default firmware of Duo has the big core Linux system controlling the LED blinking, which is achieved through a boot script. When testing this program, it is necessary to disable the script responsible for LED blinking. To do so, execute the following command on Duo's terminal: +``` +mv /mnt/system/blink.sh /mnt/system/blink.sh_backup && sync +``` + +This command renames the LED blinking script. After restarting Duo, the LED will no longer blink. + +Run the `./mailbox_test` test in Duo serial port terminal, the output is as follows: +``` +[root@milkv-duo]~# ./mailbox_test +RT: [507.950049]prvQueueISR +RT: [507.952485]recv cmd(19) from C906B, param_ptr [0x00000002] +RT: [507.958306]recv cmd(19) from C906B...send [0x00000004] to C906B +C906B: cmd.param_ptr = 0x4 +RT: [511.965433]prvQueueISR +RT: [511.967867]recv cmd(19) from C906B, param_ptr [0x00000003] +RT: [511.973689]recv cmd(19) from C906B...send [0x00000004] to C906B +C906B: cmd.param_ptr = 0x3 +``` + +You can see that the blue LED on the Duo turns on first and then turns off. + +The logs starting with `RT` are output by the small core `FreeRTOS`, and the logs starting with `C906B` are output by the `mailbox_test` application on the big core. + +In the logs, it can be observed that after the big core sends the command to light up the LED to the small core, the small core responds with 0x4 (0x00000004) to the big core, and the big core also receives 0x4. Similarly, after sending the command to turn off the LED, the small core responds with 0x4 (0x00000004) to the big core. However, the value printed on the big core side is 0x3. Combining this with the code, this 0x3 is the parameter before the big core sends the command to turn off the LED. This difference can be attributed to the usage of `RTOS_CMDQU_SEND_WAIT` and `RTOS_CMDQU_SEND` as two different parameters: +``` +RTOS_CMDQU_SEND_WAIT Wait for return value (ACK) +RTOS_CMDQU_SEND No return value +``` + +Additionally, if you want to view the relevant logs of the mailbox driver in the big core Linux kernel, you can use either of the following two methods: + +1. Modify kernel log level in the serial terminal: + ``` + echo 8 > /proc/sys/kernel/printk + ``` + Then execute the testing program: + ``` + ./mailbox_test + ``` +2. Use the `dmesg` command + +### Appendix + +The directory where the relevant code is located: + +1. Big core mailbox Linux driver: + ``` + linux_5.10/drivers/soc/cvitek/rtos_cmdqu/ + ``` +2. Small core FreeRTOS: + ``` + freertos/cvitek/driver/rtos_cmdqu/include/rtos_cmdqu.h + freertos/cvitek/task/comm/src/riscv64/ + ``` diff --git a/i18n/ja/docusaurus-plugin-content-docs/current/duo/getting-started/setup.md b/i18n/ja/docusaurus-plugin-content-docs/current/duo/getting-started/setup.md new file mode 100644 index 00000000..41c06af2 --- /dev/null +++ b/i18n/ja/docusaurus-plugin-content-docs/current/duo/getting-started/setup.md @@ -0,0 +1,191 @@ +--- +sidebar_label: 'Setting Up' +sidebar_position: 20 +--- + +# Set up the working environment + +## USBnet setup + +We have enabled RNDIS and DHCP on the system by default in order to use USB network. + +### Windows + +1. Connect the Duo to the computer via Type-C cable + +2. The "RNDIS" device appear in the Device Manager + +![rndis-step1](/docs/duo/rndis-step1.png) + +3. Select "RNDIS" and right click to update the driver + +![rndis-step2](/docs/duo/rndis-step2.png) + +4. Select "Browse my computer for drivers" + +![rndis-step3](/docs/duo/rndis-step3.png) + +5. Select "Let me pick from a list of available drivers on my computer" + +![rndis-step4](/docs/duo/rndis-step4.png) + +6. Select "Network adapters" + +![rndis-step5](/docs/duo/rndis-step5.png) + +7. Manufacturer/Model: Microsoft/USB RNDIS Adapter + +![rndis-step6](/docs/duo/rndis-step6.png) + +8. Ignore warning message and click "Yes" + +![rndis-step7](/docs/duo/rndis-step7.png) + +9. Driver update successful + +![rndis-step8](/docs/duo/rndis-step8.png) + +10. Check "USB RNDIS Adapter" + +![rndis-step9](/docs/duo/rndis-step9.png) + +11. Find the IP and test the network using ping + +![rndis-step10](/docs/duo/rndis-step10.png) + +* If you are having trouble installing the rndis driver, you can try [another installation method](./windows-rndis-dirver). + +### Linux + +In general, Linux can use RNDIS without configuration. + +You can use command ip to check the usb0 network. + +``` +neko@milk-v:~ sudo dmesg | grep usb0 +[1055270.386719] rndis_host 1-2.1:1.0 usb0: register 'rndis_host' at usb-0000:00:14.0-2.1, RNDIS device, aa:53:5d:bb:7f:28 +[1055270.423753] rndis_host 1-2.1:1.0 enxaa535dbb7f28: renamed from usb0 +neko@milk-v:~ ip addr show enxaa535dbb7f28 +15: enxaa535dbb7f28: mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000 + link/ether 42:a2:79:19:7f:e3 brd ff:ff:ff:ff:ff:ff + inet 192.168.42.69/24 brd 192.168.42.255 scope global dynamic noprefixroute enp0s20f0u1 + valid_lft 3569sec preferred_lft 3569sec + inet6 fe80::3c92:ed74:3475:cb9c/64 scope link noprefixroute + valid_lft forever preferred_lft forever +neko@milk-v:~ ping 192.168.42.1 -c 5 +PING 192.168.42.1 (192.168.42.1) 56(84) bytes of data. +64 bytes from 192.168.42.1: icmp_seq=1 ttl=64 time=0.334 ms +64 bytes from 192.168.42.1: icmp_seq=2 ttl=64 time=0.287 ms +64 bytes from 192.168.42.1: icmp_seq=3 ttl=64 time=0.275 ms +64 bytes from 192.168.42.1: icmp_seq=4 ttl=64 time=0.287 ms +64 bytes from 192.168.42.1: icmp_seq=5 ttl=64 time=0.266 ms + +--- 192.168.42.1 ping statistics --- +5 packets transmitted, 5 received, 0% packet loss, time 4096ms +rtt min/avg/max/mdev = 0.266/0.289/0.334/0.031 ms +neko@milk-v:~ +``` + +### macOS + +There is no official driver for RNDIS. We need to install [HoRNDIS](https://joshuawise.com/horndis). + +1. Download HoRNDIS driver + - Intel https://github.com/jwise/HoRNDIS/releases + - Apple silicon https://github.com/jwise/HoRNDIS/files/7323710/HoRNDIS-M1.zip + +2. Disable System Integrity Protection + + a. Enter macOS recovery + + Please refer [macOS User Guide -> Recovery](https://support.apple.com/en-hk/guide/mac-help/mchl338cf9a8/mac) to enter recovery mode. + + b. Open the terminal and type the following command + + ``` + csrutil disable + + csrutil enable --without kext + ``` + + c. Restart the Mac + +3. Install the Kext extension in the zip pack + +4. Check the network settings + +## SSH + +1. Open the terminal, type **ssh root@192.168.42.1**, and answer yes + +![rndis-ssh1](/docs/duo/rndis-ssh1.png) + +2. Enter the password **milkv** + + (The password will not be displayed on the screen) + +![rndis-ssh2](/docs/duo/rndis-ssh2.png) + +3. Login successful + +![rndis-ssh3](/docs/duo/rndis-ssh3.png) + +### Modify the IP address of RNDIS + +The default IP address of USB network RNDIS is `192.168.42.1`. If you need to modify this address, for example, when the same computer is connected to multiple Duo devices, the RNDIS IP of each Duo needs to be set to a different one. This can be achieved by modifying the following two files in the Duo device: + +```bash {8} showLineNumbers title="/mnt/system/usb-rndis.sh" +#!/bin/sh + +/etc/uhubon.sh device >> /tmp/rndis.log 2>&1 +/etc/run_usb.sh probe rndis >> /tmp/rndis.log 2>&1 +/etc/run_usb.sh start rndis >> /tmp/rndis.log 2>&1 + +sleep 0.5 +ifconfig usb0 192.168.42.1 + +count=`ps | grep dnsmasq | grep -v grep | wc -l` +if [ ${count} -lt 1 ] ;then + echo "/etc/init.d/S80dnsmasq start" >> /tmp/rndis.log 2>&1 + /etc/init.d/S80dnsmasq start >> /tmp/rndis.log 2>&1 +fi +``` + +```bash {2} showLineNumbers title="/etc/dnsmasq.conf" +interface=usb0 +dhcp-range=192.168.42.2,192.168.42.242,1h +dhcp-option=3 +dhcp-option=6 +``` + +## Serial Console + +### USB to TTL serial cable + +Each pin of a USB-to-TTL cable is defined as follows: + +![usb2ttl](/docs/duo/usb2ttl.jpg) + +### Connection + +Connect USB to TTL serial cable as shown below. Do not connect the red wire. + + +| Milk-V Duo | \<---> | USB to TTL | +| ------------ | ------ | ---------- | +| TX (pin 16) | \<---> | White wire | +| RX (pin 17) | \<---> | Green wire | +| GND (pin 18) | \<---> | Black wire | + + +![duo-serial](/docs/duo/duo-serial.jpg) + +The default serial setting for Duo u-boot and kernel console is: + +``` +baudrate: 115200 +data bit: 8 +stop bit: 1 +parity : none +flow control: none +``` diff --git a/i18n/ja/docusaurus-plugin-content-docs/current/duo/getting-started/swap.md b/i18n/ja/docusaurus-plugin-content-docs/current/duo/getting-started/swap.md new file mode 100644 index 00000000..729c3663 --- /dev/null +++ b/i18n/ja/docusaurus-plugin-content-docs/current/duo/getting-started/swap.md @@ -0,0 +1,165 @@ +--- +sidebar_label: 'Enable Swap' +sidebar_position: 30 +--- + +## 1. What is Swap + +Swap, also known as virtual RAM, is used to support storing data in hard disk when physical memory (RAM) is full. Sometimes Swap is also used in parallel to increase cache capacity even if the physical memory is not used up yet. + +:::caution +This may cause wear and tear on your microSD card leading to a shorter drive lifespan! It is strongly recommended to enable swap functionality **only when there is insufficient memory available**! +::: + +:::tip +The Duo 256M memory is relatively large, so the default firmware does not add a Swap partition and does not support the Swap function. +::: + +## 2. How to enable Swap on Duo + +Use the latest system image + +[https://github.com/milkv-duo/duo-buildroot-sdk/releases](https://github.com/milkv-duo/duo-buildroot-sdk/releases) + +Execute the following two commands to activate swap +``` +mkswap /dev/mmcblk0p3 +swapon /dev/mmcblk0p3 +``` +then run `free -h` command to check if the swap is active (256M) + +``` +[root@milkv-duo]~# free -h + total used free shared buff/cache available +Mem: 28.8M 13.6M 9.1M 76.0K 6.1M 12.4M +Swap: 256.0M 0 256.0M +``` + +## 3. How to increase the size of the Swap partition + +The default firmware size of the Swap partition is `256M`. There are two methods to increase the Swap partition size + +### 1). Modify SDK and recompile to generate a new firmware + +You can modify the value of this [size](https://github.com/milkv-duo/duo-buildroot-sdk/blob/develop/milkv/genimage-milkv-duo.cfg#L36), and then recompile to generate the firmware + +You can modify the size of the Swap partition in the configuration file used to create the image, and then recompile and generate firmware. The configuration file links corresponding to each firmware are as follows: + +[milkv-duo](https://github.com/milkv-duo/duo-buildroot-sdk/blob/develop/device/milkv-duo/genimage.cfg#L36) +[milkv-duo-lite](https://github.com/milkv-duo/duo-buildroot-sdk/blob/develop/device/milkv-duo-lite/genimage.cfg#L36) + +### 2). Directly modify using the fdisk command in Duo + +By connecting to Duo through a serial cable or SSH, you can use the `fdisk` command to modify it. The principle involves deleting the existing swap partition and creating a new one with the specified size + +:::caution +Any modifications to the partitions can potentially lead to data loss. Before performing any partition operations, please make sure to back up your important data! +::: + +The following is the step-by-step command-line interactive method using `fdisk`. If you're not familiar with this method, a script-based approach is provided later, which can be executed once to complete the modification + +#### The command-line interactive mode of fdisk + +Entering the `fdisk` command will take you into the command-line interactive mode of `fdisk` + +``` +fdisk /dev/mmcblk0 +``` + +By entering the `p` command, you can view the information of the current partition on the MicroSD Card. You will be able to see that the partition `/dev/mmcblk0p3` used for `swap` is `256MB` in size +``` +Command (m for help): p +Disk /dev/mmcblk0: 15 GB, 15931539456 bytes, 31116288 sectors +486192 cylinders, 4 heads, 16 sectors/track +Units: sectors of 1 * 512 = 512 bytes + +Device Boot StartCHS EndCHS StartLBA EndLBA Sectors Size Id Type +/dev/mmcblk0p1 * 0,0,2 16,81,2 1 262144 262144 128M c Win95 FAT32 (LBA) +/dev/mmcblk0p2 16,81,3 114,57,8 262145 1835008 1572864 768M 83 Linux +/dev/mmcblk0p3 114,57,9 146,219,10 1835009 2359296 524288 256M 0 Empty +``` +Please make a note of the `StartLBA` (starting sector) value for `/dev/mmcblk0p3`, which is `1835009`. We will need it later + +To delete a partition, you need to execute the `d` command and then enter the partition number you want to delete. In this case, we want to delete `/dev/mmcblk0p3`, so you should enter `3` +``` +Command (m for help): d +Partition number (1-4): 3 +``` + +To create a new partition, you can use the `n` command. When prompted, choose whether to create a primary or extended partition. Since we want to create a primary partition, enter `p`. Next, enter the partition number you want to create, which is `3` for `/dev/mmcblk0p3` + +The following prompt `First sector` is required to enter the starting sector value of the new partition, which is the value `1835009` recorded above. You can see that this value is recognized by default in the prompt, so you can just press Enter without inputting it + +Finally, you will be asked to input the size of the new partition. You can either enter the ending sector value or directly specify the size of the partition. For example, if you want to allocate 1GB, you can enter `+1G` according to the prompt +``` +Command (m for help): n +Partition type + p primary partition (1-4) + e extended +p +Partition number (1-4): 3 +First sector (1835009-31116287, default 1835009): +Using default value 1835009 +Last sector or +size{,K,M,G,T} (1835009-31116287, default 31116287): +1G +``` +Then execute the `p` command again to check the current partition status. You will see that `/dev/mmcblk0p3` is now `1024M`, which is equivalent to `1G` + +Finally, execute the `w` command to save the modifications and exit the fdisk interactive mode +``` +Command (m for help): w +The partition table has been altered. +Calling ioctl() to re-read partition table +fdisk: WARNING: rereading partition table failed, kernel still uses old table: Resource busy +``` +At this point, the partition modifications will not take effect until you execute the `reboot` command to restart the system or power cycle the device + +To activate Swap, you can execute the following two commands in the Duo terminal +``` +mkswap /dev/mmcblk0p3 +swapon /dev/mmcblk0p3 +``` +Then run the command `free -h` to check if the swap has been enabled (1G, which is equivalent to 1024M) + +#### The script-based approach for fdisk + +Create a script file named `swap_resize.sh` in Duo, or create it on your PC and then upload it to Duo + +The contents of the `swap_resize.sh` file, please note to modify `+1G` to the desired size +```bash +fdisk /dev/mmcblk0 <