Skip to content

Instantly share code, notes, and snippets.

@mishazawa
Last active October 16, 2020 12:00
Show Gist options
  • Select an option

  • Save mishazawa/ce34ecc047d23ce3df56a40ab9162a2c to your computer and use it in GitHub Desktop.

Select an option

Save mishazawa/ce34ecc047d23ce3df56a40ab9162a2c to your computer and use it in GitHub Desktop.
STM8L setup

STM8L discovery setup

Ubuntu deps and OpenOCD

sudo apt-get install libusb-1.0-0-dev texinfo openocd

SPL (standart peripheral lib)

Downloaded from st.com

SDCC (small device c compiler)

Downloaded from sourceforge.

tar -xjf ./<SDCC archive>
cd sdcc
sudo cp -r * /usr/local

stm8flash

Builded from source.

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

stm8-gdb

Downloaded from https://stm8-binutils-gdb.sourceforge.io/

./patch_binutils.sh
./configure_binutils.sh
cd binutils-2.30
make
sudo make install

Check USB programmer

st-info --probe

Test USB programmer

st-flash --debug read dummy.file 0 256

Connection USB -> STM8L

image

Unlock board

stm8flash -c stlinkv2 -p stm8l152?6 -w

Flush all data

echo "00 00 ff 00 ff 00 ff 00 ff 00 ff" | xxd -r -p > reset.bin
stm8flash -c stlinkv2 -p stm8l152?6 -s opt -w reset.bin

Write programm

stm8flash -c stlinkv2 -p stm8l152?6 -w <program hex>

Run debug

openocd -f interface/stlink-dap.cfg -f target/stm8l152.cfg -c "init" -c "reset init"
stm8-gdb <file elf> --tui
#######
# makefile for STM8*_StdPeriph_Lib and SDCC compiler
#
# note: paths in this Makefile assume unmodified SPL folder structure
#
# usage:
# 1. if SDCC not in PATH set path -> CC_ROOT
# 2. set correct STM8 device -> DEVICE
# 3. set project paths -> PRJ_ROOT, PRJ_SRC_DIR, PRJ_INC_DIR
# 4. set SPL paths -> SPL_ROOT
# 5. add required SPL modules -> SPL_SOURCE
# 6. add required STM8_EVAL modules -> EVAL_SOURCE, EVAL_COMM_SOURCE, EVAL_STM8L1526_SOURCE, EVAL_STM8L1528_SOURCE
#
#######
# STM8 device (for supported devices see stm8l15x.h)
DEVICE=STM8L15X_MD
# set compiler path & parameters
CC_ROOT =
CC = sdcc
CFLAGS = -lstm8 -mstm8 --opt-code-size --std-sdcc99 --nogcse --all-callee-saves --debug --verbose --stack-auto --fverbose-asm --float-reent --no-peep
# set output folder and target name
OUTPUT_DIR = ./$(DEVICE)
TARGET = $(OUTPUT_DIR)/$(DEVICE).ihx
# set project folder and files (all *.c)
PRJ_ROOT = .
PRJ_SRC_DIR = $(PRJ_ROOT)
PRJ_INC_DIR = $(PRJ_ROOT)
PRJ_SOURCE = $(notdir $(wildcard $(PRJ_SRC_DIR)/*.c))
PRJ_OBJECTS := $(addprefix $(OUTPUT_DIR)/, $(PRJ_SOURCE:.c=.rel))
# set SPL paths
SPL_ROOT = ..
SPL_SRC_DIR = $(SPL_ROOT)/Libraries/STM8L15x_StdPeriph_Driver/src
SPL_INC_DIR = $(SPL_ROOT)/Libraries/STM8L15x_StdPeriph_Driver/inc
SPL_SOURCE = stm8l15x_gpio.c # include required sources from SPL
SPL_OBJECTS := $(addprefix $(OUTPUT_DIR)/, $(SPL_SOURCE:.c=.rel))
# collect all include folders
INCLUDE = -I$(PRJ_SRC_DIR) -I$(SPL_INC_DIR)
# collect all source directories
VPATH=$(PRJ_SRC_DIR):$(SPL_SRC_DIR)
.PHONY: clean
all: $(OUTPUT_DIR) $(TARGET)
$(OUTPUT_DIR):
mkdir -p $(OUTPUT_DIR)
$(OUTPUT_DIR)/%.rel: %.c
$(CC) $(CFLAGS) $(INCLUDE) -D$(DEVICE) -c $?
$(OUTPUT_DIR)/%.rel: %.c
$(CC) $(CFLAGS) $(INCLUDE) -D$(DEVICE) -c $? -o $@
$(TARGET): $(PRJ_OBJECTS) $(SPL_OBJECTS)
$(CC) $(CFLAGS) -o $(TARGET) $^
clean:
rm -fr $(OUTPUT_DIR)
@mishazawa

Copy link
Copy Markdown
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment