Skip to content

Commit 266ab9f

Browse files
committed
Merge pull request #8 from rogerclarkmelbourne/master
Synching to Roger's
2 parents 37cdca0 + 7bea296 commit 266ab9f

664 files changed

Lines changed: 132623 additions & 615 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

GD32F1/boards.txt

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# GD32 Boards
2+
3+
4+
menu.device_variant=Variant
5+
menu.bootloader_version=Bootloader version
6+
menu.upload_method=Upload method
7+
menu.cpu_speed=CPU Speed(MHz)
8+
9+
10+
###################### Generic GD32F103C ########################################
11+
12+
genericGD32F103C.name=Generic GD32F103C series
13+
genericGD32F103C.build.variant=generic_GD32f103c
14+
genericGD32F103C.build.vect=VECT_TAB_ADDR=0x8000000
15+
genericGD32F103C.build.core=maple
16+
genericGD32F103C.build.board=GENERIC_GD32F103C
17+
genericGD32F103C.upload.use_1200bps_touch=false
18+
genericGD32F103C.upload.file_type=bin
19+
genericGD32F103C.upload.auto_reset=true
20+
genericGD32F103C.build.cpu_flags=-DMCU_STM32F103CB
21+
genericGD32F103C.build.f_cpu=72000000L
22+
23+
## GD32F103CB -------------------------
24+
genericGD32F103C.menu.device_variant.GD32F103CB=GD32F103CB (20k RAM. 128k Flash)
25+
genericGD32F103C.menu.device_variant.GD32F103CB.build.ldscript=ld/jtag.ld
26+
genericGD32F103C.menu.device_variant.GD32F103CB.upload.maximum_size=131072
27+
genericGD32F103C.menu.device_variant.GD32F103CB.upload.ram.maximum_size=20480
28+
genericGD32F103C.menu.device_variant.GD32F103CB.upload.flash.maximum_size=131072
29+
30+
31+
## GD32F103C8 -------------------------
32+
genericGD32F103C.menu.device_variant.GD32F103C8=GD32F103C8 (20k RAM. 64k Flash)
33+
genericGD32F103C.menu.device_variant.GD32F103C8.build.ldscript=ld/jtag_c8.ld
34+
genericGD32F103C.menu.device_variant.GD32F103C8.upload.maximum_size=65536
35+
genericGD32F103C.menu.device_variant.GD32F103C8.upload.ram.maximum_size=20480
36+
genericGD32F103C.menu.device_variant.GD32F103C8.upload.flash.maximum_size=65536
37+
38+
#---------------------------- UPLOAD METHODS ---------------------------
39+
40+
genericGD32F103C.menu.upload_method.DFUUploadMethod=GD32duino bootloader
41+
42+
genericGD32F103C.menu.upload_method.DFUUploadMethod.upload.protocol=maple_dfu
43+
genericGD32F103C.menu.upload_method.DFUUploadMethod.upload.tool=maple_upload
44+
genericGD32F103C.menu.upload_method.DFUUploadMethod.build.upload_flags=-DSERIAL_USB -DGENERIC_BOOTLOADER
45+
genericGD32F103C.menu.upload_method.DFUUploadMethod.build.vect=VECT_TAB_ADDR=0x8002000
46+
genericGD32F103C.menu.upload_method.DFUUploadMethod.build.ldscript=ld/bootloader_20.ld
47+
genericGD32F103C.menu.upload_method.DFUUploadMethod.upload.usbID=1EAF:0003
48+
genericGD32F103C.menu.upload_method.DFUUploadMethod.upload.altID=2
49+
50+
genericGD32F103C.menu.upload_method.serialMethod=Serial
51+
genericGD32F103C.menu.upload_method.serialMethod.upload.protocol=maple_serial
52+
genericGD32F103C.menu.upload_method.serialMethod.upload.tool=serial_upload
53+
54+
55+
genericGD32F103C.menu.upload_method.STLinkMethod=STLink
56+
genericGD32F103C.menu.upload_method.STLinkMethod.upload.protocol=STLink
57+
genericGD32F103C.menu.upload_method.STLinkMethod.upload.tool=stlink_upload
58+
genericGD32F103C.menu.upload_method.STLinkMethod.build.upload_flags=-DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG=1 -DSERIAL_USB -DGENERIC_BOOTLOADER
59+
60+
61+
genericGD32F103C.menu.upload_method.BMPMethod=BMP (Black Magic Probe)
62+
genericGD32F103C.menu.upload_method.BMPMethod.upload.protocol=gdb_bmp
63+
genericGD32F103C.menu.upload_method.BMPMethod.upload.tool=bmp_upload
64+
genericGD32F103C.menu.upload_method.BMPMethod.build.upload_flags=-DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG
65+
66+
genericGD32F103C.menu.cpu_speed.speed_120mhz=120Mhz (overdrive)
67+
genericGD32F103C.menu.cpu_speed.speed_120mhz.build.f_cpu=120000000L
68+
69+
genericGD32F103C.menu.cpu_speed.speed_96mhz=96Mhz (Stable)
70+
genericGD32F103C.menu.cpu_speed.speed_96mhz.build.f_cpu=96000000L
71+
72+
genericGD32F103C.menu.cpu_speed.speed_72mhz=72Mhz (compatibility)
73+
genericGD32F103C.menu.cpu_speed.speed_72mhz.build.f_cpu=72000000L
74+

GD32F1/cores/maple/Arduino.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/******************************************************************************
2+
* The MIT License
3+
*
4+
* Copyright (c) 2010 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+
#ifndef _WIRISH_WPROGRAM_H_
28+
#define _WIRISH_WPROGRAM_H_
29+
30+
#include "wirish.h"
31+
32+
void setup();
33+
void loop();
34+
#ifdef __cplusplus
35+
extern "C"{
36+
#endif // __cplusplus
37+
void yield(void);
38+
#ifdef __cplusplus
39+
}
40+
#endif // __cplusplus
41+
42+
#include "variant.h"
43+
44+
#endif
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
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/HardwareSerial.cpp
30+
* @brief Wirish serial port implementation.
31+
*/
32+
33+
#include "HardwareSerial.h"
34+
35+
#include <libmaple/libmaple.h>
36+
#include <libmaple/gpio.h>
37+
#include <libmaple/timer.h>
38+
#include <libmaple/usart.h>
39+
40+
#if 0
41+
42+
#define DEFINE_HWSERIAL(name, n) \
43+
HardwareSerial name(USART##n, \
44+
BOARD_USART##n##_TX_PIN, \
45+
BOARD_USART##n##_RX_PIN)
46+
47+
#define DEFINE_HWSERIAL_UART(name, n) \
48+
HardwareSerial name(UART##n, \
49+
BOARD_USART##n##_TX_PIN, \
50+
BOARD_USART##n##_RX_PIN)
51+
52+
#ifdef SERIAL_USB
53+
#if BOARD_HAVE_USART1
54+
DEFINE_HWSERIAL(Serial1, 1);
55+
#endif
56+
#if BOARD_HAVE_USART2
57+
DEFINE_HWSERIAL(Serial2, 2);
58+
#endif
59+
#if BOARD_HAVE_USART3
60+
DEFINE_HWSERIAL(Serial3, 3);
61+
#endif
62+
#if BOARD_HAVE_UART4
63+
DEFINE_HWSERIAL_UART(Serial4, 4);
64+
#endif
65+
#if BOARD_HAVE_UART5
66+
DEFINE_HWSERIAL_UART(Serial5, 5);
67+
#endif
68+
#if BOARD_HAVE_USART6
69+
DEFINE_HWSERIAL_UART(Serial6, 6);
70+
#endif
71+
#else
72+
#if BOARD_HAVE_USART1
73+
DEFINE_HWSERIAL(Serial, 1);
74+
#endif
75+
#if BOARD_HAVE_USART2
76+
DEFINE_HWSERIAL(Serial1, 2);
77+
#endif
78+
#if BOARD_HAVE_USART3
79+
DEFINE_HWSERIAL(Serial2, 3);
80+
#endif
81+
#if BOARD_HAVE_UART4
82+
DEFINE_HWSERIAL_UART(Serial3, 4);
83+
#endif
84+
#if BOARD_HAVE_UART5
85+
DEFINE_HWSERIAL_UART(Serial4, 5);
86+
#endif
87+
#if BOARD_HAVE_USART6
88+
DEFINE_HWSERIAL_UART(Serial5, 6);
89+
#endif
90+
#endif
91+
92+
#endif
93+
HardwareSerial::HardwareSerial(usart_dev *usart_device,
94+
uint8 tx_pin,
95+
uint8 rx_pin) {
96+
this->usart_device = usart_device;
97+
this->tx_pin = tx_pin;
98+
this->rx_pin = rx_pin;
99+
}
100+
101+
/*
102+
* Set up/tear down
103+
*/
104+
105+
#if STM32_MCU_SERIES == STM32_SERIES_F1
106+
/* F1 MCUs have no GPIO_AFR[HL], so turn off PWM if there's a conflict
107+
* on this GPIO bit. */
108+
static void disable_timer_if_necessary(timer_dev *dev, uint8 ch) {
109+
if (dev != NULL) {
110+
timer_set_mode(dev, ch, TIMER_DISABLED);
111+
}
112+
}
113+
#elif (STM32_MCU_SERIES == STM32_SERIES_F2) || \
114+
(STM32_MCU_SERIES == STM32_SERIES_F4)
115+
#define disable_timer_if_necessary(dev, ch) ((void)0)
116+
#else
117+
#warning "Unsupported STM32 series; timer conflicts are possible"
118+
#endif
119+
120+
void HardwareSerial::begin(uint32 baud)
121+
{
122+
begin(baud,SERIAL_8N1);
123+
}
124+
/*
125+
* Roger Clark.
126+
* Note. The config parameter is not currently used. This is a work in progress.
127+
* Code needs to be written to set the config of the hardware serial control register in question.
128+
*
129+
*/
130+
131+
void HardwareSerial::begin(uint32 baud, uint8_t config)
132+
{
133+
// ASSERT(baud <= this->usart_device->max_baud);// Roger Clark. Assert doesn't do anything useful, we may as well save the space in flash and ram etc
134+
135+
if (baud > this->usart_device->max_baud) {
136+
return;
137+
}
138+
139+
const stm32_pin_info *txi = &PIN_MAP[this->tx_pin];
140+
const stm32_pin_info *rxi = &PIN_MAP[this->rx_pin];
141+
142+
disable_timer_if_necessary(txi->timer_device, txi->timer_channel);
143+
144+
usart_config_gpios_async(this->usart_device,
145+
rxi->gpio_device, rxi->gpio_bit,
146+
txi->gpio_device, txi->gpio_bit,
147+
config);
148+
usart_init(this->usart_device);
149+
usart_set_baud_rate(this->usart_device, USART_USE_PCLK, baud);
150+
usart_enable(this->usart_device);
151+
}
152+
153+
void HardwareSerial::end(void) {
154+
usart_disable(this->usart_device);
155+
}
156+
157+
/*
158+
* I/O
159+
*/
160+
161+
int HardwareSerial::read(void) {
162+
// Block until a byte becomes available, to save user confusion.
163+
while (!this->available())
164+
;
165+
return usart_getc(this->usart_device);
166+
}
167+
168+
int HardwareSerial::available(void) {
169+
return usart_data_available(this->usart_device);
170+
}
171+
172+
/* Roger Clark. Added function missing from LibMaple code */
173+
174+
int HardwareSerial::peek(void)
175+
{
176+
return usart_peek(this->usart_device);
177+
}
178+
179+
int HardwareSerial::availableForWrite(void)
180+
{
181+
/* Roger Clark.
182+
* Currently there isn't an output ring buffer, chars are sent straight to the hardware.
183+
* so just return 1, meaning that 1 char can be written
184+
* This will be slower than a ring buffer implementation, but it should at least work !
185+
*/
186+
return 1;
187+
}
188+
189+
size_t HardwareSerial::write(unsigned char ch) {
190+
191+
usart_putc(this->usart_device, ch);
192+
return 1;
193+
}
194+
195+
void HardwareSerial::flush(void) {
196+
usart_reset_rx(this->usart_device);
197+
}

0 commit comments

Comments
 (0)