Author Topic: VS Code + SDCC + Git, build environment for 8051 microcontroller  (Read 5073 times)

0 Members and 1 Guest are viewing this topic.

Offline danchouzhouTopic starter

  • Contributor
  • Posts: 20
  • Country: tw
VS Code + SDCC + Git, build environment for 8051 microcontroller
« on: February 20, 2025, 05:39:01 am »
This is about the open-source project – the 003Clock firmware build environment.
OSHW clock kit with a 22-cent Nuvoton enhanced 8051 microcontroller, N76S003.
https://www.eevblog.com/forum/oshw/oshw-clock-kit-with-22-cents-nuvoton-enhanced-8051-microcontroller/

Around 2018, Nuvoton launched the N76E003, an enhanced 8051 microcontroller priced at just 22 cents. It is pin-to-pin compatible with the STM8S003, with a single machine cycle, built-in 18KB program memory, two UARTs, ADC, I2C, SPI, PWM, and more. It's similar to the Arduino UNO in terms of connectivity with various sensors. This year, they released the N76S003, produced with mature technology, hence still priced at 22 cents. Nuvoton guarantees it is fully pin-to-pin and code-to-code compatible, with the added SPROM feature.

Programming 8051 often involves commercial software like Keil C51 and IAR, which have code size limitations in their free versions, such as 2 KB. However, the paid versions are not friendly to hobbyists. This means the code memory 18 KB of the N76S003 would be underutilized. Therefore, I switched to using the SDCC (Small Device C Compiler), which has no code size limit and also it’s open-source tool.

SDCC is just a toolchain (commonly known as a compiler) rather than an Integrated Development Environment (IDE). We still need to build a user-friendly interface. I chose the popular VS Code. Compared to commercial software, VS Code has a simple interface.I store compiler paths as text files in .vscode/setting.json under the physical path, this is its native function, and no need to install extensions. This means moving the entire firmware project folder to another computer requires no reconfiguration (rather than a bunch of GUI settings). Thanks for the plain text setting files, it is also easy to manage projects with Git and collaborate with others.

To set up this environment, we need VS Code, SDCC, Git Bash, and programming tools. You can get them from the following links:
https://code.visualstudio.com/download
https://sourceforge.net/projects/sdcc/files/sdcc-win64/4.2.0/
https://git-scm.com/downloads

For programming tools, there are two options. If you use the NuMicro ICP Programming Tool, you need a Nuvoton Nu-Link debugger, either purchased separately or included with a development board. The NuMicro ISP Programming Tool can program firmware via USB to UART, which requires an ISP bootloader pre-installed in the chip, which must be programmed using ICP first.
https://www.nuvoton.com/tool-and-software/software-tool/programmer-tool/

Generally, follow the installation steps. Before the SDCC installation is complete, it will ask whether to add it to the environment variables. This is not necessary because we will specify the SDCC location in .vscode/setting.json later.

To operate, you should clone or download the project from GitHub by using following command in git bash. The other option is “Download ZIP” from the GitHub web.
git clone https://github.com/danchouzhou/003Clock.git --recurse-submodules
Open the project folder which include ./vscode in VS Code, so it reads the settings file .vscode/setting.json.

When compiling, first open a terminal in VS Code.

Change the directory to the one to be compiled, such as firmware/003Clock (I use directories to distinguish different firmware functions), then execute the script build.bat. Here are the commands:

If there are no error messages, the compilation is successful. The compiled binary will be in firmware/003Clock/Objects/main.bin. If you have a Nu-Link debugger connected, simply run flash.bat to complete the programming.
« Last Edit: February 20, 2025, 09:51:46 am by danchouzhou »
If you are using Nuvoton chips, visit NuForum to get faster, more professional advice and technical support from their experts.
https://forum.nuvoton.com/
 
The following users thanked this post: ledtester, koba30, Dazed_N_Confused

Offline bigendian

  • Regular Contributor
  • *
  • Posts: 82
  • Country: it
  • shutdown -h now
Re: VS Code + SDCC + Git, build environment for 8051 microcontroller
« Reply #1 on: February 20, 2025, 09:42:17 am »
Thanks, i always use keil C51 with 8051. Anyway, don't have any reason to use them as 8 bit mcus with avr core and gcc.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->