Skip to content

Commit 17e2d08

Browse files
committed
add uart examples, add new sduino pinout
1 parent 4104ae9 commit 17e2d08

19 files changed

Lines changed: 899 additions & 11 deletions

File tree

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,13 @@
66
*.hex
77
*.exe
88
tags
9+
# ignore files generated by sdcc:
10+
*.cdb
11+
*.ihx
12+
*.asm
13+
*.lst
14+
*.rel
15+
*.rst
16+
*.sym
17+
*.lk
18+
*.map

README.md

Lines changed: 244 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
# STM8 breakout board
22

3+
CPU STM8S103F3P6
34
Pins 1:1 vom STM8S103F3P6 auf die Pinleisten rausgeführt.
45
LED Test (rot) an PB5 (Pin 11)
56

7+
Anschluss an mein Flashtool:
8+
9+
3V3 1 2
10+
SWIM 2 5
11+
GND 3 7
12+
NRST 4 9
13+
614

715
## Compiler
816

@@ -31,6 +39,122 @@ muss entsprechend angepasst werden. Am Ende hochladen:
3139
stm8flash -c stlinkv2 -p stm8s103?3 -w blinky.ihx
3240

3341

42+
## Infos und Application Notes
43+
44+
STM8AF Flash programming manual (PM0051)
45+
STM8 SWIM protocol and debug manual (UM0470)
46+
47+
RS-232-Beispiel:
48+
https://sourceforge.net/p/oggstreamer/oggs-stm8-firmware-001/ci/master/tree/rx_ringbuffer.c
49+
50+
51+
### Anmerkungen zu SDCC
52+
53+
Befehl '_ _ critical{..}' sollte eigentlich den vorherigen Interrupt-Zustand
54+
wiederherstellen, es wird aber einfach ein festes Paar sim/rim produziert.
55+
56+
Compilieren: braucht libboost-graph:
57+
libboost-graph1.54-dev - generic graph components and algorithms in C++
58+
libboost-graph1.54.0 - generic graph components and algorithms in C++
59+
libboost-graph1.55-dev - generic graph components and algorithms in C++
60+
libboost-graph1.55.0 - generic graph components and algorithms in C++
61+
62+
## ST Standard Library
63+
64+
git clone https://github.com/g-gabber/STM8S_StdPeriph_Driver.git
65+
git clone https://github.com/gicking/SPL_2.2.0_SDCC_patch.git
66+
cp ../STM8S_SPL_2.2.0/Libraries/STM8S_StdPeriph_Driver/inc/stm8s.h .
67+
patch -p1 < ../SPL_2.2.0_SDCC_patch/STM8_SPL_v2.2.0_SDCC.patch
68+
cp -av ../STM8S_StdPeriph_Lib/Project/STM8S_StdPeriph_Template/stm8s_conf.h .
69+
cp -av ../STM8S_StdPeriph_Lib/Project/STM8S_StdPeriph_Template/stm8s_it.h .
70+
71+
.rel-Files sind die Objekt-Files .o
72+
73+
Zusätzlich nötiger Patch in stm8s_itc.c:
74+
75+
--- stm8s_itc.c~ 2014-10-21 17:32:20.000000000 +0200
76+
+++ stm8s_itc.c 2016-12-11 21:56:41.786048494 +0100
77+
@@ -55,9 +55,12 @@
78+
return; /* Ignore compiler warning, the returned value is in A register */
79+
#elif defined _RAISONANCE_ /* _RAISONANCE_ */
80+
return _getCC_();
81+
-#else /* _IAR_ */
82+
+#elif defined _IAR_ /* _IAR_ */
83+
asm("push cc");
84+
asm("pop a"); /* Ignore compiler warning, the returned value is in A register */
85+
+#else /* _SDCC_ */
86+
+ __asm__("push cc");
87+
+ __asm__("pop a"); /* Ignore compiler warning, the returned value is in A register */
88+
#endif /* _COSMIC_*/
89+
}
90+
91+
Dann klappt es mit diesem Makefile für den stm8s103:
92+
93+
CC=sdcc
94+
AR=sdar
95+
CFLAGS=-c -mstm8 -DSTM8S103 -I ../inc --opt-code-size -I.
96+
LDFLAGS=-rc
97+
SOURCES= \
98+
stm8s_adc1.c stm8s_awu.c stm8s_beep.c stm8s_clk.c \
99+
stm8s_exti.c stm8s_flash.c stm8s_gpio.c stm8s_i2c.c \
100+
stm8s_itc.c stm8s_iwdg.c stm8s_rst.c stm8s_spi.c \
101+
stm8s_tim1.c stm8s_tim2.c stm8s_tim4.c stm8s_uart1.c \
102+
stm8s_wwdg.c
103+
104+
OBJECTS=$(SOURCES:.c=.o)
105+
OBJECTS_LINK=$(SOURCES:.c=.rel)
106+
EXECUTABLE=stm8s.lib
107+
108+
all: $(SOURCES) $(EXECUTABLE)
109+
110+
$(EXECUTABLE): $(OBJECTS)
111+
$(AR) $(LDFLAGS) $(EXECUTABLE) $(OBJECTS_LINK)
112+
113+
.c.o:
114+
$(CC) $(CFLAGS) $< -o $@
115+
116+
clean:
117+
rm -f *.lib *.rst *.rel *.lst *.ihx *.sym *.asm *.lk *.map
118+
rm -f $(EXECUTABLE)
119+
120+
Diese Library kann dann in blink_spl oder uart_spl verwendet werden.
121+
Leider werden weiterhin stm8s_conf.h und stm8s_it.h benötigt.
122+
123+
Der Linker entfernt aber keine unbenutzten Funktionen, sondern nur
124+
ungenutzte Module (=Sammlungen, die aus einer Quell-Datei entstanden sind).
125+
Wird eine Funktion benötigt, kommt das ganze Modul mit
126+
**=> In einer Library besser jede Funktion in eine eigene Datei **
127+
128+
Erklärung wie zumindest die Interrupt-Vektoren in die eigene Datei kommen
129+
können:
130+
http://richs-words.blogspot.de/2010/09/stm8s-interrupt-handling.html
131+
132+
133+
### Interrupts
134+
135+
Namen definiert in stm8s_itc.h
136+
Interrupt-Routine definieren:
137+
138+
/* UART1 TX */
139+
void UART1_TX_IRQHandler(void) __interrupt(ITC_IRQ_UART1_TX)
140+
{
141+
}
142+
143+
Jetzt muss noch das passende IRQ-Enable-Flag gesetzt werden und Interrupt
144+
generell freigegeben werden, also hier:
145+
146+
UART1_ITConfig(UART1_IT_TXE, ENABLE);
147+
enableInterrupts();
148+
149+
Unklar ist, was die ITC-Priritäten bewirken. Es geht jedenfalls auch ohne:
150+
151+
ITC_DeInit();
152+
ITC_SetSoftwarePriority(ITC_IRQ_UART1_TX, ITC_PRIORITYLEVEL_2);
153+
154+
155+
156+
157+
34158

35159
## Programmer
36160

@@ -51,11 +175,51 @@ Belegung CN3 SWD:
51175
5 NRST
52176
6 SWO (=SWIM?)
53177

178+
Pinbelegung der Version im grünen Plastikgehäuse:
179+
180+
- +-----+
181+
T_JRST | 1 2| 3V3
182+
5V | 3 4| T_JTCK/T_SWCLK
183+
SWIM 5 6| T_JTMS/T_SWDIO
184+
GND | 7 8| T_JTDO
185+
SWIM RST| 9 10| T_JTDI
186+
- +-----+
187+
188+
Pinbelegung der Version im Metallgehäuse
189+
190+
- +-----+
191+
RST | 1 2| SWDIO
192+
GND | 3 4| GND
193+
SWIM 5 6| SWCLK
194+
3V3 | 7 8| 3V3
195+
5V | 9 10| 5V
196+
- +-----+
197+
198+
Notwendiger Eintrag in /etc/udev/rules.d/99-stlink.rules:
199+
200+
# ST-Link/V2 programming adapter
201+
202+
# ST-Link V1
203+
#SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device",
204+
ATTR{idVendor}=="0483", ATTR{idProduct}=="3744", MODE="0666", GROUP="plugdev"
205+
206+
# ST-Link/V2, the china adapter with the green plastic housing
207+
#SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ATTR{idVendor}=="0483", ATTR{idProduct}=="3748", MODE="0666"
208+
ATTR{idVendor}=="0483", ATTR{idProduct}=="3748", MODE="0666", GROUP="plugdev"
209+
210+
211+
212+
213+
## Anpassung der Beispielprogramme
214+
215+
blinky.c: Pinbelegung
54216

217+
uart.c: Pinbelegung (TX auf D5), RX ist dann D6.
218+
Es wird mit 1200 Baud gesendet => nur 2MHz statt 16MHz
55219

56220
## denkbare Arduino-Zuordnung
57221

58-
feste Kommunikationspins:
222+
a) feste Kommunikationspins:
59223
STM8 Arduino
60224
Pin Name Alt Pin Alt
61225
D6 RX Ain6 0 D0
@@ -67,7 +231,7 @@ C5 SCK 13 B5 LED
67231
B5 SDA LED 18 C4 Ain4
68232
B4 SCL 19 C5 Ain5
69233

70-
analog:
234+
b) analog:
71235
STM8 Arduino
72236
Pin Name Alt Pin Alt
73237
C4 Ain2
@@ -76,7 +240,7 @@ D3 Ain4
76240
(D5 Ain5 TX)
77241
(D6 Ain6 RX)
78242

79-
PWM:
243+
c) PWM:
80244
STM8 Arduino
81245
Pin Name Alt Pin Alt
82246
3
@@ -86,8 +250,84 @@ Pin Name Alt Pin Alt
86250
( 10 )
87251
( 11 )
88252

89-
LED: (Kollision)
253+
d) LED: (Kollision)
90254
STM8 Arduino
91255
Pin Name Alt Pin Alt
92256
(B5 SDA 13 SCK)
93257

258+
259+
e) direkte Durchnummerierung nach Gehäusepins: (ab 1)
260+
261+
1-3 -> PD4-PD6
262+
4-6 -> PA1-PA3
263+
7-8 -> PB5-PB4 (rev.)
264+
9-13 -> PC3-PC7
265+
14-16 -> PD1-PD3
266+
267+
SPI: 6,11,12,13 (gleiche Nummern, aber andere Reichenfolge -> fehlerträchtig)
268+
I2C: 7,8
269+
Seriell: 2,3
270+
Analog: 2,3,10,15,16 (in Datenblattreihenfolge: 10,15,16,2,3)
271+
272+
+ gut beim Aufbau dem Steckbrett
273+
+ logische Portzuordnung
274+
- analog wild verteilt
275+
- alle Funktionen auf total anderen Pinnummern
276+
277+
f) geometische Durchnummerierung, angefangen bei Pin 5/PA1 (ab 0)
278+
279+
0-2 -> PA1-PA3
280+
3-4 -> PB5-PB4 (rev.)
281+
5-9 -> PC3-PC7
282+
10-15 -> PD1-PD6
283+
284+
Seriell: 14,15
285+
SPI: 2,7,8,9
286+
I2C: 3,4
287+
Analog: 6,11,12,14,15 (evtl. mit Lücke nummerieren: A0, A1, A2, A4, A5)
288+
PWM: 2,5-9,11-13 (alles ausser 0,1,3,4,10,14-15)
289+
290+
PWM Bitmap pin 15-0: 0011 1011 1110 0100 = 0x3be4
291+
292+
+ auch gut beim Steckbrett
293+
+ sehr logische Portzuordnung
294+
- analog noch immer verteilt
295+
+ TX und RX sind die selten verwendeten analogen Pins A3/A4 oder A4/A5
296+
+ analoge Pins wenigstens in Datenblattreihenfolge
297+
- alle Funktionen auf total anderen Pinnummern
298+
299+
300+
Vergleich der Ergebnisse: logische gegenüber geometrischer Pinnummerierung
301+
302+
phys. STM8 nach geometrische
303+
Pin Name Funktionen Funkt. streng ab PA1
304+
1 PD4 UART_CLK/T2-1/beep 5 1~ 13~
305+
2 PD5 TX/Ain5 1 2 14/A3
306+
3 PD6 RX/Ain6 0 3 15/A4
307+
5 PA1 (OscIn, kein HS) 6 4 0
308+
6 PA2 (OscIn, kein HS) 7 5 1
309+
10 PA3 SS/T2-3 10 6~ 2~
310+
11 PB5 SDA LED 18 7 3
311+
12 PB4 SCL 19 8 4
312+
13 PC3 T1-3/[T1-n1] 9 9~ 5~
313+
14 PC4 T1-4/Ain2/[T1-n2] 4 10~ 6~/A0
314+
15 PC5 SCK/[T2-1] 13 11~ 7~
315+
16 PC6 MOSI/[T1-1] 11 12~ 8~
316+
17 PC7 MISO/[T1-2] 12 13~ 9~
317+
18 PD1 (SWIM) 8 14 10
318+
19 PD2 Ain3/[T2-3] 3 15~ 11~/A1
319+
20 PD3 Ain4/T2-2 2 16~ 12~/A2
320+
321+
Pinmapping nach Funktion:
322+
TX/RX,SPI,I2C wie Arduino,
323+
Analog auf D0-D4 (statt D14-D19),
324+
PWM 2,3,4,5,9,10,11,12,13 (Arduino PWM: 3,5,6,9,10,11, alles ausser 6 ist
325+
abgedeckt)
326+
nicht existent 14-17 -> evtl. besser I2C auf 14 und 15.
327+
328+
Pinmapping streng geometrisch:
329+
SPI: 6,11,12,13 (gleiche Nummern, aber andere Reichenfolge -> fehlerträchtig)
330+
I2C: 7,8
331+
Seriell: 2,3
332+
Analog: 2,3,10,15,16
333+

doc/ST-LinkV2_pinout_01.jpg

96.9 KB
Loading

doc/st-link-v2-dongle.png

231 KB
Loading

doc/stm8board-pinout.jpg

76.2 KB
Loading

examples/sdcc-examples-stm8/Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ all: $(OBJECTS)
99
clean:
1010
rm -f $(OBJECTS)
1111

12-
flash: $(OBJECT).ihx
13-
stm8flash -cstlink -pstm8l150 -w $(OBJECT).ihx
12+
#flash: $(OBJECT).ihx
13+
flash: blinky.ihx
14+
stm8flash -c stlinkv2 -p stm8s103?3 -w $<
15+
# stm8flash -cstlink -pstm8l150 -w $(OBJECT).ihx
1416

1517
%.ihx: %.c
1618
$(SDCC) -lstm8 -mstm8 --out-fmt-ihx $(CFLAGS) $(LDFLAGS) $<

examples/sdcc-examples-stm8/uart.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include <string.h>
2-
#include "stm8l.h"
2+
#include "stm8s.h"
33

44
int uart_write(const char *str) {
55
char i;
@@ -10,21 +10,22 @@ int uart_write(const char *str) {
1010
return(i); // Bytes sent
1111
}
1212

13+
1314
int main() {
1415
unsigned long i = 0;
1516

16-
CLK_DIVR = 0x00; // Set the frequency to 16 MHz
17+
CLK_CKDIVR = 0x00; // Set the frequency to 16 MHz
1718
CLK_PCKENR1 = 0xFF; // Enable peripherals
1819

19-
PC_DDR = 0x08; // Put TX line on
20-
PC_CR1 = 0x08;
20+
PD_DDR = 0x20; // Put TX line on
21+
PD_CR1 = 0x20;
2122

2223
USART1_CR2 = USART_CR2_TEN; // Allow TX & RX
2324
USART1_CR3 &= ~(USART_CR3_STOP1 | USART_CR3_STOP2); // 1 stop bit
2425
USART1_BRR2 = 0x03; USART1_BRR1 = 0x68; // 9600 baud
2526

2627
do {
27-
uart_write("Hello World!\n");
28+
uart_write("Hello World!\r\n");
2829
for(i = 0; i < 147456; i++) { } // Sleep
2930
} while(1);
3031
}

examples/uart-int/Makefile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
SDCC=sdcc
2+
SDLD=sdld
3+
OBJECT=uart
4+
OBJECTS=uart-int.rel
5+
6+
LIBDIR=../../STM8S_StdPeriph_Driver/src
7+
#LIBFILES=$(LIBDIR)/stm8s_gpio.rel
8+
LIBFILES=$(LIBDIR)/stm8s.lib
9+
10+
CFLAGS=-DSTM8S103 -I. -I../../STM8S_StdPeriph_Driver/inc
11+
12+
13+
.PHONY: all clean flash
14+
15+
all: $(OBJECT).ihx
16+
17+
clean:
18+
rm -f *.asm *.ihx *.rel *.sym *.map *.cdb *.lk *.lst *.rst *~
19+
20+
flash: $(OBJECT).ihx
21+
stm8flash -cstlinkv2 -pstm8s103?3 -w $(OBJECT).ihx
22+
23+
$(OBJECT).ihx: $(OBJECTS) $(LIBFILES)
24+
$(SDCC) -lstm8 -mstm8 --out-fmt-ihx $(LDFLAGS) $^ -o $@
25+
26+
%.rel: %.c
27+
$(SDCC) -lstm8 -mstm8 --out-fmt-ihx $(CFLAGS) $(LDFLAGS) -c $<

examples/uart-int/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# uart-int
2+
3+
simple uart example using interrupts and SPL functions.

0 commit comments

Comments
 (0)