0%
0%

WooDWorkeR

Like to write software, and build hardware that sounds strange

Berlin, Germany, Europe, Earth, Sol, Milky Way
Send a private message
Similar accounts worth following
woodworker
Send a private message

This user joined on 07/24/2014.

  • The 0.70 € STM8 Board

    08/17/2016 at 09:56 3 comments

    The 0.70 € Board

    So you ordered your super cheap stm8 dev board from aliexpress oder eBay and now you want to do at least a blinking LED, then this Mini Tutorial is exactly for you

    Hardware

    The STM8S103F3 dev board

    Just in case you do not have your board yet, search for "STM8S103F3 board" on you favorite china shopping page. You should see a plethora of listings from anything between 70 cents and 10 EUR, if some of them say ARM do not let them confuse you as the STM8 is very far away from an ARM cpu.

    And yes they all show a MicroUSB port on them, but this is for nothing more then to power this board. For Programming you need something called an STLink

    The STLink v2

    The STLink v2 is a small stm32 based Programmer for STM8 and also STM32, they are all based on the Reference design by ST but way cheaper. And as the Design and Firmware was made opensource china created these cheap USB Sticks so you do not need to buy a 50 EUR STLink Original.

    Again, if you don't have one search for "stlink v2" and you should see listings starting at 2 EUR.

    Software

    sdcc

    First you need some software, on a Ubuntu >=15.04 you just need to install sdcc, the small device c compiler, a compiler that supports the old 8051, zilog z80, PIC16, a lot more and for this tutorial most important the STM8

    sudo apt-get install sdcc

    Just to be sure that your installed version of sdcc supports the stm8 you can check the version string which should contain stm8

    sdcc --version
     SDCC : mcs51/z80/z180/r2k/r3ka/gbz80/tlcs90/ds390/TININative/ds400/hc08/s08/stm8 3.4.0 #8981 (Jul 12 2014) (Linux)

    published under GNU General Public License (GPL)

    stm8flash

    The next software you need is the stm8flash software that you need to fetch from github

    git clone https://github.com/vdudouyt/stm8flash.git
    cd stm8flash
    make

    If you want to install the stm8flash software globally to you system just run "sudo make install" after make finished. This will save you from typing the full path to stm8flash over and over again.

    The first steps (and what you will most probably stumble upon)

    When you get your fresh STM8S103F3 Board from China, they are most probably in a "locked mode" This will show up when you want to program them as an error message

    Is it locked?

    sudo stm8flash -c stlinkv2 -p "stm8s103f3" -w blinky.ihx
     Determine FLASH area
     Writing Intel hex file 182 bytes at 0x8000... Tries exceeded

    There is a pretty simple fix for this found in the stm8flash issues Thos who are interested in what all the 00 and ff mean, can go to the datasheet page 45 and read about the "option bytes"

    echo "00 00 ff 00 ff 00 ff 00 ff 00 ff" | xxd -r -p > factory_defaults.bin
    stm8flash -c stlinkv2 -p stm8s103f3 -s opt -w factory_defaults.bin

    Blink the LED

    And now the minimal code needed to blink an LED on your super cheap development board. The LED is connected to Pin B5, which means Port B, pin 5

    ledblink.c

    // Port B data output latch register, for setting pins HIGH or LOW)
    #define PB_ODR *(unsigned char*)0x5005
    // Port B data direction register, for setting pins as INPUT or OUTPUT 
    #define PB_DDR *(unsigned char*)0x5007
    // Port B control register 1
    #define PB_CR1 *(unsigned char*)0x5008
    
    int main() {
     int d;
     // Configure pins
     PB_DDR = 0x20; // 0x20(00100000) pin 5 set to 1 -> setting it as OUTPUT 
     PB_CR1 = 0x20; // 0x20(00100000) pin 5 set to 1 -> setting it as PUSH-PULL Mode (only when configured as output)
     // Loop
     do {
     PB_ODR ^= 0x20; // 0x20(00100000) pin 5 XOR/toggle between HIGH and LOW
     for(d = 0; d < 29000; d++) {}
     } while(1);
    }

    Push–pull output (Wikipedia)

    Now we need to compile this file

    sdcc -lstm8 -mstm8 --out-fmt-ihx ledblink.c

    SDCC has now compiled our C code into a "ledblink.ihx" file that can be uploaded to our devboard.

    sudo stm8flash -c stlinkv2 -p stm8s103f3 -w ledblink.ihx
     Determine FLASH area
     Writing Intel hex file 189 bytes at 0x8000... OK
     Bytes written: 189

    Tada, now you have a blinking LED on your STM8 dev board.

    Links

    Read more »

View page
View all

Share this profile

Share

Bits

Log In/Sign up to comment

Become a Hackaday.io Member

Create an account to leave a comment. Already have an account? Log In.

Jasper Sikken wrote 09/17/2018 at 06:41 point

Are you sure? yes | no

Dr. Cockroach wrote 04/15/2018 at 15:58 point

Good afternoon WooDWorkeR and thank you for liking my Cardboard Relay project :-)

Are you sure? yes | no

Craig Hissett wrote 04/15/2018 at 14:39 point

Thanks for liking #DINternet mate!

Check out #Flask Jukebox and #Digibone if you haven't already ;-)

Are you sure? yes | no

Christopher Bietz wrote 03/13/2016 at 17:48 point

"Now on Hackaday.io: WooDWorkeR has added a new log"
Very punny, hrhr

Are you sure? yes | no

Stefan Lochbrunner wrote 11/05/2015 at 17:40 point

Thanks for following! :)

The #c-base protothing is pretty neat, one question though: Can it also be used as a beer coaster? ;P

Are you sure? yes | no

WooDWorkeR wrote 11/05/2015 at 17:46 point

nope, to small and whats more important - to rare :D

Are you sure? yes | no

Stefan Lochbrunner wrote 11/05/2015 at 18:43 point

That's too bad ;)

Are you sure? yes | no

WooDWorkeR wrote 11/05/2015 at 19:10 point

i'm working on rev-C, after that is rev-c_ then C_, cc, cC, CC :D

Are you sure? yes | no

Eric Hertz wrote 10/07/2015 at 12:45 point

Woot! Thanks for the follow!

Are you sure? yes | no

Stefan Lochbrunner wrote 10/06/2015 at 09:04 point

Thanks for skulling!

Are you sure? yes | no

Become cool instantly

like WooDWorkeR and many others

AltStyle によって変換されたページ (->オリジナル) /