Skip to content

STM32F1 merge other (BluePill and Maple Mini) #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from
88 changes: 88 additions & 0 deletions boards.txt
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,80 @@ Disco.menu.upload_method.STLinkMethod=STLink
Disco.menu.upload_method.STLinkMethod.upload.protocol=STLink
Disco.menu.upload_method.STLinkMethod.upload.tool=stlink_upload

################################################################################
# Other boards

Other.name=Other

Other.build.vid=0x0483
Other.build.pid=0x5711
Other.vid.0=0x0483
Other.pid.0=0x5711

Other.build.core=arduino
Other.build.board=Other
Other.build.extra_flags=-D{build.product_line} {build.enable_usb} {build.enable_Serialx} {build.upload_flags}

# BLUEPILL_F103C8 board
# Support: USB HID, Serial2 (USART2 on PA3, PA2) and Serial3 (USART3 on PB11, PB10)
Other.menu.board_part_num.BLUEPILL_F103C8=BluePill F103C8
Other.menu.board_part_num.BLUEPILL_F103C8.node=NODE_F103C8
Other.menu.board_part_num.BLUEPILL_F103C8.upload.maximum_size=65536
Other.menu.board_part_num.BLUEPILL_F103C8.upload.maximum_data_size=20480
Other.menu.board_part_num.BLUEPILL_F103C8.build.mcu=cortex-m3
Other.menu.board_part_num.BLUEPILL_F103C8.build.f_cpu=72000000L
Other.menu.board_part_num.BLUEPILL_F103C8.build.board=BLUEPILL_F103C8
Other.menu.board_part_num.BLUEPILL_F103C8.build.series=STM32F1xx
Other.menu.board_part_num.BLUEPILL_F103C8.build.product_line=STM32F103xB
Other.menu.board_part_num.BLUEPILL_F103C8.build.variant=BLUEPILL_F103C8
Other.menu.board_part_num.BLUEPILL_F103C8.build.cmsis_lib_gcc=arm_cortexM3l_math

# MAPLEMINI_F103CB board
# Support: USB HID, Serial2 (USART2 on PA3, PA2) and Serial3 (USART3 on PB11, PB10)
Other.menu.board_part_num.MAPLEMINI_F103CB=MapleMini F103CB
Other.menu.board_part_num.MAPLEMINI_F103CB.node=NODE_F103CB
Other.menu.board_part_num.MAPLEMINI_F103CB.upload.maximum_size=131072
Other.menu.board_part_num.MAPLEMINI_F103CB.upload.maximum_data_size=20480
Other.menu.board_part_num.MAPLEMINI_F103CB.build.mcu=cortex-m3
Other.menu.board_part_num.MAPLEMINI_F103CB.build.f_cpu=72000000L
Other.menu.board_part_num.MAPLEMINI_F103CB.build.board=MAPLEMINI_F103CB
Other.menu.board_part_num.MAPLEMINI_F103CB.build.series=STM32F1xx
Other.menu.board_part_num.MAPLEMINI_F103CB.build.product_line=STM32F103xB
Other.menu.board_part_num.MAPLEMINI_F103CB.build.variant=MAPLEMINI_F103CB
Other.menu.board_part_num.MAPLEMINI_F103CB.build.cmsis_lib_gcc=arm_cortexM3l_math

# Upload menu
Other.menu.upload_method.DFUUploadMethod1=Maple bootloader (original version for Maple boards)
Other.menu.upload_method.DFUUploadMethod1.upload.protocol=maple_dfu
Other.menu.upload_method.DFUUploadMethod1.upload.tool=maple_upload
Other.menu.upload_method.DFUUploadMethod1.build.upload_flags=-DSERIAL_USB -DVECT_TAB_OFFSET=0x5000
Other.menu.upload_method.DFUUploadMethod1.build.ldscript=bootloader_original.ld
Other.menu.upload_method.DFUUploadMethod1.upload.usbID=1EAF:0003
Other.menu.upload_method.DFUUploadMethod1.upload.altID=1

Other.menu.upload_method.DFUUploadMethod=STM32duino bootloader
Other.menu.upload_method.DFUUploadMethod.upload.protocol=maple_dfu
Other.menu.upload_method.DFUUploadMethod.upload.tool=maple_upload
Other.menu.upload_method.DFUUploadMethod.build.upload_flags=-DSERIAL_USB -DVECT_TAB_OFFSET=0x2000
Other.menu.upload_method.DFUUploadMethod.build.ldscript=bootloader.ld
Other.menu.upload_method.DFUUploadMethod.upload.usbID=1EAF:0003
Other.menu.upload_method.DFUUploadMethod.upload.altID=2

Other.menu.upload_method.STLinkMethod=STLink
Other.menu.upload_method.STLinkMethod.upload.protocol=STLink
Other.menu.upload_method.STLinkMethod.upload.tool=stlink_upload
Other.menu.upload_method.STLinkMethod.build.upload_flags=-DSERIAL_USB
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move STLink method before DFUUploadMethod. STLink will be the default Upload method.


Other.menu.upload_method.serialMethod=Serial
Other.menu.upload_method.serialMethod.upload.protocol=maple_serial
Other.menu.upload_method.serialMethod.upload.tool=serial_upload
Other.menu.upload_method.serialMethod.build.upload_flags=

Other.menu.upload_method.BMPMethod=BMP (Black Magic Probe)
Other.menu.upload_method.BMPMethod.upload.protocol=gdb_bmp
Other.menu.upload_method.BMPMethod.upload.tool=bmp_upload
Other.menu.upload_method.BMPMethod.upload.speed=230400
Other.menu.upload_method.BMPMethod.build.upload_flags=

################################################################################
# Serialx activation
Expand Down Expand Up @@ -345,6 +419,14 @@ Disco.menu.Other_serial.enable_Serial1.build.enable_Serialx=-DENABLE_SERIAL1
Disco.menu.Other_serial.enable_Serial2=Serial2 (if available)
Disco.menu.Other_serial.enable_Serial2.build.enable_Serialx=-DENABLE_SERIAL2

Other.menu.Other_serial.enable_Serial=None
Other.menu.Other_serial.enable_SerialAll=All
Other.menu.Other_serial.enable_SerialAll.build.enable_Serialx=-DENABLE_SERIAL2 -DENABLE_SERIAL3
Other.menu.Other_serial.enable_Serial2=Serial2 (if available)
Other.menu.Other_serial.enable_Serial2.build.enable_Serialx=-DENABLE_SERIAL2
Other.menu.Other_serial.enable_Serial3=Serial3 (if available)
Other.menu.Other_serial.enable_Serial3.build.enable_Serialx=-DENABLE_SERIAL3

# USB connectivity
Nucleo_144.menu.USB_interface.enable_USB=None
Nucleo_144.menu.USB_interface.enable_HID=HID keyboard and mouse support (if available)
Expand All @@ -369,3 +451,9 @@ Disco.menu.USB_interface.enable_HID=HID keyboard and mouse support (if available
Disco.menu.USB_interface.enable_HID.build.enable_usb={build.usb_flags} -DUSBD_USE_HID_COMPOSITE
#Disco.menu.USB_interface.enable_CDC=CDC (if available)
#Disco.menu.USB_interface.enable_CDC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC -DUSE_USB_FS

Other.menu.USB_interface.enable_USB=None
Other.menu.USB_interface.enable_HID=HID keyboard and mouse support (if available)
Other.menu.USB_interface.enable_HID.build.enable_usb={build.usb_flags} -DUSBD_USE_HID_COMPOSITE
Other.menu.USB_interface.enable_CDC=CDC (if available)
Other.menu.USB_interface.enable_CDC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC -DUSE_USB_FS
1 change: 1 addition & 0 deletions cores/arduino/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ extern void loop( void ) ;
#include "WMath.h"
#include "HardwareSerial.h"
#include "wiring_pulse.h"
#include "USBSerial.h"
#endif // __cplusplus


Expand Down
212 changes: 212 additions & 0 deletions cores/arduino/USBSerial.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
/****************************************************************************
*
* USBSerial core library for Arduino STM32 + HAL + CubeMX (HALMX).
*
* Copyright (c) 2016 by Vassilis Serasidis <[email protected]>
* Home: http://www.serasidis.gr
* email: [email protected]
*
* Arduino_STM32 forum: http://www.stm32duino.com
*
* Permission to use, copy, modify, and/or distribute this software for
* any purpose with or without fee is hereby granted, provided that the
* above copyright notice and this permission notice appear in all copies.
*
* Some functions follow the sam and samd arduino core libray files.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
* WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
* BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
* WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
*
****************************************************************************/

#include <chip.h>

#if defined(SERIAL_USB) && defined(USBCON)
#include <USBSerial.h>
#include "variant.h"

// Constructors ////////////////////////////////////////////////////////////////
USBSerial::USBSerial(){
// Make sure Rx ring buffer is initialized back to empty.
rx_buffer.iHead = rx_buffer.iTail = 0;
//tx_buffer.iHead = tx_buffer.iTail = 0;
}

void USBSerial::init(void){
/* Re-enumerate the USB */
volatile unsigned int i;

#ifdef USB_DISC_PIN
pinMode(USB_DISC_PIN, OUTPUT);
digitalWrite(USB_DISC_PIN, HIGH);
for(i=0;i<512;i++);
digitalWrite(USB_DISC_PIN, LOW);
#else
#error "USB_DISC_PIN definition missing"
#endif
MX_USB_DEVICE_Init();
}


void USBSerial::begin(uint32_t baud_count){
init();
// suppress "unused parameter" warning
(void)baud_count;
}

void USBSerial::begin(uint32_t baud_count, uint8_t config){
init();
//suppress "unused parameter" warning
(void)baud_count;
(void)config;
}

void USBSerial::end(void){

}


int USBSerial::availableForWrite(void){
//return (CDC_SERIAL_BUFFER_SIZE - available());
//return (uint32_t)(CDC_SERIAL_BUFFER_SIZE + tx_buffer.iHead - tx_buffer.iTail) % CDC_SERIAL_BUFFER_SIZE;
return 0;
}


int USBSerial::available(void){
return (uint32_t)(CDC_SERIAL_BUFFER_SIZE + rx_buffer.iHead - rx_buffer.iTail) % CDC_SERIAL_BUFFER_SIZE;
}

int USBSerial::peek(void)
{
if ( rx_buffer.iHead == rx_buffer.iTail )
return -1;

return rx_buffer.buffer[rx_buffer.iTail];
}

int USBSerial::read(void)
{
// if the head isn't ahead of the tail, we don't have any characters
if ( rx_buffer.iHead == rx_buffer.iTail )
return -1;

uint8_t uc = rx_buffer.buffer[rx_buffer.iTail];
rx_buffer.iTail = (unsigned int)(rx_buffer.iTail + 1) % CDC_SERIAL_BUFFER_SIZE;

return uc;
}

void USBSerial::flush(void){
//It's not implemented yet.
}

size_t USBSerial::write(const uint8_t *buffer, size_t size){
unsigned long timeout=millis()+5;
if(hUsbDeviceFS.dev_state == USBD_STATE_CONFIGURED)
{
while(millis()<timeout)
{
if(CDC_Transmit_FS((uint8_t*)buffer, size) == USBD_OK)
{
return size;
}
}
}

return 0;


/* uint8_t i;

if(hUsbDeviceFS.dev_state == USBD_STATE_CONFIGURED){

//HAL_NVIC_DisableIRQ(USB_LP_CAN1_RX0_IRQn);
for(i=0;i<200;i++)
if(CDC_Transmit_FS((uint8_t*)buffer, size) == USBD_OK){
return size;
//break;
}


//HAL_NVIC_EnableIRQ(USB_LP_CAN1_RX0_IRQn);
}
return 0; */
}

size_t USBSerial::write(uint8_t c) {
return write(&c, 1);
}

void USBSerial::CDC_RxHandler (uint8_t* Buf, uint16_t Len){

for(uint16_t i=0;i<Len;i++){
if(available() < (CDC_SERIAL_BUFFER_SIZE - 1)){
rx_buffer.buffer[rx_buffer.iHead] = *Buf++;
rx_buffer.iHead = (uint16_t)(rx_buffer.iHead + 1) % CDC_SERIAL_BUFFER_SIZE;
}else
break;
}
}


// This operator is a convenient way for a sketch to check whether the
// port has actually been configured and opened by the host (as opposed
// to just being connected to the host). It can be used, for example, in
// setup() before printing to ensure that an application on the host is
// actually ready to receive and display the data.
// We add a short delay before returning to fix a bug observed by Federico
// where the port is configured (lineState != 0) but not quite opened.
USBSerial::operator bool()
{
// this is here to avoid spurious opening after upload
if (millis() < 500)
return false;

bool result = false;

/* if (_usbLineInfo.lineState > 0)
{
result = true;
}

delay(10); */
return result;
}

uint32_t USBSerial::baud() {
//return _usbLineInfo.dwDTERate;
return 0;
}

uint8_t USBSerial::stopbits() {
//return _usbLineInfo.bCharFormat;
return 0;
}

uint8_t USBSerial::paritytype() {
//return _usbLineInfo.bParityType;
return 0;
}

uint8_t USBSerial::numbits() {
//return _usbLineInfo.bDataBits;
return 0;
}

bool USBSerial::dtr() {
//return _usbLineInfo.lineState & 0x1;
return 0;
}

bool USBSerial::rts() {
//return _usbLineInfo.lineState & 0x2;
return 0;
}

#endif
Loading