Compile and Flash CH55x with SDCC

Compile and Flash CH55x with SDCC#

Running a Program#

To run the program, you will need to use a bash terminal. Follow these steps to clone the examples repository, navigate to the appropriate directory, and compile the project.

  1. Clone the Examples Repository

    Begin by cloning the examples repository which contains the main code. Open your bash terminal and execute the following command:

    git clone https://github.com/UNIT-Electronics/CH55x_SDCC_Examples
    
  2. Navigate to the Example Path

    Once the repository is cloned, navigate to the path where the example programs are located. Use the following command to change the directory:

    cd ~/CH55x_SDCC_Examples/Software/examples/Blink/
    
  3. Connect the Device

    Connect your CH55x device to your computer. Ensure that you press and hold the BOOT button while connecting the device. This is essential for the device to enter programming mode.

  4. Compile the Project

    To compile the project and generate the necessary files, execute the following command in your terminal:

    make all
    

    This command will compile the project, resulting in the generation of files with various extensions necessary for flashing the microcontroller.

sections of the code

Fig. 8 Compilation output files#

Install pyusb#

pyusb is a Python module necessary for flashing the CH55x microcontroller. To install pyusb, follow these steps:

Install pyusb on using pip

python3 -m pip install pyusb

Then verify the installation

python3 -m pip show pyusb

For Windows, you can use the following command:

pip install pyusb

Error with pip#

If you encounter this error, we recommend installing the Python environment:

sudo apt install python3-venv

Create an environment:

python3 -m venv .venv

Activate the environment:

source .venv/bin/activate

And install pyusb:

pip install pyusb

Flashing the Program#

Arduino IDE is a popular development environment for programming microcontrollers. You can use the Arduino IDE to program the CH55x microcontrollers by following these steps:

  1. Install Arduino IDE

    Download and install the Arduino IDE on your computer.

  2. Install CH55x Board Support

    Open the Arduino IDE and navigate to File > Preferences. In the Additional Boards Manager URLs field, add the following URL:

    https://raw.githubusercontent.com/Cesarbautista10/Uelectronics-CH552-Arduino-Package-v3/main/package_duino_mcs51_index.json
    
  3. Install CH55x Board

    Go to Tools > Board > Boards Manager and search for Cocket Nova. Install the CH55x board support package.

Note

Requires the ch372 driver to be installed.