Skip to content

Instantly share code, notes, and snippets.

@tomazas
Last active March 5, 2016 17:04
Show Gist options
  • Save tomazas/88ac5c6997c98f527414 to your computer and use it in GitHub Desktop.
Save tomazas/88ac5c6997c98f527414 to your computer and use it in GitHub Desktop.
LED blinky example for STM8 using SDCC compiler
@echo off
:: configuration
SET CC=sdcc
SET CFLAGS=-mstm8
SET INCLUDEPATH=C:/st_toolset/STM8S_StdPeriph_Lib/Libraries/STM8S_StdPeriph_Driver/inc
:: mcu type defined in stm8s.h file
SET DEFINES=STM8S103
SET SOURCE=leds
SET OUTPUT_DIR=build
:test_prerequisites
call %CC% -v || goto :failed
goto :clean
:failed
echo ERROR - SDCC compiler is not installed or not included in system PATH!
goto :exit
:clean
echo INFO - Cleaning up...
rm -Rf %OUTPUT_DIR%
rm -f %SOURCE%.hex
echo INFO - Cleanup complete
:compile
echo INFO - Compiling...
mkdir %OUTPUT_DIR%
%CC% %CFLAGS% -I%INCLUDEPATH% -D %DEFINES% -o %OUTPUT_DIR%/ %SOURCE%.c || goto :compile_failed
echo INFO - Compile complete
goto :makehex
:compile_failed
echo ERROR - Compilation failure
goto :exit
:makehex
echo INFO - Generating HEX file...
packihx %OUTPUT_DIR%/%SOURCE%.ihx > %SOURCE%.hex
echo INFO - Generate complete
echo INFO - Done. OK
:exit
pause
#include "stm8s.h"
#include "stm8s_gpio.h"
volatile void delay(volatile uint32_t t)
{
while(t--);
}
int main( void )
{
// data direction PB5 - output
GPIOB->DDR |= GPIO_PIN_5;
// control register
GPIOB->CR1 |= GPIO_PIN_5;
// data output latch register
GPIOB->ODR |= GPIO_PIN_5;
while(1)
{
delay(20000); // wait approx. 1 second
GPIOB->ODR ^= GPIO_PIN_5; // turn PB5 LED on/off (toggle state)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment