diff options
author | Christian Pointner <equinox@spreadspace.org> | 2017-08-26 03:41:05 +0200 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2017-08-26 03:41:05 +0200 |
commit | e40620cbe225b1a81c751b1344a46e34eec16d2b (patch) | |
tree | d08e2124eee11370fb8fd4d81a852f9b8c864f82 | |
parent | rename external lib stdperiph to spl (diff) |
added stm8s-discovery board and some more init fixup
-rw-r--r-- | README | 31 | ||||
-rw-r--r-- | blink/Makefile | 4 | ||||
-rw-r--r-- | blink/blink.c | 3 | ||||
-rw-r--r-- | defines.mk | 15 | ||||
-rw-r--r-- | include.mk | 3 | ||||
-rw-r--r-- | lib/led.c | 23 | ||||
-rw-r--r-- | lib/util.c | 35 | ||||
-rw-r--r-- | lib/util.h | 29 |
8 files changed, 123 insertions, 20 deletions
@@ -6,6 +6,37 @@ sdcc libusb-dev (for stm8flash) +udev example rules +================== + +STM8S-Discovery: +---------------- + +SUBSYSTEMS=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="3744", MODE:="0666", GROUP:="dialout", SYMLINK+="stlink_%n" + +The discovery board also emulates an USB mass storage device. However the +implementation is buggy and it doesn't really work with linux. It's best to +just ignore the usb-storage endpoints. You can do this temporarly using the +following command: + + # echo "0483:3744:i" >/sys/module/usb_storage/parameters/quirks + +To make this permanent, create a file '/etc/modprobe.d/stdiscovery.conf' with +the following content: + +<snip> +options usb-storage quirks=0483:3744:i +</snip> + +The changes will take effect on next reboot or after manually unloading the +usb-storage driver + + # modprobe -r usb_storage + +This might not work if there is another device connected that is or emulates +an USB storage device. + + Build ===== diff --git a/blink/Makefile b/blink/Makefile index 8790c50..9bf7eaf 100644 --- a/blink/Makefile +++ b/blink/Makefile @@ -21,9 +21,9 @@ ## NAME := blink -BOARD_TYPE := test +BOARD_TYPE := discovery OBJ := $(NAME).rel -LIBS := led +LIBS := util led EXTERNAL_LIBS := spl SPREADSTM8_PATH := .. diff --git a/blink/blink.c b/blink/blink.c index 42cd818..cce9026 100644 --- a/blink/blink.c +++ b/blink/blink.c @@ -22,10 +22,13 @@ #include <stm8s.h> +#include "util.h" #include "led.h" int main(void) { + cpu_init(); + swim_disable(); led_init(); led_off(); @@ -20,10 +20,14 @@ ## along with spreadspace stm8 utils. If not, see <http://www.gnu.org/licenses/>. ## -ifeq ($(BOARD_TYPE),test) +ifeq ($(BOARD_TYPE),discovery) MCU := stm8s105c6 - PROG := stm8flash + F_CPU := 16000000 SPL_MCU := STM8S105 + LED_CNT := 1 + LED_GPIO := GPIOD + LED_PINNUM := 0 + PROG := stm8flash endif CC = sdcc @@ -40,6 +44,13 @@ CFLAGS += -p$(MCU) # CFLAGS += --opt-code-size CFLAGS += -I$(LIB_DIR) CFLAGS += -D__BOARD_$(BOARD_TYPE)__ +CFLAGS += -DF_CPU=$(F_CPU)UL +ifdef LED_CNT + CFLAGS += -DLED_CNT=$(LED_CNT) + CFLAGS += -DLED_GPIO=$(LED_GPIO) + CFLAGS += -DLED_PINNUM=$(LED_PINNUM) +endif + ## Linker flags LDFLAGS = -mstm8 @@ -24,6 +24,9 @@ ifndef SPREADSTM8_PATH SPREADSTM8_PATH := .. endif include $(SPREADSTM8_PATH)/defines.mk +ifndef MCU +$(error Unknown board: '$(BOARD_TYPE)') +endif ## project-specific objects SRC := $(OBJ:%.rel=%.c) @@ -25,26 +25,17 @@ #include "led.h" -#if defined(__BOARD_test__) -#define NUM_LEDS 1 -#else -#define NUM_LEDS 0 +#ifndef LED_CNT +#define LED_CNT 0 #endif -#if defined(__BOARD_test__) -#define LED_DIR 1 -#else +#ifndef LED_DIR #define LED_DIR 0 #endif -#if defined(__BOARD_test__) -#define LED_GPIO GPIOD -#define LED_PINNUM 0 -#endif - void led_init(void) { -#if NUM_LEDS >= 1 +#if LED_CNT >= 1 led_off(); LED_GPIO->DDR |= 1<<LED_PINNUM; #endif @@ -52,7 +43,7 @@ void led_init(void) void led_on(void) { -#if NUM_LEDS >= 1 +#if LED_CNT >= 1 #if LED_DIR == 1 LED_GPIO->ODR |= 1<<LED_PINNUM; #else @@ -63,7 +54,7 @@ void led_on(void) void led_off(void) { -#if NUM_LEDS >= 1 +#if LED_CNT >= 1 #if LED_DIR == 1 LED_GPIO->ODR &= ~(1<<LED_PINNUM); #else @@ -74,7 +65,7 @@ void led_off(void) void led_toggle(void) { -#if NUM_LEDS >= 1 +#if LED_CNT >= 1 LED_GPIO->ODR ^= 1<<LED_PINNUM; #endif } diff --git a/lib/util.c b/lib/util.c new file mode 100644 index 0000000..9cc397c --- /dev/null +++ b/lib/util.c @@ -0,0 +1,35 @@ +/* + * spreadspace stm8 utils + * + * + * Copyright (C) 2013-2016 Christian Pointner <equinox@spreadspace.org> + * + * This file is part of spreadspace stm8 utils. + * + * spreadspace stm8 utils is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * spreadspace stm8 utils is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with spreadspace stm8 utils. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stm8s.h> + +#include "util.h" + +void cpu_init(void) +{ + CLK->CKDIVR = 0; +} + +void swim_disable(void) +{ + CFG->GCR = CFG_GCR_SWD; +} diff --git a/lib/util.h b/lib/util.h new file mode 100644 index 0000000..75e243e --- /dev/null +++ b/lib/util.h @@ -0,0 +1,29 @@ +/* + * spreadspace stm8 utils + * + * + * Copyright (C) 2013-2016 Christian Pointner <equinox@spreadspace.org> + * + * This file is part of spreadspace stm8 utils. + * + * spreadspace stm8 utils is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * spreadspace stm8 utils is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with spreadspace stm8 utils. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef SPREADSTM8_util_h_INCLUDED +#define SPREADSTM8_util_h_INCLUDED + +void cpu_init(void); +void swim_disable(void); + +#endif |