Template Makefile project for STM8 SDCC builds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CC = sdcc | |
AR = sdar | |
BUILD_DIR = ./build | |
SRC_DIR = ./src | |
INC_DIR = ./inc | |
CHIP = STM8S103 | |
CFLAGS = -mstm8 -I$(INC_DIR) -D$(CHIP) -c | |
ARFLAGS = -rc | |
STDLIB_URL = http://www.st.com/st-web-ui/static/active/en/st_prod_software_internet/resource/technical/software/firmware/stsw-stm8069.zip | |
STDLIB_ZIP = stm8s_stdlib.zip | |
BUILD_ARTIFACTS = $(BUILD_DIR) $(SRC_DIR) $(INC_DIR) $(STDLIB_ZIP) | |
OBJLIB = stm8s_stdlib.a | |
SRC_FILES = stm8s_awu.c stm8s_beep.c stm8s_clk.c stm8s_exti.c stm8s_flash.c stm8s_gpio.c stm8s_i2c.c stm8s_itc.c stm8s_iwdg.c stm8s_rst.c stm8s_spi.c stm8s_tim1.c stm8s_wwdg.c | |
ifeq ($(CHIP), $(filter $(CHIP), STM8S105 STM8S005 STM8S103 STM8S003 STM8S903 STM8AF626x)) | |
SRC_FILES += stm8s_adc1.c | |
endif | |
ifeq ($(CHIP), $(filter $(CHIP), STM8S208 STM8S207 STM8S007 STM8AF52Ax STM8AF62Ax)) | |
SRC_FILES += stm8s_adc2.c | |
endif | |
ifeq ($(CHIP), $(filter $(CHIP), STM8S208 STM8AF52Ax)) | |
SRC_FILES += stm8s_can.c | |
endif | |
ifneq ($(CHIP), STM8S903) | |
SRC_FILES += stm8s_tim2.c | |
endif | |
ifeq ($(CHIP), $(filter $(CHIP), STM8S208 STM8S207 STM8S007 STM8S105 STM8S005 STM8AF52Ax STM8AF62Ax STM8AF626x)) | |
SRC_FILES += stm8s_tim3.c | |
endif | |
ifneq ($(CHIP), STM8S903) | |
SRC_FILES += stm8s_tim4.c | |
endif | |
ifeq ($(CHIP), STM8S903) | |
SRC_FILES += stm8s_tim5.c stm8s_tim6.c | |
endif | |
ifeq ($(CHIP), $(filter $(CHIP), STM8S208 STM8S207 STM8S007 STM8S103 STM8S003 STM8S903 STM8AF52Ax STM8AF62Ax)) | |
SRC_FILES += stm8s_uart1.c | |
endif | |
ifeq ($(CHIP), $(filter $(CHIP), STM8S105 STM8S005 STM8AF626x)) | |
SRC_FILES += stm8s_uart2.c | |
endif | |
ifeq ($(CHIP), $(filter $(CHIP), STM8S208 STM8S207 STM8S007 STM8AF52Ax STM8AF62Ax)) | |
SRC_FILES += stm8s_uart3.c | |
endif | |
OBJ_FILES = $(SRC_FILES:%.c=%.rel) | |
all: $(OBJLIB) | |
$(STDLIB_ZIP): | |
@echo "---- Downloading STM8 StdLib" | |
wget -O $(STDLIB_ZIP) $(STDLIB_URL) | |
unzip: $(STDLIB_ZIP) | |
@echo "---- Unzipping STM8 StdLib contents" | |
unzip -j -o $(STDLIB_ZIP) 'STM8S_StdPeriph_Lib/Libraries/STM8S_StdPeriph_Driver/inc/*' -d $(INC_DIR) | |
unzip -j -o $(STDLIB_ZIP) 'STM8S_StdPeriph_Lib/Libraries/STM8S_StdPeriph_Driver/src/*' -d $(SRC_DIR) | |
unzip -j -o $(STDLIB_ZIP) 'STM8S_StdPeriph_Lib/Project/STM8S_StdPeriph_Template/stm8s_conf.h' | |
patch: | |
@echo "---- Patching STM8 StdLib for SDCC" | |
patch --binary $(INC_DIR)/stm8s.h < stm8s.h.patch | |
patch --binary $(SRC_DIR)/stm8s_itc.c < stm8s_itc.c.patch | |
patch --binary stm8s_conf.h < stm8s_conf.h.patch | |
mv stm8s_conf.h inc/stm8s_conf.h | |
prepare: unzip patch | |
@echo "---- Creating build dir" | |
mkdir -p $(BUILD_DIR) | |
clean: | |
@echo "---- Cleaning up directory" | |
rm -rf $(BUILD_ARTIFACTS) | |
$(OBJLIB): $(addprefix $(BUILD_DIR)/, $(OBJ_FILES)) | |
@echo "---- Linking *.rel files into library" | |
$(AR) $(ARFLAGS) $(OBJLIB) $^ | |
$(BUILD_DIR)/%.rel: $(SRC_DIR)/%.c | |
$(CC) -o $@ $(CFLAGS) $^ | |
$(SRC_DIR)/%.c: prepare | |
.PHONY: all unzip patch prepare clean | |
.PRECIOUS: $(SRC_DIR)/%.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- inc/stm8s.h 2014-09-19 12:45:10.426176737 +0200 | |
+++ stm8s.h.sdcc 2014-09-19 12:20:51.914610927 +0200 | |
@@ -75,6 +75,8 @@ | |
#define _RAISONANCE_ | |
#elif defined(__ICCSTM8__) | |
#define _IAR_ | |
+#elif defined(SDCC) | |
+ #define _SDCC_ | |
#else | |
#error "Unsupported Compiler!" /* Compiler defines not found */ | |
#endif | |
@@ -127,7 +129,14 @@ | |
#else /* STM8S903, STM8S103, STM8S003, STM8S105, STM8AF626x */ | |
/*!< Used with memory Models for code less than 64K */ | |
#define MEMCPY memcpy | |
- #endif /* STM8S208 or STM8S207 or STM8S007 or STM8AF62Ax or STM8AF52Ax */ | |
+ #endif /* STM8S208 or STM8S207 or STM8S007 or STM8AF62Ax or STM8AF52Ax */ | |
+#elif defined (_SDCC_) | |
+ #define FAR __far | |
+ // Apparently, SDCC gets confused by __near | |
+ #define NEAR | |
+ #define TINY __tiny | |
+ #define EEPROM __eeprom | |
+ #define CONST const | |
#else /*_IAR_*/ | |
#define FAR __far | |
#define NEAR __near | |
@@ -195,6 +204,9 @@ | |
#define __O volatile /*!< defines 'write only' permissions */ | |
#define __IO volatile /*!< defines 'read / write' permissions */ | |
+#if defined(_SDCC_) | |
+#include <stdint.h> | |
+#else | |
/*!< Signed integer types */ | |
typedef signed char int8_t; | |
typedef signed short int16_t; | |
@@ -204,6 +216,7 @@ | |
typedef unsigned char uint8_t; | |
typedef unsigned short uint16_t; | |
typedef unsigned long uint32_t; | |
+#endif | |
/*!< STM8 Standard Peripheral Library old types (maintained for legacy purpose) */ | |
@@ -2615,6 +2628,15 @@ | |
#define trap() {_asm("trap\n");} /* Trap (soft IT) */ | |
#define wfi() {_asm("wfi\n");} /* Wait For Interrupt */ | |
#define halt() {_asm("halt\n");} /* Halt */ | |
+#elif defined(_SDCC_) | |
+ #define enableInterrupts() {__asm__("rim\n");} /* enable interrupts */ | |
+ #define disableInterrupts() {__asm__("sim\n");} /* disable interrupts */ | |
+ #define rim() {__asm__("rim\n");} /* enable interrupts */ | |
+ #define sim() {__asm__("sim\n");} /* disable interrupts */ | |
+ #define nop() {__asm__("nop\n");} /* No Operation */ | |
+ #define trap() {__asm__("trap\n");} /* Trap (soft IT) */ | |
+ #define wfi() {__asm__("wfi\n");} /* Wait For Interrupt */ | |
+ #define halt() {__asm__("halt\n");} /* Halt */ | |
#else /*_IAR_*/ | |
#include <intrinsics.h> | |
#define enableInterrupts() __enable_interrupt() /* enable interrupts */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- stm8s_conf.h 2014-10-21 17:31:56.000000000 +0200 | |
+++ stm8s_conf_assert.h 2016-08-17 23:39:20.000000000 +0200 | |
@@ -90,7 +90,7 @@ | |
/* Exported constants --------------------------------------------------------*/ | |
/* Uncomment the line below to expanse the "assert_param" macro in the | |
Standard Peripheral Library drivers code */ | |
-#define USE_FULL_ASSERT (1) | |
+// #define USE_FULL_ASSERT (1) | |
/* Exported macro ------------------------------------------------------------*/ | |
#ifdef USE_FULL_ASSERT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- src/stm8s_itc.c 2014-09-19 12:45:04.266068330 +0200 | |
+++ stm8s_itc.c 2014-09-19 12:51:29.280254183 +0200 | |
@@ -49,6 +49,9 @@ | |
return; /* Ignore compiler warning, the returned value is in A register */ | |
#elif defined _RAISONANCE_ /* _RAISONANCE_ */ | |
return _getCC_(); | |
+#elif defined ( _SDCC_ ) | |
+ __asm__("push cc"); | |
+ __asm__("pop a"); | |
#else /* _IAR_ */ | |
asm("push cc"); | |
asm("pop a"); /* Ignore compiler warning, the returned value is in A register */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SDCC = sdcc | |
STM8FLASH = stm8flash | |
STLINK=stlinkv2 | |
CHIP = STM8S103 | |
CHIP_TYPE = STM8S103F3 | |
CHIP_TYPE_LCASE = $(shell echo $(CHIP_TYPE) | tr '[:upper:]' '[:lower:]') | |
CFLAGS = -lstm8 -mstm8 -L./libsrc/build/ -l./libsrc/stm8s_stdlib.a -I./libsrc/inc -D$(CHIP) -DUSE_STDPERIPH_DRIVER | |
MAIN_SOURCE = launcher | |
SOURCES = lcd slider keypad | |
all: clean build | |
build: $(MAIN_SOURCE:=.ihx) | |
$(MAIN_SOURCE:=.ihx): $(MAIN_SOURCE:=.rel) $(SOURCES:=.rel) | |
$(SDCC) $(CFLAGS) --out-fmt-ihx $(MAIN_SOURCE:=.rel) $(SOURCES:=.rel) | |
clean: | |
rm -f *.ihx *.lk *.lst *.map *.rel *.rst *.sym *.asm | |
flash: $(MAIN_SOURCE:=.ihx) | |
$(STM8FLASH) -c $(STLINK) -p $(CHIP_TYPE_LCASE) -w $(MAIN_SOURCE:=.ihx) | |
unlock: | |
echo "00 00 ff 00 ff 00 ff 00 ff 00 ff" | xxd -r -p > factory_defaults.bin | |
$(STM8FLASH) -c $(STLINK) -p $(CHIP_TYPE_LCASE) -s opt -w factory_defaults.bin | |
rm factory_defaults.bin | |
%.rel: %.c | |
$(SDCC) -c $(CFLAGS) $< | |
lib: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you