Browse Source

Chitu variant for disk-based update (#18264)

J.C. Nelson 4 years ago
parent
commit
40f55f8b98
No account linked to committer's email address

+ 48
- 0
buildroot/share/PlatformIO/boards/chitu_F103.json View File

@@ -0,0 +1,48 @@
1
+{
2
+  "build": {
3
+    "core": "maple",
4
+    "cpu": "cortex-m3",
5
+    "extra_flags": "-DSTM32F103xE -DSTM32F1",
6
+    "f_cpu": "72000000L",
7
+    "hwids": [
8
+      [
9
+        "0x1EAF",
10
+        "0x0003"
11
+      ],
12
+      [
13
+        "0x1EAF",
14
+        "0x0004"
15
+      ]
16
+    ],
17
+    "mcu": "stm32f103zet6",
18
+    "variant": "CHITU_F103",
19
+    "ldscript": "chitu_f103.ld"
20
+  },
21
+  "debug": {
22
+    "jlink_device": "STM32F103ZE",
23
+    "openocd_target": "stm32f1x",
24
+    "svd_path": "STM32F103xx.svd"
25
+  },
26
+  "frameworks": [
27
+    "arduino"
28
+  ],
29
+  "name": "CHITU STM32F103Z (64k RAM. 512k Flash)",
30
+  "upload": {
31
+    "disable_flushing": false,
32
+    "maximum_ram_size": 60536,
33
+    "maximum_size": 480288,
34
+    "protocol": "stlink",
35
+    "protocols": [
36
+      "jlink",
37
+      "stlink",
38
+      "blackmagic",
39
+      "serial",
40
+      "dfu"
41
+    ],
42
+    "require_upload_port": true,
43
+    "use_1200bps_touch": false,
44
+    "wait_for_upload_port": false
45
+  },
46
+  "url": "http://www.st.com/en/microcontrollers/stm32f103ze.html",
47
+  "vendor": "Generic"
48
+}

+ 233
- 0
buildroot/share/PlatformIO/variants/CHITU_F103/board.cpp View File

@@ -0,0 +1,233 @@
1
+/******************************************************************************
2
+ * The MIT License
3
+ *
4
+ * Copyright (c) 2011 LeafLabs, LLC.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person
7
+ * obtaining a copy of this software and associated documentation
8
+ * files (the "Software"), to deal in the Software without
9
+ * restriction, including without limitation the rights to use, copy,
10
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
11
+ * of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be
15
+ * included in all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ * SOFTWARE.
25
+ *****************************************************************************/
26
+
27
+/**
28
+ * @file   wirish/boards/maple/board.cpp
29
+ * @author Marti Bolivar <mbolivar@leaflabs.com>
30
+ * @brief  Maple board file.
31
+ */
32
+
33
+#include <board/board.h>         // For this board's header file
34
+
35
+/* Roger Clark. Added next to includes for changes to Serial */
36
+#include <libmaple/usart.h>
37
+#include <HardwareSerial.h>
38
+
39
+#include <wirish_types.h> // For stm32_pin_info and its contents
40
+                                 // (these go into PIN_MAP).
41
+
42
+#include "boards_private.h"      // For PMAP_ROW(), which makes
43
+                                 // PIN_MAP easier to read.
44
+
45
+// boardInit(): nothing special to do for Maple.
46
+//
47
+// When defining your own board.cpp, you can put extra code in this
48
+// function if you have anything you want done on reset, before main()
49
+// or setup() are called.
50
+//
51
+// If there's nothing special you need done, feel free to leave this
52
+// function out, as we do here.
53
+/*
54
+void boardInit(void) {
55
+}
56
+*/
57
+
58
+// Pin map: this lets the basic I/O functions (digitalWrite(),
59
+// analogRead(), pwmWrite()) translate from pin numbers to STM32
60
+// peripherals.
61
+//
62
+// PMAP_ROW() lets us specify a row (really a struct stm32_pin_info)
63
+// in the pin map. Its arguments are:
64
+//
65
+// - GPIO device for the pin (&gpioa, etc.)
66
+// - GPIO bit for the pin (0 through 15)
67
+// - Timer device, or NULL if none
68
+// - Timer channel (1 to 4, for PWM), or 0 if none
69
+// - ADC device, or NULL if none
70
+// - ADC channel, or ADCx if none
71
+
72
+extern const stm32_pin_info PIN_MAP[BOARD_NR_GPIO_PINS] = {
73
+  /*
74
+    gpio_dev *gpio_device;      GPIO device 
75
+    timer_dev *timer_device;    Pin's timer device, if any.
76
+    const adc_dev *adc_device;  ADC device, if any. 
77
+    uint8 gpio_bit;             Pin's GPIO port bit. 
78
+    uint8 timer_channel;        Timer channel, or 0 if none. 
79
+    uint8 adc_channel;          Pin ADC channel, or ADCx if none. 
80
+  */
81
+
82
+  {&gpioa, &timer2, &adc1,  0, 1,    0}, /* PA0 */
83
+  {&gpioa, &timer2, &adc1,  1, 2,    1}, /* PA1 */
84
+  {&gpioa, &timer2, &adc1,  2, 3,    2}, /* PA2 */
85
+  {&gpioa, &timer2, &adc1,  3, 4,    3}, /* PA3 */
86
+  {&gpioa,   NULL, &adc1,  4, 0,    4}, /* PA4 */	
87
+  {&gpioa,   NULL, &adc1,  5, 0,    5}, /* PA5 */
88
+  {&gpioa, &timer3, &adc1,  6, 1,    6}, /* PA6 */
89
+  {&gpioa, &timer3, &adc1,  7, 2,    7}, /* PA7 */
90
+  {&gpioa, &timer1, NULL,  8, 1, ADCx}, /* PA8 */
91
+  {&gpioa, &timer1, NULL,  9, 2, ADCx}, /* PA9 */
92
+  {&gpioa, &timer1, NULL, 10, 3, ADCx}, /* PA10 */
93
+  {&gpioa,   NULL, NULL, 11, 0, ADCx}, /* PA11 */
94
+  {&gpioa,   NULL, NULL, 12, 0, ADCx}, /* PA12 */	
95
+  {&gpioa,   NULL, NULL, 13, 0, ADCx}, /* PA13 */
96
+  {&gpioa,   NULL, NULL, 14, 0, ADCx}, /* PA14 */
97
+  {&gpioa,   NULL, NULL, 15, 0, ADCx}, /* PA15 */
98
+
99
+  {&gpiob, &timer3, &adc1,  0, 3,    8}, /* PB0 */
100
+  {&gpiob, &timer3, &adc1,  1, 4,    9}, /* PB1 */
101
+  {&gpiob, &timer3, &adc1,  2, 4,    9}, /* PB2 */
102
+  {&gpiob,   NULL, NULL,  3, 0, ADCx}, /* PB3  */
103
+  {&gpiob,   NULL, NULL,  4, 0, ADCx}, /* PB4  */
104
+  {&gpiob,   NULL, NULL,  5, 0, ADCx}, /* PB5 */
105
+  {&gpiob, &timer4, NULL,  6, 1, ADCx}, /* PB6 */
106
+  {&gpiob, &timer4, NULL,  7, 2, ADCx}, /* PB7 */
107
+  {&gpiob, &timer4, NULL,  8, 3, ADCx}, /* PB8 */
108
+  {&gpiob, &timer4, NULL,  9, 4, ADCx}, /* PB9 */
109
+  {&gpiob,   NULL, NULL, 10, 0, ADCx}, /* PB10 */
110
+  {&gpiob,   NULL, NULL, 11, 0, ADCx}, /* PB11 */
111
+  {&gpiob,   NULL, NULL, 12, 0, ADCx}, /* PB12 */
112
+  {&gpiob,   NULL, NULL, 13, 0, ADCx}, /* PB13 */
113
+  {&gpiob,   NULL, NULL, 14, 0, ADCx}, /* PB14 */
114
+  {&gpiob,   NULL, NULL, 15, 0, ADCx}, /* PB15 */
115
+
116
+
117
+  {&gpioc,   NULL, &adc1,  0, 0,   10}, /* PC0 */
118
+  {&gpioc,   NULL, &adc1,  1, 0,   11}, /* PC1 */
119
+  {&gpioc,   NULL, &adc1,  2, 0,   12}, /* PC2 */
120
+  {&gpioc,   NULL, &adc1,  3, 0,   13}, /* PC3 */
121
+  {&gpioc,   NULL, &adc1,  4, 0,   14}, /* PC4 */
122
+  {&gpioc,   NULL, &adc1,  5, 0,   15}, /* PC5 */
123
+  {&gpioc, &timer8, NULL,  6, 1, ADCx}, /* PC6 */	
124
+  {&gpioc, &timer8, NULL,  7, 2, ADCx}, /* PC7 */
125
+  {&gpioc, &timer8, NULL,  8, 3, ADCx}, /* PC8 */
126
+  {&gpioc, &timer8, NULL,  9, 4, ADCx}, /* PC9 */
127
+  {&gpioc,   NULL, NULL, 10, 0, ADCx}, /* PC10 UART4_TX/SDIO_D2 */
128
+  {&gpioc,   NULL, NULL, 11, 0, ADCx}, /* PC11 UART4_RX/SDIO_D3 */
129
+  {&gpioc,   NULL, NULL, 12, 0, ADCx}, /* PC12 UART5_TX/SDIO_CK */	
130
+  {&gpioc,   NULL, NULL, 13, 0, ADCx}, /* PC13 TAMPER-RTC */
131
+  {&gpioc,   NULL, NULL, 14, 0, ADCx}, /* PC14 OSC32_IN */
132
+  {&gpioc,   NULL, NULL, 15, 0, ADCx}, /* PC15 OSC32_OUT */
133
+
134
+	{&gpiod,   NULL, NULL,   0, 0, ADCx} , /* PD0 OSC_IN */
135
+	{&gpiod,   NULL, NULL,   1, 0, ADCx} , /* PD1  OSC_OUT */
136
+	{&gpiod,   NULL, NULL,   2, 0, ADCx} , /* PD2  TIM3_ETR/UART5_RX SDIO_CMD */
137
+	
138
+	{&gpiod,   NULL, NULL,   3, 0, ADCx} , /* PD3  FSMC_CLK */
139
+	{&gpiod,   NULL, NULL,   4, 0, ADCx} , /* PD4  FSMC_NOE */
140
+	{&gpiod,   NULL, NULL,   5, 0, ADCx} , /* PD5  FSMC_NWE */
141
+	{&gpiod,   NULL, NULL,   6, 0, ADCx} , /* PD6  FSMC_NWAIT */
142
+	{&gpiod,   NULL, NULL,   7, 0, ADCx} , /* PD7  FSMC_NE1/FSMC_NCE2 */
143
+	{&gpiod,   NULL, NULL,   8, 0, ADCx} , /* PD8  FSMC_D13 */
144
+	{&gpiod,   NULL, NULL,   9, 0, ADCx} , /* PD9  FSMC_D14 */
145
+	{&gpiod,   NULL, NULL,  10, 0, ADCx} , /* PD10  FSMC_D15 */
146
+	{&gpiod,   NULL, NULL,  11, 0, ADCx} , /* PD11  FSMC_A16 */
147
+	{&gpiod,   NULL, NULL,  12, 0, ADCx} , /* PD12  FSMC_A17 */
148
+	{&gpiod,   NULL, NULL,  13, 0, ADCx} , /* PD13  FSMC_A18 */	
149
+	{&gpiod,   NULL, NULL,  14, 0, ADCx} , /* PD14  FSMC_D0 */
150
+	{&gpiod,   NULL, NULL,  15, 0, ADCx} , /* PD15  FSMC_D1 */
151
+	
152
+	{&gpioe,   NULL, NULL,   0, 0, ADCx} , /* PE0   */
153
+	{&gpioe,   NULL, NULL,   1, 0, ADCx} , /* PE1   */
154
+	{&gpioe,   NULL, NULL,   2, 0, ADCx} , /* PE2   */
155
+	{&gpioe,   NULL, NULL,   3, 0, ADCx} , /* PE3   */
156
+	{&gpioe,   NULL, NULL,   4, 0, ADCx} , /* PE4   */
157
+	{&gpioe,   NULL, NULL,   5, 0, ADCx} , /* PE5   */
158
+	{&gpioe,   NULL, NULL,   6, 0, ADCx} , /* PE6   */
159
+	{&gpioe,   NULL, NULL,   7, 0, ADCx} , /* PE7   */
160
+	{&gpioe,   NULL, NULL,   8, 0, ADCx} , /* PE8   */
161
+	{&gpioe,   NULL, NULL,   9, 0, ADCx} , /* PE9   */
162
+	{&gpioe,   NULL, NULL,  10, 0, ADCx} , /* PE10  */
163
+	{&gpioe,   NULL, NULL,  11, 0, ADCx} , /* PE11  */
164
+	{&gpioe,   NULL, NULL,  12, 0, ADCx} , /* PE12  */
165
+	{&gpioe,   NULL, NULL,  13, 0, ADCx} , /* PE13  */	
166
+	{&gpioe,   NULL, NULL,  14, 0, ADCx} , /* PE14  */
167
+	{&gpioe,   NULL, NULL,  15, 0, ADCx} , /* PE15  */	
168
+
169
+	{&gpiof,   NULL, NULL,   0, 0, ADCx} , /* PF0   */
170
+	{&gpiof,   NULL, NULL,   1, 0, ADCx} , /* PF1   */
171
+	{&gpiof,   NULL, NULL,   2, 0, ADCx} , /* PF2   */
172
+	{&gpiof,   NULL, NULL,   3, 0, ADCx} , /* PF3   */
173
+	{&gpiof,   NULL, NULL,   4, 0, ADCx} , /* PF4   */
174
+	{&gpiof,   NULL, NULL,   5, 0, ADCx} , /* PF5   */
175
+	{&gpiof,   NULL, NULL,   6, 0, ADCx} , /* PF6   */
176
+	{&gpiof,   NULL, NULL,   7, 0, ADCx} , /* PF7   */
177
+	{&gpiof,   NULL, NULL,   8, 0, ADCx} , /* PF8   */
178
+	{&gpiof,   NULL, NULL,   9, 0, ADCx} , /* PF9   */
179
+	{&gpiof,   NULL, NULL,  10, 0, ADCx} , /* PF10  */
180
+	{&gpiof,   NULL, NULL,  11, 0, ADCx} , /* PF11  */
181
+	{&gpiof,   NULL, NULL,  12, 0, ADCx} , /* PF12  */
182
+	{&gpiof,   NULL, NULL,  13, 0, ADCx} , /* PF13  */	
183
+	{&gpiof,   NULL, NULL,  14, 0, ADCx} , /* PF14  */
184
+	{&gpiof,   NULL, NULL,  15, 0, ADCx} , /* PF15  */		
185
+	
186
+	{&gpiog,   NULL, NULL,   0, 0, ADCx} , /* PG0   */
187
+	{&gpiog,   NULL, NULL,   1, 0, ADCx} , /* PG1   */
188
+	{&gpiog,   NULL, NULL,   2, 0, ADCx} , /* PG2   */
189
+	{&gpiog,   NULL, NULL,   3, 0, ADCx} , /* PG3   */
190
+	{&gpiog,   NULL, NULL,   4, 0, ADCx} , /* PG4   */
191
+	{&gpiog,   NULL, NULL,   5, 0, ADCx} , /* PG5   */
192
+	{&gpiog,   NULL, NULL,   6, 0, ADCx} , /* PG6   */
193
+	{&gpiog,   NULL, NULL,   7, 0, ADCx} , /* PG7   */
194
+	{&gpiog,   NULL, NULL,   8, 0, ADCx} , /* PG8   */
195
+	{&gpiog,   NULL, NULL,   9, 0, ADCx} , /* PG9   */
196
+	{&gpiog,   NULL, NULL,  10, 0, ADCx} , /* PG10  */
197
+	{&gpiog,   NULL, NULL,  11, 0, ADCx} , /* PG11  */
198
+	{&gpiog,   NULL, NULL,  12, 0, ADCx} , /* PG12  */
199
+	{&gpiog,   NULL, NULL,  13, 0, ADCx} , /* PG13  */	
200
+	{&gpiog,   NULL, NULL,  14, 0, ADCx} , /* PG14  */
201
+	{&gpiog,   NULL, NULL,  15, 0, ADCx}   /* PG15  */		
202
+};
203
+
204
+/*  Basically everything that is defined as having a timer us PWM */
205
+extern const uint8 boardPWMPins[BOARD_NR_PWM_PINS] __FLASH__ = {
206
+  PA0,PA1,PA2,PA3,PA6,PA7,PA8,PA9,PA10,PB0,PB1,PB6,PB7,PB8,PB9,PC6,PC7,PC8,PC9
207
+};
208
+
209
+/*  Basically everything that is defined having ADC */
210
+extern const uint8 boardADCPins[BOARD_NR_ADC_PINS] __FLASH__ = {
211
+  PA0,PA1,PA2,PA3,PA4,PA5,PA6,PA7,PB0,PB1,PC0,PC1,PC2,PC3,PC4,PC5
212
+};
213
+
214
+/* not sure what this us used for */
215
+extern const uint8 boardUsedPins[BOARD_NR_USED_PINS] __FLASH__ = {
216
+  BOARD_JTMS_SWDIO_PIN,
217
+  BOARD_JTCK_SWCLK_PIN, BOARD_JTDI_PIN, BOARD_JTDO_PIN, BOARD_NJTRST_PIN
218
+};
219
+
220
+
221
+#ifdef SERIAL_USB
222
+	DEFINE_HWSERIAL(Serial1, 1);
223
+	DEFINE_HWSERIAL(Serial2, 2);
224
+	DEFINE_HWSERIAL(Serial3, 3);
225
+	DEFINE_HWSERIAL_UART(Serial4, 4);
226
+	DEFINE_HWSERIAL_UART(Serial5, 5);
227
+#else
228
+	DEFINE_HWSERIAL(Serial, 1);
229
+	DEFINE_HWSERIAL(Serial1, 2);
230
+	DEFINE_HWSERIAL(Serial2, 3);
231
+	DEFINE_HWSERIAL_UART(Serial3, 4);
232
+	DEFINE_HWSERIAL_UART(Serial4, 5);
233
+#endif

+ 240
- 0
buildroot/share/PlatformIO/variants/CHITU_F103/board/board.h View File

@@ -0,0 +1,240 @@
1
+/******************************************************************************
2
+ * The MIT License
3
+ *
4
+ * Copyright (c) 2011 LeafLabs, LLC.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person
7
+ * obtaining a copy of this software and associated documentation
8
+ * files (the "Software"), to deal in the Software without
9
+ * restriction, including without limitation the rights to use, copy,
10
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
11
+ * of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be
15
+ * included in all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ * SOFTWARE.
25
+ *****************************************************************************/
26
+
27
+/**
28
+ * @file   maple_RET6.h
29
+ * @author Marti Bolivar <mbolivar@leaflabs.com>
30
+ * @brief  Private include file for Maple RET6 Edition in boards.h
31
+ *
32
+ * See maple.h for more information on these definitions.
33
+ */
34
+
35
+#ifndef _BOARDS_GENERIC_STM32F103Z_H_
36
+#define _BOARDS_GENERIC_STM32F103Z_H_
37
+
38
+/* A few of these values will seem strange given that it's a
39
+ * high-density board. */
40
+
41
+#define CYCLES_PER_MICROSECOND  72
42
+#define SYSTICK_RELOAD_VAL     (F_CPU/1000) - 1 /* takes a cycle to reload */
43
+
44
+// USARTS
45
+#define BOARD_NR_USARTS         5
46
+#define BOARD_USART1_TX_PIN     PA9
47
+#define BOARD_USART1_RX_PIN     PA10
48
+
49
+#define BOARD_USART2_TX_PIN     PA2
50
+#define BOARD_USART2_RX_PIN     PA3
51
+
52
+#define BOARD_USART3_TX_PIN     PB10
53
+#define BOARD_USART3_RX_PIN     PB11
54
+
55
+#define BOARD_USART4_TX_PIN     PC10
56
+#define BOARD_USART4_RX_PIN     PC11
57
+
58
+#define BOARD_USART5_TX_PIN     PC12
59
+#define BOARD_USART5_RX_PIN     PD2
60
+
61
+/* Note:
62
+ *
63
+ * SPI3 is unusable due to pin 43 (PB4) and NRST tie-together :(, but
64
+ * leave the definitions so as not to clutter things up.  This is only
65
+ * OK since RET6 Ed. is specifically advertised as a beta board. */
66
+#define BOARD_NR_SPI            3
67
+#define BOARD_SPI1_NSS_PIN      PA4
68
+#define BOARD_SPI1_SCK_PIN      PA5
69
+#define BOARD_SPI1_MISO_PIN     PA6
70
+#define BOARD_SPI1_MOSI_PIN     PA7
71
+
72
+
73
+
74
+#define BOARD_SPI2_NSS_PIN      PB12
75
+#define BOARD_SPI2_SCK_PIN      PB13
76
+#define BOARD_SPI2_MISO_PIN     PB14
77
+#define BOARD_SPI2_MOSI_PIN     PB15
78
+
79
+
80
+#define BOARD_SPI3_NSS_PIN      PA15
81
+#define BOARD_SPI3_SCK_PIN      PB3
82
+#define BOARD_SPI3_MISO_PIN     PB4
83
+#define BOARD_SPI3_MOSI_PIN     PB5
84
+
85
+
86
+/* GPIO A to E = 5 * 16  - BOOT1 not used = 79*/
87
+#define BOARD_NR_GPIO_PINS      112
88
+/* Note: NOT 19. The missing one is D38 a.k.a. BOARD_BUTTON_PIN, which
89
+ * isn't broken out to a header and is thus unusable for PWM. */
90
+#define BOARD_NR_PWM_PINS       19
91
+#define BOARD_NR_ADC_PINS       16
92
+#define BOARD_NR_USED_PINS      7
93
+
94
+#define BOARD_JTMS_SWDIO_PIN    39
95
+#define BOARD_JTCK_SWCLK_PIN    40
96
+#define BOARD_JTDI_PIN          41
97
+#define BOARD_JTDO_PIN          42
98
+#define BOARD_NJTRST_PIN        43
99
+
100
+/* USB configuration.  BOARD_USB_DISC_DEV is the GPIO port containing
101
+ * the USB_DISC pin, and BOARD_USB_DISC_BIT is that pin's bit. */
102
+#define BOARD_USB_DISC_DEV      GPIOC
103
+#define BOARD_USB_DISC_BIT      12
104
+
105
+/*
106
+ * SDIO Pins
107
+ */
108
+#define BOARD_SDIO_D0 			PC8
109
+#define BOARD_SDIO_D1 			PC9
110
+#define BOARD_SDIO_D2 			PC10
111
+#define BOARD_SDIO_D3 			PC11
112
+#define BOARD_SDIO_CLK 			PC12
113
+#define BOARD_SDIO_CMD 			PD2
114
+
115
+/* Pin aliases: these give the GPIO port/bit for each pin as an
116
+ * enum. These are optional, but recommended. They make it easier to
117
+ * write code using low-level GPIO functionality. */
118
+enum {
119
+PA0,PA1,PA2,PA3,PA4,PA5,PA6,PA7,PA8,PA9,PA10,PA11,PA12,PA13,PA14,PA15,
120
+PB0,PB1,PB2,PB3,PB4,PB5,PB6,PB7,PB8,PB9,PB10,PB11,PB12,PB13,PB14,PB15,
121
+PC0,PC1,PC2,PC3,PC4,PC5,PC6,PC7,PC8,PC9,PC10,PC11,PC12,PC13,PC14,PC15,
122
+PD0,PD1,PD2,PD3,PD4,PD5,PD6,PD7,PD8,PD9,PD10,PD11,PD12,PD13,PD14,PD15,
123
+PE0,PE1,PE2,PE3,PE4,PE5,PE6,PE7,PE8,PE9,PE10,PE11,PE12,PE13,PE14,PE15,
124
+PF0,PF1,PF2,PF3,PF4,PF5,PF6,PF7,PF8,PF9,PF10,PF11,PF12,PF13,PF14,PF15,
125
+PG0,PG1,PG2,PG3,PG4,PG5,PG6,PG7,PG8,PG9,PG10,PG11,PG12,PG13,PG14,PG15
126
+};/* Note PB2 is skipped as this is Boot1 and is not going to be much use as its likely to be pulled permanently low */
127
+/*
128
+#define PA0 0
129
+#define PA1 1
130
+#define PA2 2
131
+#define PA3 3
132
+#define PA4 4
133
+#define PA5 5
134
+#define PA6 6
135
+#define PA7 7
136
+#define PA8 8
137
+#define PA9 9
138
+#define PA10 10
139
+#define PA11 11
140
+#define PA12 12
141
+#define PA13 13
142
+#define PA14 14
143
+#define PA15 15
144
+#define PB0 16
145
+#define PB1 17
146
+#define PB2 18
147
+#define PB3 19
148
+#define PB4 20
149
+#define PB5 21
150
+#define PB6 22
151
+#define PB7 23
152
+#define PB8 24
153
+#define PB9 25
154
+#define PB10 26
155
+#define PB11 27
156
+#define PB12 28
157
+#define PB13 29
158
+#define PB14 30
159
+#define PB15 31
160
+#define PC0 32
161
+#define PC1 33
162
+#define PC2 34
163
+#define PC3 35
164
+#define PC4 36
165
+#define PC5 37
166
+#define PC6 38
167
+#define PC7 39
168
+#define PC8 40
169
+#define PC9 41
170
+#define PC10 42
171
+#define PC11 43
172
+#define PC12 44
173
+#define PC13 45
174
+#define PC14 46
175
+#define PC15 47
176
+#define PD0 48
177
+#define PD1 49
178
+#define PD2 50
179
+#define PD3 51
180
+#define PD4 52
181
+#define PD5 53
182
+#define PD6 54
183
+#define PD7 55
184
+#define PD8 56
185
+#define PD9 57
186
+#define PD10 58
187
+#define PD11 59
188
+#define PD12 60
189
+#define PD13 61
190
+#define PD14 62
191
+#define PD15 63
192
+#define PE0 64
193
+#define PE1 65
194
+#define PE2 66
195
+#define PE3 67
196
+#define PE4 68
197
+#define PE5 69
198
+#define PE6 70
199
+#define PE7 71
200
+#define PE8 72
201
+#define PE9 73
202
+#define PE10 74
203
+#define PE11 75
204
+#define PE12 76
205
+#define PE13 77
206
+#define PE14 78
207
+#define PE15 79
208
+#define PF0 80
209
+#define PF1 81
210
+#define PF2 82
211
+#define PF3 83
212
+#define PF4 84
213
+#define PF5 85
214
+#define PF6 86
215
+#define PF7 87
216
+#define PF8 88
217
+#define PF9 89
218
+#define PF10 90
219
+#define PF11 91
220
+#define PF12 92
221
+#define PF13 93
222
+#define PF14 94
223
+#define PF15 95
224
+#define PG0 96
225
+#define PG1 97
226
+#define PG2 98
227
+#define PG3 99
228
+#define PG4 100
229
+#define PG5 101
230
+#define PG6 102
231
+#define PG7 103
232
+#define PG8 104
233
+#define PG9 105
234
+#define PG10 106
235
+#define PG11 107
236
+#define PG12 108
237
+#define PG13 109
238
+#define PG14 110
239
+#define PG15 111 */
240
+#endif

+ 220
- 0
buildroot/share/PlatformIO/variants/CHITU_F103/ld/common.inc View File

@@ -0,0 +1,220 @@
1
+/*
2
+ * Linker script for libmaple.
3
+ *
4
+ * Original author "lanchon" from ST forums, with modifications by LeafLabs.
5
+ */
6
+
7
+OUTPUT_FORMAT ("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
8
+
9
+/*
10
+ * Configure other libraries we want in the link.
11
+ *
12
+ * libgcc, libc, and libm are common across supported toolchains.
13
+ * However, some toolchains require additional archives which aren't
14
+ * present everywhere (e.g. ARM's gcc-arm-embedded releases).
15
+ *
16
+ * To hack around this, we let the build system specify additional
17
+ * archives by putting the right extra_libs.inc (in a directory under
18
+ * toolchains/) in our search path.
19
+ */
20
+GROUP(libgcc.a libc.a libm.a)
21
+INCLUDE extra_libs.inc
22
+
23
+/*
24
+ * These force the linker to search for vector table symbols.
25
+ *
26
+ * These symbols vary by STM32 family (and also within families).
27
+ * It's up to the build system to configure the link's search path
28
+ * properly for the target MCU.
29
+ */
30
+INCLUDE vector_symbols.inc
31
+
32
+/* STM32 vector table. */
33
+EXTERN(__stm32_vector_table)
34
+
35
+/* C runtime initialization function. */
36
+EXTERN(start_c)
37
+
38
+/* main entry point */
39
+EXTERN(main)
40
+
41
+/* Initial stack pointer value. */
42
+EXTERN(__msp_init)
43
+PROVIDE(__msp_init = ORIGIN(ram) + LENGTH(ram));
44
+
45
+/* Reset vector and chip reset entry point */
46
+EXTERN(__start__)
47
+ENTRY(__start__)
48
+PROVIDE(__exc_reset = __start__);
49
+
50
+/* Heap boundaries, for libmaple */
51
+EXTERN(_lm_heap_start);
52
+EXTERN(_lm_heap_end);
53
+
54
+SECTIONS
55
+{
56
+    .text :
57
+      {
58
+        __text_start__ = .;
59
+        /*
60
+         * STM32 vector table.  Leave this here.  Yes, really.
61
+         */
62
+        *(.stm32.interrupt_vector)
63
+
64
+        /*
65
+         * Program code and vague linking
66
+         */
67
+        *(.text .text.* .gnu.linkonce.t.*)
68
+        *(.plt)
69
+        *(.gnu.warning)
70
+        *(.glue_7t) *(.glue_7) *(.vfp11_veneer)
71
+
72
+        *(.ARM.extab* .gnu.linkonce.armextab.*)
73
+        *(.gcc_except_table)
74
+        *(.eh_frame_hdr)
75
+        *(.eh_frame)
76
+
77
+        . = ALIGN(4);
78
+        KEEP(*(.init))
79
+
80
+        . = ALIGN(4);
81
+        __preinit_array_start = .;
82
+        KEEP (*(.preinit_array))
83
+        __preinit_array_end = .;
84
+
85
+        . = ALIGN(4);
86
+        __init_array_start = .;
87
+        KEEP (*(SORT(.init_array.*)))
88
+        KEEP (*(.init_array))
89
+        __init_array_end = .;
90
+
91
+        . = ALIGN(0x4);
92
+        KEEP (*crtbegin.o(.ctors))
93
+        KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
94
+        KEEP (*(SORT(.ctors.*)))
95
+        KEEP (*crtend.o(.ctors))
96
+
97
+        . = ALIGN(4);
98
+        KEEP(*(.fini))
99
+
100
+        . = ALIGN(4);
101
+        __fini_array_start = .;
102
+        KEEP (*(.fini_array))
103
+        KEEP (*(SORT(.fini_array.*)))
104
+        __fini_array_end = .;
105
+
106
+        KEEP (*crtbegin.o(.dtors))
107
+        KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
108
+        KEEP (*(SORT(.dtors.*)))
109
+        KEEP (*crtend.o(.dtors))
110
+      } > REGION_TEXT
111
+
112
+    /*
113
+     * End of text
114
+     */
115
+    .text.align :
116
+      {
117
+        . = ALIGN(8);
118
+        __text_end__ = .;
119
+      } > REGION_TEXT
120
+
121
+    /*
122
+     * .ARM.exidx exception unwinding; mandated by ARM's C++ ABI
123
+     */
124
+    __exidx_start = .;
125
+    .ARM.exidx :
126
+      {
127
+        *(.ARM.exidx* .gnu.linkonce.armexidx.*)
128
+      } > REGION_RODATA
129
+    __exidx_end = .;
130
+
131
+    /*
132
+     * .data
133
+     */
134
+    .data :
135
+      {
136
+        __data_start__ = .;
137
+      	LONG(0)
138
+        . = ALIGN(8);
139
+
140
+        *(.got.plt) *(.got)
141
+        *(.data .data.* .gnu.linkonce.d.*)
142
+
143
+        . = ALIGN(8);
144
+        __data_end__ = .;
145
+      } > REGION_DATA AT> REGION_RODATA
146
+
147
+    /*
148
+     * Read-only data
149
+     */
150
+    .rodata :
151
+      {
152
+        *(.rodata .rodata.* .gnu.linkonce.r.*)
153
+        /* .USER_FLASH: We allow users to allocate into Flash here */
154
+        *(.USER_FLASH)
155
+        /* ROM image configuration; for C startup */
156
+        . = ALIGN(4);
157
+        _lm_rom_img_cfgp = .;
158
+        LONG(LOADADDR(.data));
159
+        /*
160
+         * Heap: Linker scripts may choose a custom heap by overriding
161
+         * _lm_heap_start and _lm_heap_end. Otherwise, the heap is in
162
+         * internal SRAM, beginning after .bss, and growing towards
163
+         * the stack.
164
+         *
165
+         * I'm shoving these here naively; there's probably a cleaner way
166
+         * to go about this. [mbolivar]
167
+         */
168
+        _lm_heap_start = DEFINED(_lm_heap_start) ? _lm_heap_start : _end;
169
+        _lm_heap_end   = DEFINED(_lm_heap_end) ? _lm_heap_end : __msp_init;
170
+      } > REGION_RODATA
171
+
172
+    /*
173
+     * .bss
174
+     */
175
+    .bss :
176
+      {
177
+        . = ALIGN(8);
178
+        __bss_start__ = .;
179
+        *(.bss .bss.* .gnu.linkonce.b.*)
180
+        *(COMMON)
181
+        . = ALIGN (8);
182
+        __bss_end__ = .;
183
+        _end = __bss_end__;
184
+      } > REGION_BSS
185
+
186
+    /*
187
+     * Debugging sections
188
+     */
189
+    .stab 0 (NOLOAD) : { *(.stab) }
190
+    .stabstr 0 (NOLOAD) : { *(.stabstr) }
191
+    /* DWARF debug sections.
192
+     * Symbols in the DWARF debugging sections are relative to the beginning
193
+     * of the section so we begin them at 0.  */
194
+    /* DWARF 1 */
195
+    .debug          0 : { *(.debug) }
196
+    .line           0 : { *(.line) }
197
+    /* GNU DWARF 1 extensions */
198
+    .debug_srcinfo  0 : { *(.debug_srcinfo) }
199
+    .debug_sfnames  0 : { *(.debug_sfnames) }
200
+    /* DWARF 1.1 and DWARF 2 */
201
+    .debug_aranges  0 : { *(.debug_aranges) }
202
+    .debug_pubnames 0 : { *(.debug_pubnames) }
203
+    /* DWARF 2 */
204
+    .debug_info     0 : { *(.debug_info .gnu.linkonce.wi.*) }
205
+    .debug_abbrev   0 : { *(.debug_abbrev) }
206
+    .debug_line     0 : { *(.debug_line) }
207
+    .debug_frame    0 : { *(.debug_frame) }
208
+    .debug_str      0 : { *(.debug_str) }
209
+    .debug_loc      0 : { *(.debug_loc) }
210
+    .debug_macinfo  0 : { *(.debug_macinfo) }
211
+    /* SGI/MIPS DWARF 2 extensions */
212
+    .debug_weaknames 0 : { *(.debug_weaknames) }
213
+    .debug_funcnames 0 : { *(.debug_funcnames) }
214
+    .debug_typenames 0 : { *(.debug_typenames) }
215
+    .debug_varnames  0 : { *(.debug_varnames) }
216
+
217
+    .note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) }
218
+    .ARM.attributes 0 : { KEEP (*(.ARM.attributes)) }
219
+    /DISCARD/ : { *(.note.GNU-stack) }
220
+}

+ 7
- 0
buildroot/share/PlatformIO/variants/CHITU_F103/ld/extra_libs.inc View File

@@ -0,0 +1,7 @@
1
+/*
2
+ * Extra archives needed by ARM's GCC ARM Embedded arm-none-eabi-
3
+ * releases (https://launchpad.net/gcc-arm-embedded/).
4
+ */
5
+
6
+/* This is for the provided newlib. */
7
+GROUP(libnosys.a)

+ 29
- 0
buildroot/share/PlatformIO/variants/CHITU_F103/ld/stm32f103z_dfu.ld View File

@@ -0,0 +1,29 @@
1
+/*
2
+ * libmaple linker script 
3
+ *
4
+ * This build puts .text (and .rodata) in Flash, and
5
+ * .data/.bss/heap (of course) in SRAM, but links starting at the
6
+ * Flash and SRAM starting addresses (0x08000000 and 0x20000000
7
+ * respectively). This will wipe out a Maple bootloader if there's one
8
+ * on the board, so only use this if you know what you're doing.
9
+ *
10
+ * This build is perfectly usable for upload over SWD,
11
+ * the system memory bootloader, etc. The name is just a historical
12
+ * artifact.
13
+ */
14
+
15
+
16
+MEMORY
17
+{
18
+  ram (rwx) : ORIGIN = 0x20000000, LENGTH = 64K
19
+  rom (rx)  : ORIGIN = 0x08002000, LENGTH = 504K
20
+}
21
+
22
+/* Provide memory region aliases for common.inc */
23
+REGION_ALIAS("REGION_TEXT", rom);
24
+REGION_ALIAS("REGION_DATA", ram);
25
+REGION_ALIAS("REGION_BSS", ram);
26
+REGION_ALIAS("REGION_RODATA", rom);
27
+
28
+/* Let common.inc handle the real work. */
29
+INCLUDE common.inc

+ 27
- 0
buildroot/share/PlatformIO/variants/CHITU_F103/ld/stm32f103zc.ld View File

@@ -0,0 +1,27 @@
1
+/*
2
+ * libmaple linker script 
3
+ *
4
+ * This build puts .text (and .rodata) in Flash, and
5
+ * .data/.bss/heap (of course) in SRAM, but links starting at the
6
+ * Flash and SRAM starting addresses (0x08000000 and 0x20000000
7
+ * respectively). This will wipe out a Maple bootloader if there's one
8
+ * on the board, so only use this if you know what you're doing.
9
+ *
10
+ * This build is perfectly usable for upload over SWD,
11
+ * the system memory bootloader, etc. The name is just a historical
12
+ * artifact.
13
+ */
14
+MEMORY
15
+{
16
+  ram (rwx) : ORIGIN = 0x20000000, LENGTH = 48K
17
+  rom (rx)  : ORIGIN = 0x08000000, LENGTH = 512K
18
+}
19
+
20
+/* Provide memory region aliases for common.inc */
21
+REGION_ALIAS("REGION_TEXT", rom);
22
+REGION_ALIAS("REGION_DATA", ram);
23
+REGION_ALIAS("REGION_BSS", ram);
24
+REGION_ALIAS("REGION_RODATA", rom);
25
+
26
+/* Let common.inc handle the real work. */
27
+INCLUDE common.inc

+ 27
- 0
buildroot/share/PlatformIO/variants/CHITU_F103/ld/stm32f103zd.ld View File

@@ -0,0 +1,27 @@
1
+/*
2
+ * libmaple linker script 
3
+ *
4
+ * This build puts .text (and .rodata) in Flash, and
5
+ * .data/.bss/heap (of course) in SRAM, but links starting at the
6
+ * Flash and SRAM starting addresses (0x08000000 and 0x20000000
7
+ * respectively). This will wipe out a Maple bootloader if there's one
8
+ * on the board, so only use this if you know what you're doing.
9
+ *
10
+ * This build is perfectly usable for upload over SWD,
11
+ * the system memory bootloader, etc. The name is just a historical
12
+ * artifact.
13
+ */
14
+MEMORY
15
+{
16
+  ram (rwx) : ORIGIN = 0x20000000, LENGTH = 64K
17
+  rom (rx)  : ORIGIN = 0x08000000, LENGTH = 512K
18
+}
19
+
20
+/* Provide memory region aliases for common.inc */
21
+REGION_ALIAS("REGION_TEXT", rom);
22
+REGION_ALIAS("REGION_DATA", ram);
23
+REGION_ALIAS("REGION_BSS", ram);
24
+REGION_ALIAS("REGION_RODATA", rom);
25
+
26
+/* Let common.inc handle the real work. */
27
+INCLUDE common.inc

+ 29
- 0
buildroot/share/PlatformIO/variants/CHITU_F103/ld/stm32f103ze.ld View File

@@ -0,0 +1,29 @@
1
+/*
2
+ * libmaple linker script 
3
+ *
4
+ * This build puts .text (and .rodata) in Flash, and
5
+ * .data/.bss/heap (of course) in SRAM, but links starting at the
6
+ * Flash and SRAM starting addresses (0x08000000 and 0x20000000
7
+ * respectively). This will wipe out a Maple bootloader if there's one
8
+ * on the board, so only use this if you know what you're doing.
9
+ *
10
+ * This build is perfectly usable for upload over SWD,
11
+ * the system memory bootloader, etc. The name is just a historical
12
+ * artifact.
13
+ */
14
+
15
+
16
+MEMORY
17
+{
18
+  ram (rwx) : ORIGIN = 0x20000000, LENGTH = 64K
19
+  rom (rx)  : ORIGIN = 0x08000000, LENGTH = 512K
20
+}
21
+
22
+/* Provide memory region aliases for common.inc */
23
+REGION_ALIAS("REGION_TEXT", rom);
24
+REGION_ALIAS("REGION_DATA", ram);
25
+REGION_ALIAS("REGION_BSS", ram);
26
+REGION_ALIAS("REGION_RODATA", rom);
27
+
28
+/* Let common.inc handle the real work. */
29
+INCLUDE common.inc

+ 78
- 0
buildroot/share/PlatformIO/variants/CHITU_F103/ld/vector_symbols.inc View File

@@ -0,0 +1,78 @@
1
+EXTERN(__msp_init)
2
+EXTERN(__exc_reset)
3
+EXTERN(__exc_nmi)
4
+EXTERN(__exc_hardfault)
5
+EXTERN(__exc_memmanage)
6
+EXTERN(__exc_busfault)
7
+EXTERN(__exc_usagefault)
8
+EXTERN(__stm32reservedexception7)
9
+EXTERN(__stm32reservedexception8)
10
+EXTERN(__stm32reservedexception9)
11
+EXTERN(__stm32reservedexception10)
12
+EXTERN(__exc_svc)
13
+EXTERN(__exc_debug_monitor)
14
+EXTERN(__stm32reservedexception13)
15
+EXTERN(__exc_pendsv)
16
+EXTERN(__exc_systick)
17
+
18
+EXTERN(__irq_wwdg)
19
+EXTERN(__irq_pvd)
20
+EXTERN(__irq_tamper)
21
+EXTERN(__irq_rtc)
22
+EXTERN(__irq_flash)
23
+EXTERN(__irq_rcc)
24
+EXTERN(__irq_exti0)
25
+EXTERN(__irq_exti1)
26
+EXTERN(__irq_exti2)
27
+EXTERN(__irq_exti3)
28
+EXTERN(__irq_exti4)
29
+EXTERN(__irq_dma1_channel1)
30
+EXTERN(__irq_dma1_channel2)
31
+EXTERN(__irq_dma1_channel3)
32
+EXTERN(__irq_dma1_channel4)
33
+EXTERN(__irq_dma1_channel5)
34
+EXTERN(__irq_dma1_channel6)
35
+EXTERN(__irq_dma1_channel7)
36
+EXTERN(__irq_adc)
37
+EXTERN(__irq_usb_hp_can_tx)
38
+EXTERN(__irq_usb_lp_can_rx0)
39
+EXTERN(__irq_can_rx1)
40
+EXTERN(__irq_can_sce)
41
+EXTERN(__irq_exti9_5)
42
+EXTERN(__irq_tim1_brk)
43
+EXTERN(__irq_tim1_up)
44
+EXTERN(__irq_tim1_trg_com)
45
+EXTERN(__irq_tim1_cc)
46
+EXTERN(__irq_tim2)
47
+EXTERN(__irq_tim3)
48
+EXTERN(__irq_tim4)
49
+EXTERN(__irq_i2c1_ev)
50
+EXTERN(__irq_i2c1_er)
51
+EXTERN(__irq_i2c2_ev)
52
+EXTERN(__irq_i2c2_er)
53
+EXTERN(__irq_spi1)
54
+EXTERN(__irq_spi2)
55
+EXTERN(__irq_usart1)
56
+EXTERN(__irq_usart2)
57
+EXTERN(__irq_usart3)
58
+EXTERN(__irq_exti15_10)
59
+EXTERN(__irq_rtcalarm)
60
+EXTERN(__irq_usbwakeup)
61
+
62
+EXTERN(__irq_tim8_brk)
63
+EXTERN(__irq_tim8_up)
64
+EXTERN(__irq_tim8_trg_com)
65
+EXTERN(__irq_tim8_cc)
66
+EXTERN(__irq_adc3)
67
+EXTERN(__irq_fsmc)
68
+EXTERN(__irq_sdio)
69
+EXTERN(__irq_tim5)
70
+EXTERN(__irq_spi3)
71
+EXTERN(__irq_uart4)
72
+EXTERN(__irq_uart5)
73
+EXTERN(__irq_tim6)
74
+EXTERN(__irq_tim7)
75
+EXTERN(__irq_dma2_channel1)
76
+EXTERN(__irq_dma2_channel2)
77
+EXTERN(__irq_dma2_channel3)
78
+EXTERN(__irq_dma2_channel4_5)

+ 2
- 0
buildroot/share/PlatformIO/variants/CHITU_F103/pins_arduino.h View File

@@ -0,0 +1,2 @@
1
+// API compatibility
2
+#include "variant.h"

+ 17
- 0
buildroot/share/PlatformIO/variants/CHITU_F103/variant.h View File

@@ -0,0 +1,17 @@
1
+#pragma once
2
+
3
+#define digitalPinToPort(P)        ( PIN_MAP[P].gpio_device )
4
+#define digitalPinToBitMask(P)     ( BIT(PIN_MAP[P].gpio_bit) )
5
+#define portOutputRegister(port)   ( &(port->regs->ODR) )
6
+#define portInputRegister(port)    ( &(port->regs->IDR) )
7
+
8
+#define portSetRegister(pin)       ( &(PIN_MAP[pin].gpio_device->regs->BSRR) )
9
+#define portClearRegister(pin)     ( &(PIN_MAP[pin].gpio_device->regs->BRR) )
10
+
11
+#define portConfigRegister(pin)    ( &(PIN_MAP[pin].gpio_device->regs->CRL) )
12
+
13
+static const uint8_t SS   = BOARD_SPI1_NSS_PIN;
14
+static const uint8_t SS1  = BOARD_SPI2_NSS_PIN;
15
+static const uint8_t MOSI = BOARD_SPI1_MOSI_PIN;
16
+static const uint8_t MISO = BOARD_SPI1_MISO_PIN;
17
+static const uint8_t SCK  = BOARD_SPI1_SCK_PIN;

+ 225
- 0
buildroot/share/PlatformIO/variants/CHITU_F103/wirish/boards.cpp View File

@@ -0,0 +1,225 @@
1
+/******************************************************************************
2
+ * The MIT License
3
+ *
4
+ * Copyright (c) 2010 Perry Hung.
5
+ * Copyright (c) 2011, 2012 LeafLabs, LLC.
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person
8
+ * obtaining a copy of this software and associated documentation
9
+ * files (the "Software"), to deal in the Software without
10
+ * restriction, including without limitation the rights to use, copy,
11
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
12
+ * of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be
16
+ * included in all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
22
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
23
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ * SOFTWARE.
26
+ *****************************************************************************/
27
+
28
+/**
29
+ * @file wirish/boards.cpp
30
+ * @brief init() and board routines.
31
+ *
32
+ * This file is mostly interesting for the init() function, which
33
+ * configures Flash, the core clocks, and a variety of other available
34
+ * peripherals on the board so the rest of Wirish doesn't have to turn
35
+ * things on before using them.
36
+ *
37
+ * Prior to returning, init() calls boardInit(), which allows boards
38
+ * to perform any initialization they need to. This file includes a
39
+ * weak no-op definition of boardInit(), so boards that don't need any
40
+ * special initialization don't have to define their own.
41
+ *
42
+ * How init() works is chip-specific. See the boards_setup.cpp files
43
+ * under e.g. wirish/stm32f1/, wirish/stmf32f2 for the details, but be
44
+ * advised: their contents are unstable, and can/will change without
45
+ * notice.
46
+ */
47
+
48
+#include <boards.h>
49
+#include <libmaple/libmaple_types.h>
50
+#include <libmaple/flash.h>
51
+#include <libmaple/nvic.h>
52
+#include <libmaple/systick.h>
53
+#include "boards_private.h"
54
+
55
+static void setup_flash(void);
56
+static void setup_clocks(void);
57
+static void setup_nvic(void);
58
+static void setup_adcs(void);
59
+static void setup_timers(void);
60
+
61
+/*
62
+ * Exported functions
63
+ */
64
+
65
+void init(void) {
66
+    setup_flash();
67
+    setup_clocks();
68
+    setup_nvic();
69
+    systick_init(SYSTICK_RELOAD_VAL);
70
+    wirish::priv::board_setup_gpio();
71
+    setup_adcs();
72
+    setup_timers();
73
+    wirish::priv::board_setup_usb();
74
+    wirish::priv::series_init();
75
+    boardInit();
76
+}
77
+
78
+/* Provide a default no-op boardInit(). */
79
+__weak void boardInit(void) {
80
+}
81
+
82
+/* You could farm this out to the files in boards/ if e.g. it takes
83
+ * too long to test on boards with lots of pins. */
84
+bool boardUsesPin(uint8 pin) {
85
+    for (int i = 0; i < BOARD_NR_USED_PINS; i++) {
86
+        if (pin == boardUsedPins[i]) {
87
+            return true;
88
+        }
89
+    }
90
+    return false;
91
+}
92
+
93
+/*
94
+ * Auxiliary routines
95
+ */
96
+
97
+static void setup_flash(void) {
98
+    // Turn on as many Flash "go faster" features as
99
+    // possible. flash_enable_features() just ignores any flags it
100
+    // can't support.
101
+    flash_enable_features(FLASH_PREFETCH | FLASH_ICACHE | FLASH_DCACHE);
102
+    // Configure the wait states, assuming we're operating at "close
103
+    // enough" to 3.3V.
104
+    flash_set_latency(FLASH_SAFE_WAIT_STATES);
105
+}
106
+
107
+static void setup_clocks(void) {
108
+    // Turn on HSI. We'll switch to and run off of this while we're
109
+    // setting up the main PLL.
110
+    rcc_turn_on_clk(RCC_CLK_HSI);
111
+
112
+    // Turn off and reset the clock subsystems we'll be using, as well
113
+    // as the clock security subsystem (CSS). Note that resetting CFGR
114
+    // to its default value of 0 implies a switch to HSI for SYSCLK.
115
+    RCC_BASE->CFGR = 0x00000000;
116
+    rcc_disable_css();
117
+    rcc_turn_off_clk(RCC_CLK_PLL);
118
+    rcc_turn_off_clk(RCC_CLK_HSE);
119
+    wirish::priv::board_reset_pll();
120
+    // Clear clock readiness interrupt flags and turn off clock
121
+    // readiness interrupts.
122
+    RCC_BASE->CIR = 0x00000000;
123
+#if !USE_HSI_CLOCK
124
+    // Enable HSE, and wait until it's ready.
125
+    rcc_turn_on_clk(RCC_CLK_HSE);
126
+    while (!rcc_is_clk_ready(RCC_CLK_HSE))
127
+        ;
128
+#endif
129
+    // Configure AHBx, APBx, etc. prescalers and the main PLL.
130
+    wirish::priv::board_setup_clock_prescalers();
131
+    rcc_configure_pll(&wirish::priv::w_board_pll_cfg);
132
+
133
+    // Enable the PLL, and wait until it's ready.
134
+    rcc_turn_on_clk(RCC_CLK_PLL);
135
+    while(!rcc_is_clk_ready(RCC_CLK_PLL))
136
+        ;
137
+
138
+    // Finally, switch to the now-ready PLL as the main clock source.
139
+    rcc_switch_sysclk(RCC_CLKSRC_PLL);
140
+}
141
+
142
+/*
143
+ * These addresses are where usercode starts when a bootloader is
144
+ * present. If no bootloader is present, the user NVIC usually starts
145
+ * at the Flash base address, 0x08000000.
146
+ */
147
+#if defined(BOOTLOADER_maple)
148
+	#define USER_ADDR_ROM 0x08005000
149
+#else
150
+	#define USER_ADDR_ROM 0x08000000
151
+#endif
152
+#define USER_ADDR_RAM 0x20000C00
153
+extern char __text_start__;
154
+
155
+static void setup_nvic(void) {
156
+
157
+nvic_init((uint32)VECT_TAB_ADDR, 0);
158
+
159
+/* Roger Clark. We now control nvic vector table in boards.txt using the build.vect paramater
160
+#ifdef VECT_TAB_FLASH
161
+    nvic_init(USER_ADDR_ROM, 0);
162
+#elif defined VECT_TAB_RAM
163
+    nvic_init(USER_ADDR_RAM, 0);
164
+#elif defined VECT_TAB_BASE
165
+    nvic_init((uint32)0x08000000, 0);
166
+#elif defined VECT_TAB_ADDR
167
+    // A numerically supplied value
168
+    nvic_init((uint32)VECT_TAB_ADDR, 0);
169
+#else
170
+    // Use the __text_start__ value from the linker script; this
171
+    // should be the start of the vector table.
172
+    nvic_init((uint32)&__text_start__, 0);
173
+#endif
174
+
175
+*/
176
+}
177
+
178
+static void adc_default_config(adc_dev *dev) {
179
+    adc_enable_single_swstart(dev);
180
+    adc_set_sample_rate(dev, wirish::priv::w_adc_smp);
181
+}
182
+
183
+static void setup_adcs(void) {
184
+    adc_set_prescaler(wirish::priv::w_adc_pre);
185
+    adc_foreach(adc_default_config);
186
+}
187
+
188
+static void timer_default_config(timer_dev *dev) {
189
+    timer_adv_reg_map *regs = (dev->regs).adv;
190
+    const uint16 full_overflow = 0xFFFF;
191
+    const uint16 half_duty = 0x8FFF;
192
+
193
+    timer_init(dev);
194
+    timer_pause(dev);
195
+
196
+    regs->CR1 = TIMER_CR1_ARPE;
197
+    regs->PSC = 1;
198
+    regs->SR = 0;
199
+    regs->DIER = 0;
200
+    regs->EGR = TIMER_EGR_UG;
201
+    switch (dev->type) {
202
+    case TIMER_ADVANCED:
203
+        regs->BDTR = TIMER_BDTR_MOE | TIMER_BDTR_LOCK_OFF;
204
+        // fall-through
205
+    case TIMER_GENERAL:
206
+        timer_set_reload(dev, full_overflow);
207
+        for (uint8 channel = 1; channel <= 4; channel++) {
208
+            if (timer_has_cc_channel(dev, channel)) {
209
+                timer_set_compare(dev, channel, half_duty);
210
+                timer_oc_set_mode(dev, channel, TIMER_OC_MODE_PWM_1,
211
+                                  TIMER_OC_PE);
212
+            }
213
+        }
214
+        // fall-through
215
+    case TIMER_BASIC:
216
+        break;
217
+    }
218
+
219
+    timer_generate_update(dev);
220
+    timer_resume(dev);
221
+}
222
+
223
+static void setup_timers(void) {
224
+    timer_foreach(timer_default_config);
225
+}

+ 123
- 0
buildroot/share/PlatformIO/variants/CHITU_F103/wirish/boards_setup.cpp View File

@@ -0,0 +1,123 @@
1
+/******************************************************************************
2
+ * The MIT License
3
+ *
4
+ * Copyright (c) 2012 LeafLabs, LLC.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person
7
+ * obtaining a copy of this software and associated documentation
8
+ * files (the "Software"), to deal in the Software without
9
+ * restriction, including without limitation the rights to use, copy,
10
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
11
+ * of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be
15
+ * included in all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ * SOFTWARE.
25
+*****************************************************************************/
26
+
27
+/**
28
+ * @file wirish/stm32f1/boards_setup.cpp
29
+ * @author Marti Bolivar <mbolivar@leaflabs.com>
30
+ * @brief STM32F1 chip setup.
31
+ *
32
+ * This file controls how init() behaves on the STM32F1. Be very
33
+ * careful when changing anything here. Many of these values depend
34
+ * upon each other.
35
+ */
36
+
37
+#include "boards_private.h"
38
+
39
+#include <libmaple/gpio.h>
40
+#include <libmaple/timer.h>
41
+
42
+#include <boards.h>
43
+#include <usb_serial.h>
44
+
45
+// Allow boards to provide a PLL multiplier. This is useful for
46
+// e.g. STM32F100 value line MCUs, which use slower multipliers.
47
+// (We're leaving the default to RCC_PLLMUL_9 for now, since that
48
+// works for F103 performance line MCUs, which is all that LeafLabs
49
+// currently officially supports).
50
+#ifndef BOARD_RCC_PLLMUL
51
+  #if !USE_HSI_CLOCK
52
+  #if F_CPU==128000000
53
+    #define BOARD_RCC_PLLMUL RCC_PLLMUL_16
54
+  #elif F_CPU==72000000
55
+    #define BOARD_RCC_PLLMUL RCC_PLLMUL_9
56
+  #elif F_CPU==48000000
57
+    #define BOARD_RCC_PLLMUL RCC_PLLMUL_6
58
+  #elif F_CPU==16000000
59
+    #define BOARD_RCC_PLLMUL RCC_PLLMUL_2
60
+  #endif
61
+  #else
62
+  #define BOARD_RCC_PLLMUL RCC_PLLMUL_16
63
+  #endif
64
+#endif
65
+
66
+namespace wirish {
67
+    namespace priv {
68
+
69
+        static stm32f1_rcc_pll_data pll_data = {BOARD_RCC_PLLMUL};
70
+#if !USE_HSI_CLOCK
71
+        __weak rcc_pll_cfg w_board_pll_cfg = {RCC_PLLSRC_HSE, &pll_data};
72
+#else
73
+        __weak rcc_pll_cfg w_board_pll_cfg = {RCC_PLLSRC_HSI_DIV_2, &pll_data};
74
+#endif
75
+        __weak adc_prescaler w_adc_pre = ADC_PRE_PCLK2_DIV_6;
76
+        __weak adc_smp_rate w_adc_smp = ADC_SMPR_55_5;
77
+
78
+        __weak void board_reset_pll(void) {
79
+            // TODO
80
+        }
81
+
82
+        __weak void board_setup_clock_prescalers(void) {
83
+            rcc_set_prescaler(RCC_PRESCALER_AHB, RCC_AHB_SYSCLK_DIV_1);
84
+            rcc_set_prescaler(RCC_PRESCALER_APB1, RCC_APB1_HCLK_DIV_2);
85
+            rcc_set_prescaler(RCC_PRESCALER_APB2, RCC_APB2_HCLK_DIV_1);
86
+      rcc_clk_disable(RCC_USB);
87
+      #if F_CPU == 72000000
88
+      rcc_set_prescaler(RCC_PRESCALER_USB, RCC_USB_SYSCLK_DIV_1_5);
89
+      #elif F_CPU == 48000000
90
+      rcc_set_prescaler(RCC_PRESCALER_USB, RCC_USB_SYSCLK_DIV_1);     
91
+      #endif  
92
+        }
93
+
94
+        __weak void board_setup_gpio(void) {
95
+            gpio_init_all();
96
+        }
97
+
98
+        __weak void board_setup_usb(void) {
99
+      
100
+
101
+  
102
+#ifdef SERIAL_USB 
103
+#ifdef GENERIC_BOOTLOADER     
104
+      //Reset the USB interface on generic boards - developed by Victor PV
105
+      gpio_set_mode(PIN_MAP[PA12].gpio_device, PIN_MAP[PA12].gpio_bit, GPIO_OUTPUT_PP);
106
+      gpio_write_bit(PIN_MAP[PA12].gpio_device, PIN_MAP[PA12].gpio_bit,0);
107
+      
108
+      for(volatile unsigned int i=0;i<512;i++);// Only small delay seems to be needed, and USB pins will get configured in Serial.begin
109
+      gpio_set_mode(PIN_MAP[PA12].gpio_device, PIN_MAP[PA12].gpio_bit, GPIO_INPUT_FLOATING);
110
+#endif  
111
+
112
+      Serial.begin();// Roger Clark. Changed SerialUSB to Serial for Arduino sketch compatibility
113
+#endif
114
+        }
115
+
116
+        __weak void series_init(void) {
117
+            // Initialize AFIO here, too, so peripheral remaps and external
118
+            // interrupts work out of the box.
119
+            afio_init();
120
+        }
121
+
122
+    }
123
+}

+ 57
- 0
buildroot/share/PlatformIO/variants/CHITU_F103/wirish/start.S View File

@@ -0,0 +1,57 @@
1
+/******************************************************************************
2
+ * The MIT License
3
+ *
4
+ * Copyright (c) 2011 LeafLabs, LLC.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person
7
+ * obtaining a copy of this software and associated documentation
8
+ * files (the "Software"), to deal in the Software without
9
+ * restriction, including without limitation the rights to use, copy,
10
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
11
+ * of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be
15
+ * included in all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ * SOFTWARE.
25
+ *****************************************************************************/
26
+
27
+/*
28
+ * This file is a modified version of a file obtained from
29
+ * CodeSourcery Inc. (now part of Mentor Graphics Corp.), in which the
30
+ * following text appeared:
31
+ *
32
+ * The authors hereby grant permission to use, copy, modify, distribute,
33
+ * and license this software and its documentation for any purpose, provided
34
+ * that existing copyright notices are retained in all copies and that this
35
+ * notice is included verbatim in any distributions. No written agreement,
36
+ * license, or royalty fee is required for any of the authorized uses.
37
+ * Modifications to this software may be copyrighted by their authors
38
+ * and need not follow the licensing terms described here, provided that
39
+ * the new terms are clearly indicated on the first page of each file where
40
+ * they apply.
41
+ */
42
+
43
+        .text
44
+        .code 16
45
+        .thumb_func
46
+
47
+        .globl __start__
48
+        .type __start__, %function
49
+__start__:
50
+        .fnstart
51
+        ldr r1,=__msp_init
52
+        mov sp,r1
53
+        ldr r1,=start_c
54
+        bx r1
55
+        .pool
56
+        .cantunwind
57
+        .fnend

+ 144
- 0
buildroot/share/PlatformIO/variants/CHITU_F103/wirish/start_c.c View File

@@ -0,0 +1,144 @@
1
+/******************************************************************************
2
+ * The MIT License
3
+ *
4
+ * Copyright (c) 2011 LeafLabs, LLC.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person
7
+ * obtaining a copy of this software and associated documentation
8
+ * files (the "Software"), to deal in the Software without
9
+ * restriction, including without limitation the rights to use, copy,
10
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
11
+ * of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be
15
+ * included in all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ * SOFTWARE.
25
+ *****************************************************************************/
26
+
27
+/*
28
+ * This file is a modified version of a file obtained from
29
+ * CodeSourcery Inc. (now part of Mentor Graphics Corp.), in which the
30
+ * following text appeared:
31
+ *
32
+ * Copyright (c) 2006, 2007 CodeSourcery Inc
33
+ *
34
+ * The authors hereby grant permission to use, copy, modify, distribute,
35
+ * and license this software and its documentation for any purpose, provided
36
+ * that existing copyright notices are retained in all copies and that this
37
+ * notice is included verbatim in any distributions. No written agreement,
38
+ * license, or royalty fee is required for any of the authorized uses.
39
+ * Modifications to this software may be copyrighted by their authors
40
+ * and need not follow the licensing terms described here, provided that
41
+ * the new terms are clearly indicated on the first page of each file where
42
+ * they apply.
43
+ */
44
+
45
+#include <stddef.h>
46
+
47
+#include <libmaple/rcc.h>
48
+#include <libmaple/libmaple.h>
49
+#include <libmaple/bitband.h>
50
+
51
+#include "rcc_private.h"
52
+
53
+#include <libmaple/usart.h>
54
+#include <libmaple/gpio.h>
55
+#include "usart_private.h"
56
+
57
+#include <libmaple/sdio.h>
58
+#include <string.h>
59
+
60
+extern void __libc_init_array(void);
61
+
62
+extern int main(int, char**, char**);
63
+
64
+extern void exit(int) __attribute__((noreturn, weak));
65
+
66
+/* The linker must ensure that these are at least 4-byte aligned. */
67
+extern char __data_start__, __data_end__;
68
+extern char __bss_start__, __bss_end__;
69
+
70
+struct rom_img_cfg {
71
+    int *img_start;
72
+};
73
+
74
+extern char _lm_rom_img_cfgp;
75
+extern void __lm_error();
76
+extern void timer_disable_all();
77
+
78
+    /* Turn off ADC */
79
+extern void adc_disable_all();
80
+
81
+    /* Turn off all USARTs */
82
+extern void usart_disable_all();
83
+extern void DisableEverything();
84
+
85
+void __attribute__((noreturn)) start_c(void) {
86
+    struct rom_img_cfg *img_cfg = (struct rom_img_cfg*)&_lm_rom_img_cfgp;
87
+    int *src = img_cfg->img_start;
88
+    int *dst = (int*)&__data_start__;
89
+    int exit_code;
90
+
91
+    asm("CPSID I");
92
+    /* Reset the RCC clock configuration to the default reset state(for debug purpose) */
93
+    /* Set HSION bit */
94
+    RCC_BASE->CR |= 0x00000001U;
95
+
96
+    /* Reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits */
97
+    RCC_BASE->CFGR &= 0xF0FF0000U;
98
+
99
+    /* Reset HSEON, CSSON and PLLON bits */
100
+    RCC_BASE->CR &= 0xFEF6FFFFU;
101
+
102
+    /* Reset HSEBYP bit */
103
+    RCC_BASE->CR &= 0xFFFBFFFFU;
104
+
105
+    /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE/OTGFSPRE bits */
106
+    RCC_BASE->CFGR &= 0xFF80FFFFU;
107
+
108
+    /* Disable all interrupts and clear pending bits  */
109
+    RCC_BASE->CIR = 0x009F0000U;
110
+
111
+    USART1_BASE->CR1 = 0;
112
+    USART1_BASE->CR2 = 0;
113
+    USART1_BASE->CR3 = 0;
114
+
115
+    memset(SDIO_BASE, 0, sizeof(sdio_reg_map));
116
+    asm("CPSIE I");
117
+
118
+    /* Initialize .data, if necessary. */
119
+    if (src != dst) {
120
+        int *end = (int*)&__data_end__;
121
+        while (dst < end) {
122
+            *dst++ = *src++;
123
+        }
124
+    }
125
+
126
+    /* Zero .bss. */
127
+    dst = (int*)&__bss_start__;
128
+    while (dst < (int*)&__bss_end__) {
129
+        *dst++ = 0;
130
+    }
131
+
132
+    /* Run initializers. */
133
+    __libc_init_array();
134
+
135
+    /* Jump to main. */
136
+    exit_code = main(0, 0, 0);
137
+    if (exit) {
138
+        exit(exit_code);
139
+    }
140
+
141
+    /* If exit is NULL, make sure we don't return. */
142
+    for (;;)
143
+        continue;
144
+}

+ 176
- 0
buildroot/share/PlatformIO/variants/CHITU_F103/wirish/syscalls.c View File

@@ -0,0 +1,176 @@
1
+/******************************************************************************
2
+ * The MIT License
3
+ *
4
+ * Copyright (c) 2010 Perry Hung.
5
+ * Copyright (c) 2011, 2012 LeafLabs, LLC.
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person
8
+ * obtaining a copy of this software and associated documentation
9
+ * files (the "Software"), to deal in the Software without
10
+ * restriction, including without limitation the rights to use, copy,
11
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
12
+ * of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be
16
+ * included in all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
22
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
23
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ * SOFTWARE.
26
+ *****************************************************************************/
27
+
28
+/**
29
+ * @file wirish/syscalls.c
30
+ * @brief newlib stubs
31
+ *
32
+ * Low level system routines used by newlib for basic I/O and memory
33
+ * allocation. You can override most of these.
34
+ */
35
+
36
+#include <libmaple/libmaple.h>
37
+
38
+#include <sys/stat.h>
39
+#include <errno.h>
40
+#include <stddef.h>
41
+
42
+/* If CONFIG_HEAP_START (or CONFIG_HEAP_END) isn't defined, then
43
+ * assume _lm_heap_start (resp. _lm_heap_end) is appropriately set by
44
+ * the linker */
45
+#ifndef CONFIG_HEAP_START
46
+extern char _lm_heap_start;
47
+#define CONFIG_HEAP_START               ((void *)&_lm_heap_start)
48
+#endif
49
+#ifndef CONFIG_HEAP_END
50
+extern char _lm_heap_end;
51
+#define CONFIG_HEAP_END                 ((void *)&_lm_heap_end)
52
+#endif
53
+
54
+/*
55
+ * _sbrk -- Increment the program break.
56
+ *
57
+ * Get incr bytes more RAM (for use by the heap).  malloc() and
58
+ * friends call this function behind the scenes.
59
+ */
60
+void *_sbrk(int incr) {
61
+    static void * pbreak = NULL; /* current program break */
62
+    void * ret;
63
+
64
+    if (pbreak == NULL) {
65
+        pbreak = CONFIG_HEAP_START;
66
+    }
67
+
68
+    if ((CONFIG_HEAP_END - pbreak < incr) ||
69
+        (pbreak - CONFIG_HEAP_START < -incr)) {
70
+        errno = ENOMEM;
71
+        return (void *)-1;
72
+    }
73
+
74
+    ret = pbreak;
75
+    pbreak += incr;
76
+    return ret;
77
+}
78
+
79
+__weak int _open(const char *path __attribute__((unused)), int flags __attribute__((unused)), ...) {
80
+    return 1;
81
+}
82
+
83
+__weak int _close(int fd __attribute__((unused))) {
84
+    return 0;
85
+}
86
+
87
+__weak int _fstat(int fd __attribute__((unused)), struct stat *st) {
88
+    st->st_mode = S_IFCHR;
89
+    return 0;
90
+}
91
+
92
+__weak int _isatty(int fd __attribute__((unused))) {
93
+    return 1;
94
+}
95
+
96
+__weak int isatty(int fd __attribute__((unused))) {
97
+    return 1;
98
+}
99
+
100
+__weak int _lseek(int fd __attribute__((unused)), off_t pos __attribute__((unused)), int whence __attribute__((unused))) {
101
+    return -1;
102
+}
103
+
104
+__weak unsigned char getch(void) {
105
+    return 0;
106
+}
107
+
108
+
109
+__weak int _read(int fd __attribute__((unused)), char *buf, size_t cnt __attribute__((unused))) {
110
+    *buf = getch();
111
+
112
+    return 1;
113
+}
114
+
115
+__weak void putch(unsigned char c __attribute__((unused))) {
116
+}
117
+
118
+__weak void cgets(char *s, int bufsize) {
119
+    char *p;
120
+    int c;
121
+    int i;
122
+
123
+    for (i = 0; i < bufsize; i++) {
124
+        *(s+i) = 0;
125
+    }
126
+//    memset(s, 0, bufsize);
127
+
128
+    p = s;
129
+
130
+    for (p = s; p < s + bufsize-1;) {
131
+        c = getch();
132
+        switch (c) {
133
+        case '\r' :
134
+        case '\n' :
135
+            putch('\r');
136
+            putch('\n');
137
+            *p = '\n';
138
+            return;
139
+
140
+        case '\b' :
141
+            if (p > s) {
142
+                *p-- = 0;
143
+                putch('\b');
144
+                putch(' ');
145
+                putch('\b');
146
+            }
147
+            break;
148
+
149
+        default :
150
+            putch(c);
151
+            *p++ = c;
152
+            break;
153
+        }
154
+    }
155
+    return;
156
+}
157
+
158
+__weak int _write(int fd __attribute__((unused)), const char *buf, size_t cnt) {
159
+    int i;
160
+
161
+    for (i = 0; i < cnt; i++)
162
+        putch(buf[i]);
163
+
164
+    return cnt;
165
+}
166
+
167
+/* Override fgets() in newlib with a version that does line editing */
168
+__weak char *fgets(char *s, int bufsize, void *f __attribute__((unused))) {
169
+    cgets(s, bufsize);
170
+    return s;
171
+}
172
+
173
+__weak void _exit(int exitcode __attribute__((unused))) {
174
+    while (1)
175
+        ;
176
+}

+ 3
- 2
platformio.ini View File

@@ -646,8 +646,9 @@ lib_ignore  = LiquidCrystal, LiquidTWI2, Adafruit NeoPixel, TMCStepper, U8glib-H
646 646
 [env:chitu_f103]
647 647
 platform      = ${common_stm32f1.platform}
648 648
 extends       = common_stm32f1
649
-board         = genericSTM32F103ZE
650
-#extra_scripts = buildroot/share/PlatformIO/scripts/chitu_crypt.py
649
+board         = chitu_f103
650
+extra_scripts = pre:buildroot/share/PlatformIO/scripts/STM32F1_create_variant.py
651
+  buildroot/share/PlatformIO/scripts/chitu_crypt.py
651 652
 build_flags   = ${common_stm32f1.build_flags}
652 653
   -DSTM32F1xx -DSTM32_XL_DENSITY
653 654
 build_unflags = ${common_stm32f1.build_unflags}

Loading…
Cancel
Save