Ameba ARDUINO: Getting Started with BW16

Required Environment

RTL8720DN Dual-Band Wi-Fi board currently supports Windows XP/7/8/10 32-bits and 64-bits operating systems. In this documentation, please use Arduino IDE with version 1.8.15 or later.

Introduction to BW16

Realtek RTL8720DN is a Wi-Fi and Bluetooth IC that supports 2.4GHz and 5GHz dual bands for Wi-Fi communication, and Bluetooth Low Energy (BLE) 5.0. BW16 is a module manufactured by B&T, this module is a highly integrated Wi-Fi and Bluetooth module with the RTL8720DN as the main SoC (System on Chip), it can be regarded as an SoC for the Wi-Fi and Bluetooth application with typical SBCs.

get-start-1

RTL8720DN (BW16) has a smaller size than AmebaD and AmebaD MINI as shown in the above figure. It uses Micro USB to supply power, which is common in many smart devices.
Please refer to the following figure and table for the pin diagram and function of RTL8720DN (BW16).

get-start-2

 PIN nameGPIO INTADCPWMUARTSPII2C
D0 (PA7)GPIOA_7  UART_LOG_TX  
D1 (PA8)GPIOA_8  UART_LOG_RX  
D2 (PA27)GPIOA_27     
D3 (PA30)GPIOA_30     
D4 (PB1)GPIOB_1A0 Serial_TX  
D5 (PB2)GPIOB_2A1 Serial_RX  
D6 (PB3)GPIOB_3A2    
D7 (PA25)GPIOA_25   I2C0_CLK
D8 (PA26)GPIOA_26   I2C0_SDA
D9 (PA15)GPIOA_15   SPI_CS 
D10 (PA14)GPIOA_14   SPI_CLK 
D11 (PA13)GPIOA_13  SPI_MISO 
D12 (PA12)GPIOA_12  SPI_MOSI 

Setting up Development Environment

Step 1. Installing the Driver

First, connect RTL8720DN (BW16) to the computer via Micro USB:

get-start-3

If this is the first time you connect RTL8720DN (BW16) to your computer, here is something that you might take note of:

get-start-4

From the pinmap above, we know D0 and D1 pins are used for program uploading. However, the onboard USB-to-UART module is connected to D4 and D5 according to the schematic design, which cannot be directly used for program upload.
In order to upload the program, you could choose to either use an external USB-to-UART module connecting to D0 and D1, or short the pins indicated below to use the on-board USB:
D1 ––– D5
D0 ––– D4

After connecting accordingly, the USB driver for RTL8720DN (BW16) will be automatically installed. You can check the COM Port number in your Device Manager:

get-start-5

Step 2. Set up Arduino IDE

From version 1.6.5, Arduino IDE supports third-party hardware. Therefore, we can use Arduino IDE to develop applications on RTL8720DN (BW16), and the basic examples of Arduino can run on RTL8720DN (BW16) too. Refer to the basic example link.

Arduino IDE can be downloaded in the Arduino website: https://www.arduino.cc/en/Main/Software

When the installation is finished, open Arduino IDE. To set up RTL8720DN (BW16) correctly in Arduino IDE, go to “File” -> “Preferences”.

And paste the following URL into the “Additional Boards Manager URLs” field: https://github.com/ambiot/ambd_arduino/raw/master/Arduino_package/package_realtek.com_amebad_index.json
RTL8720DN (BW16) will be supported from v3.0.8 officially.

Next, go to “Tools” -> “Board” -> “Boards Manager”:

get-start-6

The “Boards Manager” requires about 10~20 seconds to refresh all hardware files (if the network is in bad condition, it may take longer). Every time the new hardware is connected, we need to reopen the Board Manager. So, we close the Boards Manager, and then open it again. Find “Realtek AmebaD Boards (32-bits ARM Cortex-M33 @200MHz)” in the list, click “Install”, then the Arduino IDE starts to download required files for AmebaD.

get-start-7

If you are facing GitHub downloading issue, please refer to the following link at “Download/Software Development Kit”. There are 3 sections.
1. “AmebaD_Arduino_patch1_SDK”, please select at least 1 of the SDKs. There are 5 latest released SDK options.
2. “AmebaD_Arduino_patch2_Tools”, please select according to your operating system. There are Windows, Linux, and macOS.
3. “AmebaD_Arduino_Source_Code”, this section is an optional download only wants to refer to the latest source code.

https://www.amebaiot.com/ameba-arduino-summary/

Download the files selected, then unzip (patch1 and patch2 are compulsory). There are “Install.doc”/“Install.pdf” for you to refer to installation steps. According to your system, please run the installation tool in the “Offline_SDK_installation_tool” folder.
After the installation tool running successfully, you may open Arduino IDE and proceed to “tools” -> “Board“ -> “Boards Manager…”. Try to find “Realtek AmebaD Boards (32-bits ARM Cortex-M33 @200MHz)” in the list, click “Install”, then the Arduino IDE starts to download the required files for AmebaD.
Finally, we select AmebaD as current connected board in “Tools” -> “Board” -> “Ameba ARM (32-bits) Boards” ->” RTL8720DN(BW16)”:

get-start-8

How to upload firmware into BW16

Depending on the batch of manufacturing, some BW16 modules on the development board might have built-in the default B&T firmware, the firmware information is shown in the image below:

get-start-9

This will cause Arduino Image unable to flash into the module. Although information of “All images are sent successfully! Image tool closed! Upload Image did.” is showing in the Image Tool, however, the factory image is unable to be erased. Unfortunately after press the onboard RST button, you will find the factory image still remains in the flash.

Uploading Solution

Method 1: Use AmebaD Image Tool to erase flash.

The B&T default factory image can be washed using “Erase” function provided by Realtek’s Image Tool. Using Image Tool to erase the flash image memory starting from memory address: 0x8000_0000 till the end of 2MB memory location, later on, we need to upload Realtek’s image back to the module again using Arduino IDE.

get-start-10

Step 1 – Download and prepare the Image Tool.
Download ambd_sdk from the link ambiot GitHub: https://github.com/ambiot/ambd_sdk.
The Realtek’s Image Tool can be found under the following file path: “ambd_sdk\tools\AmbaD\Image_tool\image_tool.exe”

Step 2 – Setup the Image Tool
1. In the “Chip Select” option, choose “AmebaD(8721D)” which is also suitable for RTL8720DN chip.
2. Select correct COM Port that you are using.
3. Set the Baudrate to “115200”.
4. Then key in the Flash Erase starting position from Memory Address of 0x8000 0000, with a specific memory size of 2048 KB.
5. Set the module to “Download mode” first, then click the “Erase” button.

get-start-11

Upon finishing the above image erase and press the reset button, we could find that the “#calibration” will no longer pop out, only ”#” will appear in the Serial Monitor.

get-start-12

Step 3 – Download Image using Arduino IDE
Now you are able to download the program via UART in Ardunio IDE. In order to upload the program, you could choose to either use an external USB-to-UART module connecting to D0 and D1, or short the pins indicated below to use the on-board USB:

get-start-13

D1 ––– D5
D0 ––– D4

Optional Uploading Solution

OTA (Over The Air)
Ai-Thinker is providing a guide for OTA firmware upload in Section 6.1 of B&T “RTL8720D AT Command User Manual” of which can be retrieved from the link below:
https://docs.ai-thinker.com/_media/rtl8710/docs/rtl8720d-at%E6%8C%87%E4%BB%A4%E6%89%8B%E5%86%8Cv2.4.1-20190814.pdf.

Try the First Example

Step 1. Compile & Upload

Arduino IDE provides many built-in examples, which can be compiled, uploaded, and run directly on the boards. Here, we take the “Blink” example as the first try.
Open “File” -> “Examples” -> “01.Basics” -> “Blink”:

get-start-14

Arduino IDE opens a new window with the complete sample code.

get-start-15

There is an onboard LED of RTL8720DN(BW16), the default “LED_BUILTIN” is a green onboard LED. Change “LED_BUILTIN” to “LED_B” or “LED_R” for different colors such as blue and red. Here we use “LED_B” for demonstration purpose.
Next, we compile the sample code directly; click “Sketch” -> “Verify/Compile”:

get-start-16

Arduino IDE prints the compiling messages in the bottom area of the IDE window. When the compilation is finished, you will get a message similar to the following figure:

get-start-17

Afterward, we will upload the compiled code to RTL8720DN(BW16).

Please make sure RTL8720DN(BW16) is connected to your computer, then click “Sketch” -> “Upload”.

The Arduino IDE will compile first then upload. During the uploading process, users are required to enter the upload mode of the board. To enter the upload mode, first press and hold the RTL8720DN(BW16) “Burn” button, press the “RST” button, and then release the “Burn” button.

get-start-18

Press “Upload” button in Arduino IDE to compile and upload the program. Arduino IDE will wait for 5s for the development board to enter the upload mode.

get-start-19

Again, during the uploading procedure the IDE prints messages. The uploading procedure takes a considerably longer time (about 30 seconds to 1 minute). When the upload is completed, the “Upload Image done” message is printed.

Step 2. Run the Blink example

In each example, Arduino not only provides sample code but also detailed documentation, including wiring diagram, sample code explanation, technical details, …etc. These examples can be directly used on RTL8720DN (BW16).
So, we find the detailed information of the Blink example in the link below: https://www.arduino.cc/en/Tutorial/BuiltInExamples/Blink

In short, for RTL8720DN, the example can be run on both the onboard RGB LED or external LED (use any GPIO pins for signal output). Finally, press the “RST” button, and you can see the RGB LED turns into blue and keep blinking.

References

1. Introduction of RTL8720DN on Instructable:
https://www.instructables.com/RTL8720DN/
2. Load Arduino image into BW16:
How to load BW16 program with Arduino – #13
3. RTL8720DN (BW16) IMG2 SIGN Invalid Solution:
RTL8720DN(BW16) IMG2 SIGN Invalid Solution
4. FTDI Driver Download from here:
https://ftdichip.com/wp-content/uploads/2021/02/CDM21228_Setup.zip

Please confirm that QQ communication software is installed