smt8 sdcc
brew install sdcc
brew install autoconf automake pkg-config libusb libusb-compat stlink
https://github.com/EMBEDONIX/stm8
roshbaby/stm8s-sdcc: STM8S Standard Peripheral Library Ported to SDCC for multiple STM8 targets
STM8S Programming · TG9541/stm8ef Wiki
STM8 development with Eclipse and macOS – nubix-Weblog
Setup Eclipse
Eclipse can be configured to allow development of C++ firmware cod for the STM8 with editing, flashing and debugging. There are some steps that are critical to get Eclipse to work with the STM8 board.
1. Install HomeBrew on Mac
- HomeBrew is used to comfortably install necessary tools over the command line
- only needed to be installed if not installed yet
- maybe ‘brew doctor’ shows errors that have to be fixed before using HomeBrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew update
brew doctor
- ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- brew update
- brew doctor
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew update
brew doctor
2. Setup of Programmer ST-Link/V2
- ST-LINK/V2 is a programmer and debugger for STM8 and STM32
- can be installed with HomeBrewn
brew install autoconf automake pkg-config libusb libusb-compat stlink
st-util -h
- brew install autoconf automake pkg-config libusb libusb-compat stlink
- st-util -h
brew install autoconf automake pkg-config libusb libusb-compat stlink
st-util -h
Stop!
st-util does not recognize the DISCOVERY board and has problems using it. A quick research shows that the tool only supports the SWD-mode for STM32-MCU’s. The STM8-MCU’s need the SWIM-mode. This mode is only usable with the tool stm8-flash that is not well-maintained. This tool does not allow debugging at the moment. Conclusion: Debugging of STM8 code is not usable under Linux or Mac OS X.
3. Install SDCC Cross-Compiler
- SDCC is a free cross-complier for multiple microcontrollers with great compatibility and able to generate excellent results.
brew install sdcc
sdcc -v
- brew install sdcc
- sdcc -v
brew install sdcc
sdcc -v
4. Install STM8Flash
git clone https://github.com/vdudouyt/stm8flash.git
cd stm8flash
make
make install
cd ..
rm -R stm8flash
stm8flash
5. Test if the STM8L-DISCOVERY board is responding
stm8flash -c stlinkv2 -p stm8l152?6 -r test.ihx
stm8flash -c stlinkv2 -p stm8s003f3 -r blinky.ihx
stm8flash -c Flash examples: ./stm8flash -c stlinkv2 -p stm8s003f3 -r blinky.ihx EEPROM examples: ./stm8flash -c stlinkv2 -p stm8s003f3 -s eeprom -r ee.bin # 读取文件 echo "00 00 ff 02 fd 00 ff 00 ff 00 ff" | xxd -r -p > option_bytes.bin
The supported file types are Intel Hex, Motorola S-Record and Raw Binary. The type is detected by the file extension.
./stm8flash -c stlinkv2 -p stm8s003f3 -w blinky.ihx
./stm8flash -c stlinkv2 -p stm8s003f3 -s eeprom -w ee.bin # 写入文件
./stm8flash -c stlinkv2 -p stm8s003f3 -s eeprom -v ee.bin # 验证文件修改OPT选项
stm8flash -c stlinkv2 -p stm8s003f3 -s opt -w option_bytes.bin
stm8flash -c stlinkv2 -p stm8s003f3 -s flash -w voliera.ihxexport PATH := $(PATH):$(HOME)/local/sdcc/bin
MCU = stm8s003f3
ARCH = stm8
F_CPU ?= 2000000
TARGET ?= main.ihx
#LIBDIR = ../../inc
INCDIR = ../../inc
SRCDIR = ../../src
SRCS := $(wildcard *.c $(SRCDIR)/*.c)
ASRCS := $(wildcard *.s $(SRCDIR)/*.s)
OBJS = $(SRCS:.c=.rel)
OBJS += $(ASRCS:.s=.rel)
CC = sdcc
LD = sdld
AS = sdasstm8
OBJCOPY = sdobjcopy
ASFLAGS = -plosgff
CFLAGS = -m$(ARCH) -p$(MCU) --std-sdcc11
CFLAGS += -DF_CPU=$(F_CPU)UL -I. -I$(INCDIR)
CFLAGS += --stack-auto --noinduction --use-non-free
## Extra optimization rules - use with care
#CFLAGS += --peep-file $(LIBDIR)/util/extra.def
LDFLAGS = -m$(ARCH) -l$(ARCH) --out-fmt-ihx
all: $(TARGET) size
$(TARGET): $(OBJS)
$(CC) $(LDFLAGS) $(OBJS) -o $@
%.rel: %.c
$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
%.rel: %.s
$(AS) $(ASFLAGS) $<
size:
@$(OBJCOPY) -I ihex --output-target=binary $(TARGET) $(TARGET).bin
@echo "----------"
@echo "Image size:"
@stat -L -c %s $(TARGET).bin
flash: $(TARGET)
stm8flash -c stlinkv2 -p $(MCU) -w $(TARGET)
clean:
rm -f *.map *.asm *.rel *.ihx *.o *.sym *.lk *.lst *.rst *.cdb *.bin
.PHONY: clean all flash