Skip to content

Commit 90c0f5a

Browse files
committed
BluePill F103C8 variant added.
Upload method Bootloader, Serial and BMP added. USBSerial class added because is required by bootloader. Signed-off-by: fpr <[email protected]>
1 parent 4b0baaa commit 90c0f5a

20 files changed

+3402
-0
lines changed

Diff for: boards.txt

+66
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,58 @@ Disco.menu.upload_method.STLinkMethod=STLink
282282
Disco.menu.upload_method.STLinkMethod.upload.protocol=STLink
283283
Disco.menu.upload_method.STLinkMethod.upload.tool=stlink_upload
284284

285+
################################################################################
286+
# Other boards
287+
288+
Other.name=Other
289+
290+
Other.build.vid=0x0483
291+
Other.build.pid=0x5711
292+
Other.vid.0=0x0483
293+
Other.pid.0=0x5711
294+
295+
Other.build.core=arduino
296+
Other.build.board=Other
297+
Other.build.extra_flags=-D{build.product_line} {build.enable_usb} {build.enable_Serialx}
298+
299+
# BLUEPILL_F103C8 board
300+
# Support: USB HID, Serial2 (USART2 on PA3, PA2) and Serial3 (USART3 on PB11, PB10)
301+
Other.menu.board_part_num.BLUEPILL_F103C8=BluePill F103C8
302+
Other.menu.board_part_num.BLUEPILL_F103C8.node=NODE_F103C8
303+
Other.menu.board_part_num.BLUEPILL_F103C8.upload.maximum_size=65536
304+
Other.menu.board_part_num.BLUEPILL_F103C8.upload.maximum_data_size=20480
305+
Other.menu.board_part_num.BLUEPILL_F103C8.build.mcu=cortex-m3
306+
Other.menu.board_part_num.BLUEPILL_F103C8.build.f_cpu=72000000L
307+
Other.menu.board_part_num.BLUEPILL_F103C8.build.board=BLUEPILL_F103C8
308+
Other.menu.board_part_num.BLUEPILL_F103C8.build.series=STM32F1xx
309+
Other.menu.board_part_num.BLUEPILL_F103C8.build.product_line=STM32F103xB
310+
Other.menu.board_part_num.BLUEPILL_F103C8.build.variant=BLUEPILL_F103C8
311+
Other.menu.board_part_num.BLUEPILL_F103C8.build.cmsis_lib_gcc=arm_cortexM3l_math
312+
313+
# Upload menu
314+
Other.menu.upload_method.DFUUploadMethod=STM32duino bootloader
315+
Other.menu.upload_method.DFUUploadMethod.upload.protocol=maple_dfu
316+
Other.menu.upload_method.DFUUploadMethod.upload.tool=maple_upload
317+
Other.menu.upload_method.DFUUploadMethod.build.upload_flags=-DSERIAL_USB -DVECT_TAB_OFFSET=0x2000
318+
Other.menu.upload_method.DFUUploadMethod.build.ldscript=bootloader.ld
319+
Other.menu.upload_method.DFUUploadMethod.upload.usbID=1EAF:0003
320+
Other.menu.upload_method.DFUUploadMethod.upload.altID=2
321+
322+
Other.menu.upload_method.STLinkMethod=STLink
323+
Other.menu.upload_method.STLinkMethod.upload.protocol=STLink
324+
Other.menu.upload_method.STLinkMethod.upload.tool=stlink_upload
325+
Other.menu.upload_method.STLinkMethod.build.upload_flags=-DSERIAL_USB
326+
327+
Other.menu.upload_method.serialMethod=Serial
328+
Other.menu.upload_method.serialMethod.upload.protocol=maple_serial
329+
Other.menu.upload_method.serialMethod.upload.tool=serial_upload
330+
Other.menu.upload_method.serialMethod.build.upload_flags=
331+
332+
Other.menu.upload_method.BMPMethod=BMP (Black Magic Probe)
333+
Other.menu.upload_method.BMPMethod.upload.protocol=gdb_bmp
334+
Other.menu.upload_method.BMPMethod.upload.tool=bmp_upload
335+
Other.menu.upload_method.BMPMethod.upload.speed=230400
336+
Other.menu.upload_method.BMPMethod.build.upload_flags=
285337

286338
################################################################################
287339
# Serialx activation
@@ -317,6 +369,14 @@ Disco.menu.Other_serial.enable_Serial1.build.enable_Serialx=-DENABLE_SERIAL1
317369
Disco.menu.Other_serial.enable_Serial2=Serial2 (if available)
318370
Disco.menu.Other_serial.enable_Serial2.build.enable_Serialx=-DENABLE_SERIAL2
319371

372+
Other.menu.Other_serial.enable_Serial=None
373+
Other.menu.Other_serial.enable_SerialAll=All
374+
Other.menu.Other_serial.enable_SerialAll.build.enable_Serialx=-DENABLE_SERIAL2 -DENABLE_SERIAL3
375+
Other.menu.Other_serial.enable_Serial2=Serial2 (if available)
376+
Other.menu.Other_serial.enable_Serial2.build.enable_Serialx=-DENABLE_SERIAL2
377+
Other.menu.Other_serial.enable_Serial3=Serial3 (if available)
378+
Other.menu.Other_serial.enable_Serial3.build.enable_Serialx=-DENABLE_SERIAL3
379+
320380
# USB connectivity
321381
Nucleo_144.menu.USB_interface.enable_USB=None
322382
Nucleo_144.menu.USB_interface.enable_HID=HID keyboard and mouse support (if available)
@@ -341,3 +401,9 @@ Disco.menu.USB_interface.enable_HID=HID keyboard and mouse support (if available
341401
Disco.menu.USB_interface.enable_HID.build.enable_usb={build.usb_flags} -DUSBD_USE_HID_COMPOSITE
342402
#Disco.menu.USB_interface.enable_CDC=CDC (if available)
343403
#Disco.menu.USB_interface.enable_CDC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC -DUSE_USB_FS
404+
405+
Other.menu.USB_interface.enable_USB=None
406+
Other.menu.USB_interface.enable_HID=HID keyboard and mouse support (if available)
407+
Other.menu.USB_interface.enable_HID.build.enable_usb={build.usb_flags} -DUSBD_USE_HID_COMPOSITE
408+
Other.menu.USB_interface.enable_CDC=CDC (if available)
409+
Other.menu.USB_interface.enable_CDC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC -DUSE_USB_FS

Diff for: cores/arduino/Arduino.h

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ extern void loop( void ) ;
6868
#include "WMath.h"
6969
#include "HardwareSerial.h"
7070
#include "wiring_pulse.h"
71+
#include "USBSerial.h"
7172
#endif // __cplusplus
7273

7374

Diff for: cores/arduino/USBSerial.cpp

+212
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
/****************************************************************************
2+
*
3+
* USBSerial core library for Arduino STM32 + HAL + CubeMX (HALMX).
4+
*
5+
* Copyright (c) 2016 by Vassilis Serasidis <[email protected]>
6+
* Home: http://www.serasidis.gr
7+
8+
*
9+
* Arduino_STM32 forum: http://www.stm32duino.com
10+
*
11+
* Permission to use, copy, modify, and/or distribute this software for
12+
* any purpose with or without fee is hereby granted, provided that the
13+
* above copyright notice and this permission notice appear in all copies.
14+
*
15+
* Some functions follow the sam and samd arduino core libray files.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
18+
* WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
19+
* WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
20+
* BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
21+
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
22+
* WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
23+
* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
24+
*
25+
****************************************************************************/
26+
27+
#include <chip.h>
28+
29+
#if defined(SERIAL_USB) && defined(USBCON)
30+
#include <USBSerial.h>
31+
#include "variant.h"
32+
33+
// Constructors ////////////////////////////////////////////////////////////////
34+
USBSerial::USBSerial(){
35+
// Make sure Rx ring buffer is initialized back to empty.
36+
rx_buffer.iHead = rx_buffer.iTail = 0;
37+
//tx_buffer.iHead = tx_buffer.iTail = 0;
38+
}
39+
40+
void USBSerial::init(void){
41+
/* Re-enumerate the USB */
42+
volatile unsigned int i;
43+
44+
#ifdef USB_DISC_PIN
45+
pinMode(USB_DISC_PIN, OUTPUT);
46+
digitalWrite(USB_DISC_PIN, HIGH);
47+
for(i=0;i<512;i++);
48+
digitalWrite(USB_DISC_PIN, LOW);
49+
#else
50+
#error "USB_DISC_PIN definition missing"
51+
#endif
52+
MX_USB_DEVICE_Init();
53+
}
54+
55+
56+
void USBSerial::begin(uint32_t baud_count){
57+
init();
58+
// suppress "unused parameter" warning
59+
(void)baud_count;
60+
}
61+
62+
void USBSerial::begin(uint32_t baud_count, uint8_t config){
63+
init();
64+
//suppress "unused parameter" warning
65+
(void)baud_count;
66+
(void)config;
67+
}
68+
69+
void USBSerial::end(void){
70+
71+
}
72+
73+
74+
int USBSerial::availableForWrite(void){
75+
//return (CDC_SERIAL_BUFFER_SIZE - available());
76+
//return (uint32_t)(CDC_SERIAL_BUFFER_SIZE + tx_buffer.iHead - tx_buffer.iTail) % CDC_SERIAL_BUFFER_SIZE;
77+
return 0;
78+
}
79+
80+
81+
int USBSerial::available(void){
82+
return (uint32_t)(CDC_SERIAL_BUFFER_SIZE + rx_buffer.iHead - rx_buffer.iTail) % CDC_SERIAL_BUFFER_SIZE;
83+
}
84+
85+
int USBSerial::peek(void)
86+
{
87+
if ( rx_buffer.iHead == rx_buffer.iTail )
88+
return -1;
89+
90+
return rx_buffer.buffer[rx_buffer.iTail];
91+
}
92+
93+
int USBSerial::read(void)
94+
{
95+
// if the head isn't ahead of the tail, we don't have any characters
96+
if ( rx_buffer.iHead == rx_buffer.iTail )
97+
return -1;
98+
99+
uint8_t uc = rx_buffer.buffer[rx_buffer.iTail];
100+
rx_buffer.iTail = (unsigned int)(rx_buffer.iTail + 1) % CDC_SERIAL_BUFFER_SIZE;
101+
102+
return uc;
103+
}
104+
105+
void USBSerial::flush(void){
106+
//It's not implemented yet.
107+
}
108+
109+
size_t USBSerial::write(const uint8_t *buffer, size_t size){
110+
unsigned long timeout=millis()+5;
111+
if(hUsbDeviceFS.dev_state == USBD_STATE_CONFIGURED)
112+
{
113+
while(millis()<timeout)
114+
{
115+
if(CDC_Transmit_FS((uint8_t*)buffer, size) == USBD_OK)
116+
{
117+
return size;
118+
}
119+
}
120+
}
121+
122+
return 0;
123+
124+
125+
/* uint8_t i;
126+
127+
if(hUsbDeviceFS.dev_state == USBD_STATE_CONFIGURED){
128+
129+
//HAL_NVIC_DisableIRQ(USB_LP_CAN1_RX0_IRQn);
130+
for(i=0;i<200;i++)
131+
if(CDC_Transmit_FS((uint8_t*)buffer, size) == USBD_OK){
132+
return size;
133+
//break;
134+
}
135+
136+
137+
//HAL_NVIC_EnableIRQ(USB_LP_CAN1_RX0_IRQn);
138+
}
139+
return 0; */
140+
}
141+
142+
size_t USBSerial::write(uint8_t c) {
143+
return write(&c, 1);
144+
}
145+
146+
void USBSerial::CDC_RxHandler (uint8_t* Buf, uint16_t Len){
147+
148+
for(uint16_t i=0;i<Len;i++){
149+
if(available() < (CDC_SERIAL_BUFFER_SIZE - 1)){
150+
rx_buffer.buffer[rx_buffer.iHead] = *Buf++;
151+
rx_buffer.iHead = (uint16_t)(rx_buffer.iHead + 1) % CDC_SERIAL_BUFFER_SIZE;
152+
}else
153+
break;
154+
}
155+
}
156+
157+
158+
// This operator is a convenient way for a sketch to check whether the
159+
// port has actually been configured and opened by the host (as opposed
160+
// to just being connected to the host). It can be used, for example, in
161+
// setup() before printing to ensure that an application on the host is
162+
// actually ready to receive and display the data.
163+
// We add a short delay before returning to fix a bug observed by Federico
164+
// where the port is configured (lineState != 0) but not quite opened.
165+
USBSerial::operator bool()
166+
{
167+
// this is here to avoid spurious opening after upload
168+
if (millis() < 500)
169+
return false;
170+
171+
bool result = false;
172+
173+
/* if (_usbLineInfo.lineState > 0)
174+
{
175+
result = true;
176+
}
177+
178+
delay(10); */
179+
return result;
180+
}
181+
182+
uint32_t USBSerial::baud() {
183+
//return _usbLineInfo.dwDTERate;
184+
return 0;
185+
}
186+
187+
uint8_t USBSerial::stopbits() {
188+
//return _usbLineInfo.bCharFormat;
189+
return 0;
190+
}
191+
192+
uint8_t USBSerial::paritytype() {
193+
//return _usbLineInfo.bParityType;
194+
return 0;
195+
}
196+
197+
uint8_t USBSerial::numbits() {
198+
//return _usbLineInfo.bDataBits;
199+
return 0;
200+
}
201+
202+
bool USBSerial::dtr() {
203+
//return _usbLineInfo.lineState & 0x1;
204+
return 0;
205+
}
206+
207+
bool USBSerial::rts() {
208+
//return _usbLineInfo.lineState & 0x2;
209+
return 0;
210+
}
211+
212+
#endif

0 commit comments

Comments
 (0)