Ameba ARDUINO: Getting Started with BW16/RTL8720DN

Required Environment

BW16/RTL8720DN Dual-Band Wi-Fi board currently supports Windows OS 32-bits and 64-bits (WIN7/8/10), Linux OS (Ubuntu 18 LTS/20 LTS/latest) and macOS operating systems. Please use the latest OS version to have the best experiences. In this documentation, please use the latest version Arduino IDE (at least version 1.8.12).

Introduction to BW16/RTL8720DN

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

BW16/RTL8720DN has a smaller size than RTL8722DM and RTL8722DM_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 BW16/RTL8720DN.

get-start-2

PIN nameGPIO INTADCPWMUARTSPII2C
GPIOA_7    
GPIOB_1    
GPIOA_12   
GPIOA_13   
GPIOA_14    
GPIOA_15    
GPIOA_25   
GPIOA_26   
GPIOA_27     
GPIOA_30     
GPIOB_1    
GPIOB_2    
GPIOB_3    

Setting up Development Environment

Step 1. Installing the Driver

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

get-start-3

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

get-start-4

The pins LOG_UART_TX (PA7) and LOG_UART_RX (PA8) are used for program upload. However, the onboard USB-to-UART module is connected to LP_UART_TX (PB1) and LP_UART_RX (PB2) and thus cannot be used directly for program upload. You can choose to either use an external USB-to-UART module connected to PA7 and PA8, or you could short these pins together to use the on-board USB for program upload:
PA8–––PB2
PA7–––PB1
After connecting accordingly, the USB driver for BW16/RTL8720DN will be automatically installed. You can check the COM port number in Device Manager of your computer:

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 BW16/RTL8720DN, and the basic examples of Arduino can run on BW16/RTL8720DN 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 BW16/RTL8720DN 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
BW16/RTL8720DN 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-M4 @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-M4 @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/RTL8720DN

Required Components

• USB Serial Adapter
• BW16/RTL8720DN Module

Connection

get-start-9

BW16USB Serial Adapter
LOG_RX (PA8)TX
LOG_TX (PA7)RX
3V33V3
GNDGND

Trigger Module Reset

Connect EN Pin to GND (pulling low) will trigger a module reset.

How to enter Download Mode

1. Connect LOG_TX (PA7) to GND.
2. Connect EN to GND (pulling low), then to 3V3 (pulling high) to trigger a module reset.
3. Disconnect LOG_TX (PA8) from GND.
4. Now BW16 is entered into the download mode and ready for the program to upload.

Problem Encountered

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-10

This will cause Arduino Image to not be able 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 not being erased, while pressing the onboard RST button, the factory image will remain in the flash.

Uploading Solution

Method 1: OTA (Over The Air)

The B&T default factory image can be washed through the OTA method provided by Realtek’s Image Tool that allows users to update the firmware through the Ardunio UART process without fail. The detailed description of the OTA method and definition of common AT Commands are described in B&T “RTL8720D AT Command User Manual” Appendix 6.1, which can be found in the Reference section below.

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 – Download and prepare the Image Tool.

Open any terminal communication program, Tera Term, etc. Connect to AP via the AT Command: “#ATPN=your-SSID,your-password”, and wait until ATPN responds “#ATPN OK” (For more details, please refer to B&T “RTL8720D AT Command User Manual” Section 3.2).

get-start-11

Note that the Wi-Fi connection of both the PC and RTL8720DN Module should connect to the same SSID address.

Step 3 – Generate the OTA.bin file

Use Ameba Image Tools from the link in the “ambd_sdk” downloaded in Step 1 to generate an “OTA.bin” that could be uploaded to the board wirelessly:
“ambd_sdk\tools\AmbaD\Image_tool\image_tool.exe”

get-start-12

Click the “Generate” tab, in the “Generate Target” Section select “OTA_All”. Then, tick the checkbox on the right side of “Bin 3” and the Ardunio binary file can be found in the file path below:
“C:\%USER%\AppData\Local\Arduino15\packages\realtek\tools\ameba_d_tools\1.0.5\km0_km4_image2.bin”

get-start-13

Then click “Generate”, save the generated “OTA.bin” file under the following file path:
“ambd_sdk\tools\DownloadServer”.

get-start-14

Step 4 – Start the OTA process

• Open Windows Command Prompt, change the root directory to: “ambd_sdk\tools\DownloadServer”.
Runs “start.bat” and waits for the port number displayed, the port number used by my PC is “8082”.

get-start-15

• Then, key in the “ipconfig” command in the Command Prompt to obtain your IPv4 address:

get-start-16

• Upon obtaining the ip address and port number, start the server program using the command in Windows Shell: .\DownlaoadServer.exe YOUR-PORT-NUMBER ota.bin
The following information will be shown in the Shell terminal after the OTA server is set up correctly:

get-start-17

• Since previously we have already connected the BW16 module (OTA client) to the same SSID as the PC (OTA server) in step 2. Now, we will use another AT Command “#ATSO=IP-address,port-number” to connect to the OTA server (please refer to B&T “RTL8720D AT Command User Manual” Section 2.9 for more information).
Upon key in the command, the information of ”Erase is ongoing…..” will appear. You can see that the terminal shows OTA status, wait until the whole uploading process finishes. When OTA finish, press the reset button again.

get-start-18

Step 5 – Download Arduino program via UART

Now we can download the program via UART in Ardunio, but since the RTLDuino USB chip is connected to LP_UART instead of LOG_UART. The pins LOG_UART_TX (GPIOA_7) and LOG_UART_RX (GPIOA_8) are used for program upload. However, the onboard USB-to-UART module is connected to LP_UART_TX (GPIOB_1) and LP_UART_RX (GPIOB_2) and thus cannot be used directly for program upload.

get-start-19

You can choose to either use an external USB-to-UART module connected to GPIOA_7 and GPIOA_8, or you could short these pins together to use the on-board USB for program upload:
• PA8 ––– PB2
• PA7 ––– PB1
If entries UART download process, first hold the burn button and reset button and then release the reset button and burn button.

Method 2: Use AmebaD Image Tool to erase flash.

Alternatively, without using OTA that only allows the module upload program after connecting to Wi-Fi. Another way is 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-20

Follow Method 1 Step 1 to download ambd_sdk and do the necessary setup preparation before moving on to using this method.

Step 1 – Open Image Tool

Set the Baudrate to “115200”, then select the Flash Erase range from Memory Address of 0x80006000, with a specific address of 2024 KB. Set the module to “Download mode”, then click Erase button.

get-start-21

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.

get-start-22

Step 2 – Download Image using Arduino IDE

Download the Arduino program following the instruction in Method 1 Step 5, the image will be installed back again.

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-23

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

get-start-24

There is an onboard LED of BW16/RTL8720DN, the default “LED_BUILTIN” is a green onboard LED. Change “LED_BUILTIN” to “LED_BUILTIN_B” or “LED_BUILTIN_R” for different colors blue and red. Here we use LED_BUILTIN_B as an example.

Next, we compile the sample code directly; click “Sketch” -> “Verify/Compile”:

get-start-25

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-26

Afterward, we will upload the compiled code to BW16/RTL8720DN.
Please make sure BW16/RTL8720DN 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. Arduino IDE will wait for 5s for the development board to enter the upload mode.

get-start-27

To enter the upload mode, first press and hold the BW16/RTL8720DN “Burn” button, press the “RST” button, and then release the “Burn” button. Press “Upload” to compile and upload the program.

It is optional for users to check if the board entered the upload mode. Open serial monitor/terminal and look for “#Flash Download Start”. Note, it is normal that some serial terminals may show unknown characters as following picture.

get-start-28

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.

get-start-28

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 BW16/RTL8720DN.
So, we find the detailed information of the Blink example in the link below: https://www.arduino.cc/en/Tutorial/BuiltInExamples/Blink

get-start-29

In short, for BW16/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 blue LED blinking.
If you encounter any problem, please refer to Troubleshooting Guide.

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

Copyrights ©瑞晟微电子(苏州)有限公司 2021. All rights reserved.
Please confirm that QQ communication software is installed