Skip to content

Commit 5229612

Browse files
fpistmlacklustrlabs
authored andcommitted
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 2415879 commit 5229612

19 files changed

+3424
-0
lines changed

boards.txt

+89
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,58 @@ Disco.menu.upload_method.STLink=STLink
374374
Disco.menu.upload_method.STLink.upload.protocol=STLink
375375
Disco.menu.upload_method.STLink.upload.tool=stlink_upload
376376

377+
################################################################################
378+
# Other boards
379+
380+
Other.name=Other
381+
382+
Other.build.vid=0x0483
383+
Other.build.pid=0x5711
384+
Other.vid.0=0x0483
385+
Other.pid.0=0x5711
386+
387+
Other.build.core=arduino
388+
Other.build.board=Other
389+
Other.build.extra_flags=-D{build.product_line} {build.enable_usb} {build.enable_Serialx}
390+
391+
# BLUEPILL_F103C8 board
392+
# Support: USB HID, Serial2 (USART2 on PA3, PA2) and Serial3 (USART3 on PB11, PB10)
393+
Other.menu.board_part_num.BLUEPILL_F103C8=BluePill F103C8
394+
Other.menu.board_part_num.BLUEPILL_F103C8.node=NODE_F103C8
395+
Other.menu.board_part_num.BLUEPILL_F103C8.upload.maximum_size=65536
396+
Other.menu.board_part_num.BLUEPILL_F103C8.upload.maximum_data_size=20480
397+
Other.menu.board_part_num.BLUEPILL_F103C8.build.mcu=cortex-m3
398+
Other.menu.board_part_num.BLUEPILL_F103C8.build.f_cpu=72000000L
399+
Other.menu.board_part_num.BLUEPILL_F103C8.build.board=BLUEPILL_F103C8
400+
Other.menu.board_part_num.BLUEPILL_F103C8.build.series=STM32F1xx
401+
Other.menu.board_part_num.BLUEPILL_F103C8.build.product_line=STM32F103xB
402+
Other.menu.board_part_num.BLUEPILL_F103C8.build.variant=BLUEPILL_F103C8
403+
Other.menu.board_part_num.BLUEPILL_F103C8.build.cmsis_lib_gcc=arm_cortexM3l_math
404+
405+
# Upload menu
406+
Other.menu.upload_method.DFUUploadMethod=STM32duino bootloader
407+
Other.menu.upload_method.DFUUploadMethod.upload.protocol=maple_dfu
408+
Other.menu.upload_method.DFUUploadMethod.upload.tool=maple_upload
409+
Other.menu.upload_method.DFUUploadMethod.build.upload_flags=-DSERIAL_USB -DVECT_TAB_OFFSET=0x2000
410+
Other.menu.upload_method.DFUUploadMethod.build.ldscript=bootloader.ld
411+
Other.menu.upload_method.DFUUploadMethod.upload.usbID=1EAF:0003
412+
Other.menu.upload_method.DFUUploadMethod.upload.altID=2
413+
414+
Other.menu.upload_method.STLinkMethod=STLink
415+
Other.menu.upload_method.STLinkMethod.upload.protocol=STLink
416+
Other.menu.upload_method.STLinkMethod.upload.tool=stlink_upload
417+
Other.menu.upload_method.STLinkMethod.build.upload_flags=-DSERIAL_USB
418+
419+
Other.menu.upload_method.serialMethod=Serial
420+
Other.menu.upload_method.serialMethod.upload.protocol=maple_serial
421+
Other.menu.upload_method.serialMethod.upload.tool=serial_upload
422+
Other.menu.upload_method.serialMethod.build.upload_flags=
423+
424+
Other.menu.upload_method.BMPMethod=BMP (Black Magic Probe)
425+
Other.menu.upload_method.BMPMethod.upload.protocol=gdb_bmp
426+
Other.menu.upload_method.BMPMethod.upload.tool=bmp_upload
427+
Other.menu.upload_method.BMPMethod.upload.speed=230400
428+
Other.menu.upload_method.BMPMethod.build.upload_flags=
377429

378430
################################################################################
379431
# Serialx activation
@@ -409,6 +461,14 @@ Disco.menu.xserial.all.build.xSerial=-DALL_HWSERIAL
409461
Disco.menu.xserial.third=Enable first third (USART1 to 3 if available)
410462
Disco.menu.xserial.third.build.xSerial=-DFIRST_THIRD_HWSERIAL
411463

464+
Other.menu.Other_serial.enable_Serial=None
465+
Other.menu.Other_serial.enable_SerialAll=All
466+
Other.menu.Other_serial.enable_SerialAll.build.enable_Serialx=-DENABLE_SERIAL2 -DENABLE_SERIAL3
467+
Other.menu.Other_serial.enable_Serial2=Serial2 (if available)
468+
Other.menu.Other_serial.enable_Serial2.build.enable_Serialx=-DENABLE_SERIAL2
469+
Other.menu.Other_serial.enable_Serial3=Serial3 (if available)
470+
Other.menu.Other_serial.enable_Serial3.build.enable_Serialx=-DENABLE_SERIAL3
471+
412472
# USB connectivity
413473
Nucleo_144.menu.usb.none=None
414474
Nucleo_144.menu.usb.HID=HID keyboard and mouse support (if available)
@@ -546,3 +606,32 @@ Disco.menu.opt.o3lto.build.flags.ldspecs=-flto
546606
Disco.menu.opt.ogstd=Debug (-g)
547607
Disco.menu.opt.ogstd.build.flags.optimize=-g -Og
548608
Disco.menu.opt.ogstd.build.flags.ldspecs=
609+
Nucleo_144.menu.USB_interface.enable_USB=None
610+
Nucleo_144.menu.USB_interface.enable_HID=HID keyboard and mouse support (if available)
611+
Nucleo_144.menu.USB_interface.enable_HID.build.enable_usb={build.usb_flags} -DUSBD_USE_HID_COMPOSITE
612+
#Nucleo_144.menu.USB_interface.enable_CDC=CDC (if available)
613+
#Nucleo_144.menu.USB_interface.enable_CDC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC -DUSE_USB_FS
614+
615+
Nucleo_64.menu.USB_interface.enable_USB=None
616+
Nucleo_64.menu.USB_interface.enable_HID=HID keyboard and mouse support (if available)
617+
Nucleo_64.menu.USB_interface.enable_HID.build.enable_usb={build.usb_flags} -DUSBD_USE_HID_COMPOSITE
618+
#Nucleo_64.menu.USB_interface.enable_CDC=CDC (if available)
619+
#Nucleo_64.menu.USB_interface.enable_CDC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC -DUSE_USB_FS
620+
621+
Nucleo_32.menu.USB_interface.enable_USB=None
622+
Nucleo_32.menu.USB_interface.enable_HID=HID keyboard and mouse support (if available)
623+
Nucleo_32.menu.USB_interface.enable_HID.build.enable_usb={build.usb_flags} -DUSBD_USE_HID_COMPOSITE
624+
#Nucleo_32.menu.USB_interface.enable_CDC=CDC (if available)
625+
#Nucleo_32.menu.USB_interface.enable_CDC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC -DUSE_USB_FS
626+
627+
Disco.menu.USB_interface.enable_USB=None
628+
Disco.menu.USB_interface.enable_HID=HID keyboard and mouse support (if available)
629+
Disco.menu.USB_interface.enable_HID.build.enable_usb={build.usb_flags} -DUSBD_USE_HID_COMPOSITE
630+
#Disco.menu.USB_interface.enable_CDC=CDC (if available)
631+
#Disco.menu.USB_interface.enable_CDC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC -DUSE_USB_FS
632+
633+
Other.menu.USB_interface.enable_USB=None
634+
Other.menu.USB_interface.enable_HID=HID keyboard and mouse support (if available)
635+
Other.menu.USB_interface.enable_HID.build.enable_usb={build.usb_flags} -DUSBD_USE_HID_COMPOSITE
636+
Other.menu.USB_interface.enable_CDC=CDC (if available)
637+
Other.menu.USB_interface.enable_CDC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC -DUSE_USB_FS

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)