Ameba ARDUINO: Getting Started with BW16/RTL8720DN
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.
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.
|PIN name||GPIO INT||ADC||PWM||UART||SPI||I2C|
Setting up Development Environment
Step 1. Installing the Driver
First, connect BW16/RTL8720DN to the computer via Micro USB:
If this is the first time you connect BW16/RTL8720DN to your computer, here is something that you might take note of:
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:
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:
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”:
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.
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.
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)”：
How to upload firmware into BW16/RTL8720DN
• USB Serial Adapter
• BW16/RTL8720DN Module
|BW16||USB Serial Adapter|
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.
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.
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.
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).
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:
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:
Then click “Generate”, save the generated “OTA.bin” file under the following file path:
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”.
• Then, key in the “ipconfig” command in the Command Prompt to obtain your IPv4 address:
• 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:
• 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.
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.
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.
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.
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.
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”:
Arduino IDE opens a new window with the complete sample code.
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”:
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:
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.
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.
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 BW16/RTL8720DN.
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 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.
1. Introduction of RTL8720DN on Instructable:
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: