[Sharing] Ameba family is now supporting Auto-upload features 🥳

Introduction

:mega: The Ameba Auto Upload Tool was contributed by community member Joe Hsieh, who programmed and tested this auto-upload feature with BW16 and RTL8722DM based evaluation boards. Joe has written the auto-upload tool as a standalone replacement of the original upload tool used in Arduino IDE for all three OS platforms (Windows/Linux/macOS).
Ameba auto-upload tool has been tested on Windows 10 64-bits, Linux, and macOS (Big Sur) using BW16 and RTL8722DM evaluation boards.

Background

Here is a brief introduction to how Joe reverses engineered and figured out the upload process necessary for the auto-upload tool to work.
Firstly, “SerialMon” (a serial port sniffer tool) is used to read out the communications occurring while the image tool is uploading an image. The recorded log could be saved in a text format for convenience when analyzing. Modifying some settings in the image tool (e.g., upload speed, flash address) will cause the communications to change. By testing out each setting, recording the communication log, and comparing it with previous logs, it is possible to figure out how each set corresponds to changes in the data sent.
However, not all the changes could be explained by comparing the logs, therefore the “IDA Disassembler” tool is used to translate the binary file back to “.c” code to extract the remaining missing information.

Problem Statement

In the default configuration, to enter the UART download mode on the development boards, the RESET (CHIP-EN) pin should be pulled LOW and released while LOG_UART_TX (PA7) is held in the LOW state. Please refer to the sequence in the flow chart below for detailed procedures:
image

Normally, this is achieved with manual input using buttons located on the evaluation boards. However, the above procedure could be automated with an additional circuit using the DTR and RTS pins on a USB-UART adapter (e.g., CH340G, CP2102, FT232), 2 BJT transistors (e.g., S8050), and 2 10kOhm resistors.

Environment Setup

Step 1. Setting up the Development Environment

Please refer to the Getting Started documentation corresponding to the development board that you are using.

  • For users of BW16, please refer to the section “Setting up Development Environment” of Ameba ARDUINO: Getting Started with BW16/RTL8720DN for detailed instructions

  • For users of RTL8722DM, please refer to the section “Setting up Development Environment” of Ameba ARDUINO: Getting Started with RTL8722 for detailed instructions

  • For users of RTL8722DM-MINI, currently, the supportive function on RTL8722DM-MINI is still under testing and confirmation, updated information will be provided in this section upon the test is finished.

Step 2. Patch the Environment accordingly

Since this tool completely replaces the original upload tool “amebad_image_tool.exe” (Windows/Linux/macOS), a patch to the development environment is required.
Download the “ameba_bw16_autoflash” repository from GitHub [1]. Replace the original “amebad_image_tool.exe” based on the system that you are using:

  • Windows
    Replace the “upload_image_tool_windows.exe” found in the following path: C:\Users\xxxxxx\AppData\Local\Arduino15\packages\realtek\tools\ameba_d_tools\1.0.5
  • Linux
    Replace “upload_image_tool_linux” found in the following path:
    ~/.arduino15/packages/realtek/tools/ameba_d_tools/1.0.5
  • MacOS (Big Sur)
    Replace “upload_image_tool_macos” found in the following path:
    ~/Library/Arduino15/packages/realtek/tools/ameba_d_tools/1.0.5

Step 3. Hardware Modification

After the software environment setup is done, some additional hardware components need to be added to the development board to achieve the auto flashing function.

Required Components

  • USB-UART adapter module (e.g., CH340G, CP2102, FT232)
  • 10KOhm Resistors x2
  • BJT Transistor x2 (e.g., S8050)
  • BW16 / RTL8722DM / RTL8722DM-MINI board

Circuit Connection Diagram & Logic Table

image
Figure 1 Circuit Connection Diagram


image
Table 1 Circuit Logic Table

Operation Principle

CH340 is a USB bus converter chip that converts USB to a UART serial interface. It is commonly used to provide a serial USB connection for microcontrollers without a native USB controller. In the serial interface mode, common MODEM liaison signals are also available: RTS (Request to Send), DTR (Data Terminal Ready), DCD (Data Carrier Detect), DSR (Data Set Ready), and CTS (Clear to Send) [2].

image

According to the code above the auto-upload process is as follows:

  1. When the upload process starts, DTR = 1, RTS = 0, resulting in RST = 0, which forces the chip into reset
  2. After a delay (500ms), DTR = 0, RTS = 1, resulting in LOG_UART_TX (PA7) = 0, to prepare to enter download mode
  3. After a delay(200ms), DTR =1, RTS = 1, releasing both RST and LOG_UART_TX pins, which allows the chip to restart in download mode
  4. The required flash images are transferred using the USB-UART serial port
  5. DTR = 1, RTS = 0, resulting in RST = 0, which forces the chip into reset
  6. After a delay (500ms), DTR =1, RTS = 1, releasing the RST pin, which allows the chip to restart in normal mode

References

[1] GitHub resources ameba_bw16_autoflash
[2] USB to serial chip CH340

2 Likes