Friday, July 13, 2018

Hacking "ESP8266 Black Board T5" Part 2 - Blinky and Hello World on SDCC


Previous Part:
Hacking "ESP8266 Black Board T5" Part 1 - Blinky on Keil

Lets now move to SDCC, because SDCC is free and the free version of Keil has limitations. We will also move away from Windows to Ubuntu 64 bit

Installing SDCC on your Ubuntu PC

Download 64 bit snapshot from: http://sdcc.sourceforge.net/snap.php#Linux
The archive file would be named something like:
sdcc-snapshot-amd64-unknown-linux2.5-20180712-10467.tar.bz2

Download it to your ~/Documents directory

Then execute the following commands from the same directory (~/Documents) where you have placed the downloaded archive:
  1. tar xjf ../sdcc-snapshot-amd64-unknown-linux2.5-20180712-10467.tar.bz2 
  2. cd sdcc 
  3. sudo cp -r * /usr/local
This will install sdcc binaries into: /usr/local/bin/
header files into: /usr/local/share/sdcc/include/
non-free header files into: /usr/local/share/sdcc/non-free/include/
library files into: /usr/local/share/sdcc/lib/
non-free library files into: /usr/local/share/sdcc/non-free/lib/
and documentation into: /usr/local/share/sdcc/doc/


You can test the install by entering:
/usr/local/bin/sdcc -v
This should return sdcc's version number, something like:
SDCC : mcs51/z80/z180/r2k/r3ka/gbz80/tlcs90/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8 3.7.1 #10467 (Linux)

published under GNU General Public License (GPL)

Get the blinky source code and compile it

  1. Install git if you don't have it installed:
    sudo apt-get install git 
  2. Clone the repo 
    1. cd ~/Documents 
    2. git clone https://github.com/lithiumhead/Black_Cloud_STC15L2K32S2 
  3. Compile the code 
    1. cd Black_Cloud_STC15L2K32S2/Blinky
    2. sdcc -mmcs51 --verbose main.c
SDCC Compiling C program for 8051


This will generate the Intel Hex file main.ihx

To remove the generated artifacts, you can use the git command to remove the files with extensions listed in .gitignore:
git clean -fX
git clean -fX helps remove build artifact

Download stcgal  command line open source in-system programmer


  1. Install python and stcgal dependencies 
    1. sudo apt install python3 python3-pip 
    2. pip3 install pyserial tqdm 
  2. Clone the git repo and install: 
    1. cd ~/Documents 
    2. git clone https://github.com/grigorig/stcgal 
    3. cd stcgal 
    4. ./setup.py build 
    5. sudo ./setup.py install 
  3. Try downloading the ihx file into Black Board: 
    1. Connect the CH340 USB-Serial board to your Ubuntu Computer. It will appear as /dev/ttyUSB0. The USB-Serial's pin header should be connected to STC15L2K32S2's UART header. 
    2. cd ~/Documents/Black_Cloud_STC15L2K32S2/Blinky 
    3. sudo stcgal -P stc15 -p /dev/ttyUSB0 main.ihx 
    4. Turn on the power to the BlackBoard, this will cause the bootloader to initially run - stcgal will detect it and download the ihx file into the microcontroller's flash memory. The program will run immediately post downloading.
Success downloading ihx to Black Board STC15L2K32S2
Blinky running on the Black Board

Next try compiling and downloading the hello world program
  1. cd ~/Documents/Black_Cloud_STC15L2K32S2/UART_Echo 
  2. sdcc -mmcs51 --verbose main.c 
  3. sudo stcgal -P stc15 -p /dev/ttyUSB0 main.ihx 
  4. sudo apt install minicom 
  5. sudo minicom -D /dev/ttyUSB0 
  6. Configure minicom 
    1. Press Ctrl+A followed by Z 
    2. Press O 
    3. Select "serial port setup" 
    4. press F to change "Hardware Flow Control" to No 
    5. Press Enter 
    6. Select "Save setup as dfl" 
    7. Select exit 
  7. Power cycle the Black Board and you will see the message printed on minicom 
  8. Press Ctrl+A X to leave minicom
Message printed on minicom sent by Black Cloud's STC15L2K32S2


0 comments:

Post a Comment