diff options
Diffstat (limited to 'lib/chibios/os/hal/boards/ST_STM8S_DISCOVERY')
-rw-r--r-- | lib/chibios/os/hal/boards/ST_STM8S_DISCOVERY/board.c | 77 | ||||
-rw-r--r-- | lib/chibios/os/hal/boards/ST_STM8S_DISCOVERY/board.h | 121 |
2 files changed, 198 insertions, 0 deletions
diff --git a/lib/chibios/os/hal/boards/ST_STM8S_DISCOVERY/board.c b/lib/chibios/os/hal/boards/ST_STM8S_DISCOVERY/board.c new file mode 100644 index 000000000..47b46177f --- /dev/null +++ b/lib/chibios/os/hal/boards/ST_STM8S_DISCOVERY/board.c | |||
@@ -0,0 +1,77 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | #include "hal.h" | ||
18 | |||
19 | /** | ||
20 | * @brief PAL setup. | ||
21 | * @details Digital I/O ports static configuration as defined in @p board.h. | ||
22 | */ | ||
23 | #if HAL_USE_PAL || defined(__DOXYGEN__) | ||
24 | ROMCONST PALConfig pal_default_config = | ||
25 | { | ||
26 | { | ||
27 | {VAL_GPIOAODR, 0, VAL_GPIOADDR, VAL_GPIOACR1, VAL_GPIOACR2}, | ||
28 | {VAL_GPIOBODR, 0, VAL_GPIOBDDR, VAL_GPIOBCR1, VAL_GPIOBCR2}, | ||
29 | {VAL_GPIOCODR, 0, VAL_GPIOCDDR, VAL_GPIOCCR1, VAL_GPIOCCR2}, | ||
30 | {VAL_GPIODODR, 0, VAL_GPIODDDR, VAL_GPIODCR1, VAL_GPIODCR2}, | ||
31 | {VAL_GPIOEODR, 0, VAL_GPIOEDDR, VAL_GPIOECR1, VAL_GPIOECR2}, | ||
32 | {VAL_GPIOFODR, 0, VAL_GPIOFDDR, VAL_GPIOFCR1, VAL_GPIOFCR2}, | ||
33 | {VAL_GPIOGODR, 0, VAL_GPIOGDDR, VAL_GPIOGCR1, VAL_GPIOGCR2}, | ||
34 | } | ||
35 | }; | ||
36 | #endif | ||
37 | |||
38 | /* | ||
39 | * TIM 2 clock after the prescaler. | ||
40 | */ | ||
41 | #define TIM2_CLOCK (SYSCLK / 16) | ||
42 | #define TIM2_ARR ((TIM2_CLOCK / CH_FREQUENCY) - 1) | ||
43 | |||
44 | /* | ||
45 | * TIM2 interrupt handler. | ||
46 | */ | ||
47 | CH_IRQ_HANDLER(13) { | ||
48 | |||
49 | CH_IRQ_PROLOGUE(); | ||
50 | |||
51 | chSysLockFromIsr(); | ||
52 | chSysTimerHandlerI(); | ||
53 | chSysUnlockFromIsr(); | ||
54 | |||
55 | TIM2->SR1 = 0; | ||
56 | |||
57 | CH_IRQ_EPILOGUE(); | ||
58 | } | ||
59 | |||
60 | /* | ||
61 | * Board-specific initialization code. | ||
62 | */ | ||
63 | void boardInit(void) { | ||
64 | |||
65 | /* | ||
66 | * TIM2 initialization as system tick. | ||
67 | */ | ||
68 | CLK->PCKENR1 |= CLK_PCKENR1_TIM2; | ||
69 | TIM2->PSCR = 4; /* Prescaler divide by 2^4=16.*/ | ||
70 | TIM2->ARRH = (uint8_t)(TIM2_ARR >> 8); | ||
71 | TIM2->ARRL = (uint8_t)(TIM2_ARR); | ||
72 | TIM2->CNTRH = 0; | ||
73 | TIM2->CNTRL = 0; | ||
74 | TIM2->SR1 = 0; | ||
75 | TIM2->IER = TIM2_IER_UIE; | ||
76 | TIM2->CR1 = TIM2_CR1_CEN; | ||
77 | } | ||
diff --git a/lib/chibios/os/hal/boards/ST_STM8S_DISCOVERY/board.h b/lib/chibios/os/hal/boards/ST_STM8S_DISCOVERY/board.h new file mode 100644 index 000000000..372af7509 --- /dev/null +++ b/lib/chibios/os/hal/boards/ST_STM8S_DISCOVERY/board.h | |||
@@ -0,0 +1,121 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | #ifndef _BOARD_H_ | ||
18 | #define _BOARD_H_ | ||
19 | |||
20 | /* | ||
21 | * Setup for STMicroelectronics STM8S-Discovery board. | ||
22 | */ | ||
23 | |||
24 | /* | ||
25 | * Board identifiers. | ||
26 | */ | ||
27 | #define BOARD_ST_STM8S_DISCOVERY | ||
28 | #define BOARD_NAME "ST STM8S-Discovery" | ||
29 | |||
30 | /* | ||
31 | * Board frequencies. | ||
32 | */ | ||
33 | #define HSECLK 16000000 | ||
34 | |||
35 | /* | ||
36 | * MCU model used on the board. | ||
37 | */ | ||
38 | #define STM8S105 | ||
39 | |||
40 | /* | ||
41 | * Pin definitions. | ||
42 | */ | ||
43 | #define PA_OSCIN 1 | ||
44 | #define PA_OSCOUT 2 | ||
45 | |||
46 | #define PC_TS_KEY 1 | ||
47 | #define PC_TS_LOADREF 2 | ||
48 | #define PC_TS_SHIELD 3 | ||
49 | |||
50 | #define PD_LD10 0 | ||
51 | #define PD_SWIM 1 | ||
52 | #define PD_TX 5 | ||
53 | #define PD_RX 6 | ||
54 | |||
55 | /* | ||
56 | * Port A initial setup. | ||
57 | */ | ||
58 | #define VAL_GPIOAODR 0 | ||
59 | #define VAL_GPIOADDR 0 /* All inputs. */ | ||
60 | #define VAL_GPIOACR1 0xFF /* All pull-up or push-pull. */ | ||
61 | #define VAL_GPIOACR2 0 | ||
62 | |||
63 | /* | ||
64 | * Port B initial setup. | ||
65 | */ | ||
66 | #define VAL_GPIOBODR 0 | ||
67 | #define VAL_GPIOBDDR 0 /* All inputs. */ | ||
68 | #define VAL_GPIOBCR1 0xFF /* All push-pull. */ | ||
69 | #define VAL_GPIOBCR2 0 | ||
70 | |||
71 | /* | ||
72 | * Port C initial setup. | ||
73 | */ | ||
74 | #define VAL_GPIOCODR 0 | ||
75 | #define VAL_GPIOCDDR 0 /* All inputs. */ | ||
76 | #define VAL_GPIOCCR1 0xFF /* All pull-up. */ | ||
77 | #define VAL_GPIOCCR2 0 | ||
78 | |||
79 | /* | ||
80 | * Port D initial setup. | ||
81 | */ | ||
82 | #define VAL_GPIODODR (1 << PD_LD10) | (1 << PD_TX) | ||
83 | #define VAL_GPIODDDR (1 << PD_LD10) | (1 << PD_TX) | ||
84 | #define VAL_GPIODCR1 0xFF /* All pull-up. */ | ||
85 | #define VAL_GPIODCR2 0 | ||
86 | |||
87 | /* | ||
88 | * Port E initial setup. | ||
89 | */ | ||
90 | #define VAL_GPIOEODR 0 | ||
91 | #define VAL_GPIOEDDR 0 /* All inputs. */ | ||
92 | #define VAL_GPIOECR1 0xFF /* All pull-up. */ | ||
93 | #define VAL_GPIOECR2 0 | ||
94 | |||
95 | /* | ||
96 | * Port F initial setup. | ||
97 | */ | ||
98 | #define VAL_GPIOFODR 0 | ||
99 | #define VAL_GPIOFDDR 0 /* All inputs. */ | ||
100 | #define VAL_GPIOFCR1 0xFF /* All pull-up. */ | ||
101 | #define VAL_GPIOFCR2 0 | ||
102 | |||
103 | /* | ||
104 | * Port G initial setup. | ||
105 | */ | ||
106 | #define VAL_GPIOGODR 0 | ||
107 | #define VAL_GPIOGDDR 0 /* All inputs. */ | ||
108 | #define VAL_GPIOGCR1 0xFF /* All pull-up or push-pull. */ | ||
109 | #define VAL_GPIOGCR2 0 | ||
110 | |||
111 | #if !defined(_FROM_ASM_) | ||
112 | #ifdef __cplusplus | ||
113 | extern "C" { | ||
114 | #endif | ||
115 | void boardInit(void); | ||
116 | #ifdef __cplusplus | ||
117 | } | ||
118 | #endif | ||
119 | #endif /* _FROM_ASM_ */ | ||
120 | |||
121 | #endif /* _BOARD_H_ */ | ||