By Abdul Rehman
Assembly language programming is always a great tool to understand underlying architecture of microcontroller. It also helps us to use any microcontroller at it’s full potential. In today’s Article we are going to develop a hello world program and we will be using ST Visual develop IDE throughout our tutorial. We are also going to present some very useful links and helping material to better understand stm8 assembly language. So without wasting any further time let’s just dive into actual stuff.
We are going to target STM8S103F3P microcontroller and will be using stm8s blue pill board for this. You can get this development board via amazon or any other local store if available. I chooses this board because of its availability in our local store and because of it is very cost effective and cheap. If you find difficulty getting this board you can also purchase this microcontroller directly from ST website or you can choose some similar STM8S microcontroller board.
Although you may see USB connector on this board but this is only for powering up this board. This connector has no other functionality rather then providing power to board. There is also one Reset switch to reset microcontroller and one Power LED and one Test LED. Power LED, as it’s names suggest is just to indicate power and the TEST led is available for user to program according to their need. According to its schematic this LED is connected to PORTD pin 3 or PD3
We will try to target this pin for blinking this on board LED available for us to play with.
According to Datasheet of this microcontroller, STM8S103F3 has following features
To upload final object file into this microcontroller or to flash this development board we need a ST-LINK Utility and device. You should not assume that you are going to program this board like an Arduino board via USB cable.
If you are unable to figure out how to do this? Than in this blogpost about program stm8 board with st-link v2, writer had explained it very well.
Now its time to write a quick code and see something actually happening. So first of all just download and install STVD for stm8. After installing you will see its shortcut on desktop and also in start menu. So just go and start simply you do with any other application. Now Create a blank workspace and after creating a workspace, create a new empty project. While creating a project it will give option to select the compiler type and in this dialog box you need to select ST Assembler Linker option. After selecting this the editor will automatically add a path you do not need to change that path.
In microcontroller selection screen, you need to select STM8S103F3P for our development board. You can choose other device if your board comes with any other STM8 Chip. Once you are done the project window will show three auto generated directories. There is main.asm file in source Files Directory. You can remove all the lengthy pre-written code and just come up with following simple and clean code.
You need to understand one very basic thing about STM8 assembly language
indentation here matters a lot. Indentation in STM8 assembly denotes as columns and according to reference manual the first column is denoted as Labels. So if you put any opcode in first column then that will be treated as label if it meet labels criteria or will be prompted as error during compile time.
This label at first line tells assembler linker that the targeted platform is of STM8 microcontroller family. Next segment ‘rom’ Line tells to store code in rom. Segment opcode tells where to place it and we are telling assembler to put code at very beginning of the Flash ROM. The ‘rom’ directive is defined in mapping.asm file like this
WORDS ; The following addresses are 16 bits long segment byte at 8080-9FFF 'rom'
So according to this definition our code will be started at address 0x8080. It’s like ORG directive in other kind of Assembly programming.
There must be an END directive at the last line of code and there must be a line break after that directive. This directive tells assembler that the code has been ended and whenever assembler find this directive it will stop compiling further code even if present.
This instruction is short form of JUMP RELATIVE ALWAYS. This is force jump instruction and tells controller to jump over specific relative address always. Whenever controller find this instruction it will jump to the provided address without any hesitation and without caring anything in code. So according to this definition it expect one operator which is relative address of a location to jump over. We can provide label here as we did in our code. So our final code looks something like this so far
Code language: PHP (php)
stm8/ #include "mapping.inc" segment 'rom' MLOOP NOP JRA MLOOP end
Now its time to compile our code and see if we are able to compile without facing and error or warnings. To compile our code just press F7 key or go to build menu and selection Build option. If everything goes well this will show success message something like this
So that’s it for today’s tutorial. If you followed along this tutorial and end up with a successful compile message, Congratulations than, You had properly setup your development environment and written your first hello world program. This program will do one very important work for your microcontroller which is to keep it busy and stuck it to one loop called infinite loop in Embedded Systems. In our next tutorial we will blink LED and see things happening in our Development board.
27 April 2021
10 February 2021
03 February 2021
27 January 2021
FYP Solutions Powered By Impressive Business WordPress Theme