Skip to content

Commit 410ccd8

Browse files
committed
add experimental support for sduino_UNO board (untested)
1 parent 1eaf9d1 commit 410ccd8

2 files changed

Lines changed: 325 additions & 0 deletions

File tree

sduino/hardware/sduino/stm8/boards.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,22 @@ stm8sdisco.build.variant=stm8sdisco
3636
# meaningless variables just to keep the makefile happy
3737

3838
stm8sdisco.upload.speed=1
39+
40+
41+
##############################################################
42+
43+
s8uno.name=sduino_UNO Board with STM8S105K6 using stlink
44+
45+
s8uno.upload.using=stm8flash
46+
s8uno.upload.protocol=stlink
47+
s8uno.upload.mcu=stm8s105?6
48+
s8uno.upload.maximum_size=32768
49+
50+
s8uno.build.mcu=STM8S105
51+
s8uno.build.f_cpu=16000000L
52+
s8uno.build.core=sduino
53+
s8uno.build.variant=s8uno
54+
55+
# meaningless variables just to keep the makefile happy
56+
57+
s8uno.upload.speed=115200
Lines changed: 306 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,306 @@
1+
/*
2+
pins_arduino.h - Pin definition functions for Arduino
3+
Part of Arduino - http://www.arduino.cc/
4+
5+
Copyright (c) 2007 David A. Mellis
6+
7+
This library is free software; you can redistribute it and/or
8+
modify it under the terms of the GNU Lesser General Public
9+
License as published by the Free Software Foundation; either
10+
version 2.1 of the License, or (at your option) any later version.
11+
12+
This library is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
Lesser General Public License for more details.
16+
17+
You should have received a copy of the GNU Lesser General
18+
Public License along with this library; if not, write to the
19+
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20+
Boston, MA 02111-1307 USA
21+
*/
22+
23+
#ifndef Pins_Arduino_h
24+
#define Pins_Arduino_h
25+
26+
#ifndef _BV
27+
#define _BV(X) (1<<(X))
28+
#endif
29+
30+
31+
#define NUM_DIGITAL_PINS (15+(NUM_ANALOG_INPUTS))
32+
#define NUM_ANALOG_INPUTS 6
33+
#define analogInputToDigitalPin(p) ((p < NUM_ANALOG_INPUTS) ? (p) + (NUM_DIGITAL_PINS-NUM_ANALOG_INPUTS) : -1)
34+
35+
36+
/* functional pin mapping for the STM8S105 used on the sduino-uno board.
37+
*
38+
* This pin mapping tries to reassemble the original Arduino Uno mapping
39+
* for the ATmega328 as closely as possible.
40+
*/
41+
enum portpin {
42+
PD6, /* IO0/RX PD6/UART2_RX */
43+
PD5, /* IO1/TX PD5/UART2_TX */
44+
PD7, /* IO2 PD7/TLI [TIM1_CH4] */
45+
PD2, /* IO3~ PD2 (HS)/TIM3_CH1 [TIM2_CH3] */
46+
PD0, /* IO4~ PD0 (HS)/TIM3_CH2 [TIM1_BKIN]/[CLK_COO] */
47+
PD4, /* IO5~ PD4 (HS)/TIM2_CH1 [BEEP] */
48+
PD3, /* IO6~ PD3 (HS)/TIM2_CH2/ADC_ETR */
49+
PD1, /* IO7 PD1 (HS)/SWIM */
50+
PC1, /* IO8~ PC1 (HS)/TIM1_CH1/UART2_CK */
51+
PC3, /* IO9~ PC3 (HS)/TIM1_CH3 */
52+
PC4, /* IO10~ PC4 (HS)/TIM1_CH4 */
53+
PC6, /* IO11/MOSI PC6 (HS)/SPI_MOSI */
54+
PC7, /* IO12/MISO PC7 (HS)/SPI_MISO */
55+
PC5, /* IO13/SCK PC5 (HS)/SPI_SCK */
56+
PC2, /* IO14~ PC2 (HS)/TIM1_CH2 */
57+
PE5, /* IO15/SS PE5/SPI_NSS */
58+
PB0, /* AD0 PB0/AIN0 [TIM1_CH1N] */
59+
PB1, /* AD1 PB1/AIN1 [TIM1_CH2N] */
60+
PB2, /* AD2 PB2/AIN2 [TIM1_CH3N] */
61+
PB3, /* AD3 PB3/AIN3 [TIM1_ETR] */
62+
PB5, /* AD4/SDA PB5/AIN5 [I2C_SDA] */
63+
PB4, /* AD5/SCL PB4/AIN4 [I2C_SCL] */
64+
};
65+
66+
67+
68+
// PWM on pins 3-6, 8-10, 14
69+
#define digitalPinHasPWM(p) ( ( (p)>=3 & (p)<=10 & (p)!=7 ) \
70+
| (p)==14 \
71+
)
72+
73+
#define PIN_SPI_SS (PE5) // 15
74+
#define PIN_SPI_MOSI (PC6) // 11
75+
#define PIN_SPI_MISO (PC7) // 12
76+
#define PIN_SPI_SCK (PC5) // 13
77+
78+
/* SDCC workaround: These const variables wouldn't be replaced by hard
79+
* constant loads. So use defines instead.
80+
static const uint8_t SS = PIN_SPI_SS;
81+
static const uint8_t MOSI = PIN_SPI_MOSI;
82+
static const uint8_t MISO = PIN_SPI_MISO;
83+
static const uint8_t SCK = PIN_SPI_SCK;
84+
*/
85+
#define SS PIN_SPI_SS
86+
#define MOSI PIN_SPI_MOSI
87+
#define MISO PIN_SPI_MISO
88+
#define SCK PIN_SPI_SCK
89+
90+
#define PIN_WIRE_SDA (PB5) // 20
91+
#define PIN_WIRE_SCL (PB4) // 21
92+
93+
/* SDCC workaround
94+
static const uint8_t SDA = PIN_WIRE_SDA;
95+
static const uint8_t SCL = PIN_WIRE_SCL;
96+
*/
97+
#define SDA PIN_WIRE_SDA
98+
#define SCL PIN_WIRE_SCL
99+
100+
#define PIN_LED_BUILDIN (PC5) // sduino: pin for the buildin LED, pin 13
101+
#define PIN_TX (PD5) // sduino: pin for TX line, pin 1
102+
#define PIN_RX (PD6) // sduino: pin for RX line, pin 0
103+
104+
#define LED_BUILDIN (PC5) // pin for the buildin LED, pin 13
105+
106+
#define PIN_A0 (PB0) // 16, Ain0
107+
#define PIN_A1 (PB1) // 17, Ain1
108+
#define PIN_A2 (PB2) // 18, Ain2
109+
#define PIN_A3 (PB3) // 19, Ain3
110+
#define PIN_A4 (PB5) // 20, Ain5
111+
#define PIN_A5 (PB4) // 21, Ain4
112+
113+
/* SDCC workaround
114+
static const uint8_t A0 = PIN_A0;
115+
static const uint8_t A1 = PIN_A1;
116+
static const uint8_t A2 = PIN_A2;
117+
static const uint8_t A3 = PIN_A3;
118+
static const uint8_t A4 = PIN_A4;
119+
*/
120+
#define A0 PIN_A0
121+
#define A1 PIN_A1
122+
#define A2 PIN_A2
123+
#define A3 PIN_A3
124+
#define A4 PIN_A4
125+
#define A5 PIN_A5
126+
127+
//#define NO_ANALOG 0xff
128+
129+
// map the logical pin numbers to the physical ADC channels:
130+
// pin 20,21 -> channel 5,4 (reverse order!)
131+
// pin 16..19 -> channel 0-3
132+
// smaller numbers are not modified but used as channel numbers directly.
133+
#define analogPinToChannel(P) ( (P)>=20 ? 25-(P) : ( \
134+
(P)>=16 ? (P)-16 : \
135+
(P) \
136+
))
137+
138+
/* alternative way to define the mapping:
139+
#define analogPinToChannel(P) ( (P)<16 ? (P) : ( \
140+
(P)<20 ? (P)-16 : \
141+
25-(P) \
142+
))
143+
*/
144+
145+
146+
/*FIXME
147+
#define digitalPinToPCICR(p) (((p) >= 0 && (p) <= 21) ? (&PCICR) : ((uint8_t *)0))
148+
#define digitalPinToPCICRbit(p) (((p) <= 7) ? 2 : (((p) <= 13) ? 0 : 1))
149+
#define digitalPinToPCMSK(p) (((p) <= 7) ? (&PCMSK2) : (((p) <= 13) ? (&PCMSK0) : (((p) <= 21) ? (&PCMSK1) : ((uint8_t *)0))))
150+
#define digitalPinToPCMSKbit(p) (((p) <= 7) ? (p) : (((p) <= 13) ? ((p) - 8) : ((p) - 14)))
151+
152+
#define digitalPinToInterrupt(p) ((p) == 2 ? 0 : ((p) == 3 ? 1 : NOT_AN_INTERRUPT))
153+
*/
154+
155+
#ifdef ARDUINO_MAIN
156+
157+
// sduino-uno board featuring a STM8S105K6 CPU
158+
// from https://github.com/roybaer/sduino_uno
159+
160+
// these arrays map port names (e.g. port B) to the
161+
// appropriate addresses for various functions (e.g. reading
162+
// and writing)
163+
const uint16_t PROGMEM port_to_mode_PGM[] = {
164+
NOT_A_PORT,
165+
GPIOA_BaseAddress+2,
166+
GPIOB_BaseAddress+2,
167+
GPIOC_BaseAddress+2,
168+
GPIOD_BaseAddress+2,
169+
GPIOE_BaseAddress+2,
170+
/*
171+
(uint16_t) &GPIOA->DDR,
172+
(uint16_t) &GPIOB->DDR,
173+
(uint16_t) &GPIOC->DDR,
174+
(uint16_t) &GPIOD->DDR,
175+
*/
176+
};
177+
178+
const uint16_t PROGMEM port_to_output_PGM[] = {
179+
NOT_A_PORT,
180+
GPIOA_BaseAddress,
181+
GPIOB_BaseAddress,
182+
GPIOC_BaseAddress,
183+
GPIOD_BaseAddress,
184+
GPIOE_BaseAddress,
185+
/*
186+
(uint16_t) &GPIOA->ODR,
187+
(uint16_t) &GPIOB->ODR,
188+
(uint16_t) &GPIOC->ODR,
189+
(uint16_t) &GPIOD->ODR,
190+
*/
191+
};
192+
193+
const uint16_t PROGMEM port_to_input_PGM[] = {
194+
NOT_A_PORT,
195+
GPIOA_BaseAddress+1,
196+
GPIOB_BaseAddress+1,
197+
GPIOC_BaseAddress+1,
198+
GPIOD_BaseAddress+1,
199+
GPIOE_BaseAddress+1,
200+
/*
201+
(uint16_t) &GPIOA->IDR,
202+
(uint16_t) &GPIOB->IDR,
203+
(uint16_t) &GPIOC->IDR,
204+
(uint16_t) &GPIOD->IDR,
205+
*/
206+
};
207+
208+
const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
209+
PD, /* 0 */
210+
PD,
211+
PD,
212+
PD,
213+
PD,
214+
PD,
215+
PD,
216+
PD,
217+
PC, /* 8 */
218+
PC,
219+
PC,
220+
PC,
221+
PC,
222+
PC,
223+
PC,
224+
PE, /* 15 */
225+
PB, /* 16 */
226+
PB,
227+
PB,
228+
PB,
229+
PB,
230+
PB, /* 21 */
231+
};
232+
233+
const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
234+
_BV(6), /* 0, port D */
235+
_BV(5),
236+
_BV(7),
237+
_BV(2),
238+
_BV(0),
239+
_BV(4),
240+
_BV(3),
241+
_BV(1),
242+
_BV(1), /* 8, port C */
243+
_BV(3),
244+
_BV(4),
245+
_BV(6),
246+
_BV(7),
247+
_BV(5),
248+
_BV(2),
249+
_BV(5), /* 15, port E */
250+
_BV(0), /* 16, port B */
251+
_BV(1),
252+
_BV(2),
253+
_BV(3),
254+
_BV(5),
255+
_BV(4),
256+
};
257+
258+
const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
259+
NOT_ON_TIMER,
260+
NOT_ON_TIMER,
261+
NOT_ON_TIMER,
262+
TIMER31, // 3
263+
TIMER32, // 4
264+
TIMER21, // 5
265+
TIMER22, // 6
266+
NOT_ON_TIMER,
267+
TIMER11, // 8
268+
TIMER13, // 9
269+
TIMER14, // 10
270+
NOT_ON_TIMER,
271+
NOT_ON_TIMER,
272+
NOT_ON_TIMER,
273+
TIMER12, // 14
274+
NOT_ON_TIMER,
275+
NOT_ON_TIMER,
276+
NOT_ON_TIMER,
277+
NOT_ON_TIMER,
278+
NOT_ON_TIMER,
279+
NOT_ON_TIMER,
280+
NOT_ON_TIMER,
281+
};
282+
283+
#endif
284+
285+
#define NEED_TIMER_11_12
286+
#define NEED_TIMER_31_32
287+
288+
// These serial port names are intended to allow libraries and architecture-neutral
289+
// sketches to automatically default to the correct port name for a particular type
290+
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
291+
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
292+
//
293+
// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
294+
//
295+
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
296+
//
297+
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
298+
//
299+
// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
300+
//
301+
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
302+
// pins are NOT connected to anything by default.
303+
#define SERIAL_PORT_MONITOR Serial
304+
#define SERIAL_PORT_HARDWARE Serial
305+
306+
#endif

0 commit comments

Comments
 (0)