From dbabd6fd52ec40914769a03cf00133f78c2f1199 Mon Sep 17 00:00:00 2001 From: Roger Clark Date: Sat, 1 Nov 2014 09:27:18 +1100 Subject: [PATCH] Changes to generic STM32 board definitions for Serial. The first UATT is now Serial, second is Serial1 (this maps Serial -> UART1, Serial1->UART2 etc). Also fixed missing sprintf, - needed more includes in wirish.h. Also investigated implementing printf for Serial.printf (currently a work in progress) --- STM32F1XX/boards.txt | 2 +- STM32F1XX/cores/maple/HardwareSerial.cpp | 56 +++++++++++++------ STM32F1XX/cores/maple/Print.cpp | 19 +++++++ STM32F1XX/cores/maple/wirish/HardwareSerial.h | 55 ++++++++++++------ STM32F1XX/cores/maple/wirish/Print.h | 4 ++ STM32F1XX/cores/maple/wirish/wirish.h | 2 + 6 files changed, 102 insertions(+), 36 deletions(-) diff --git a/STM32F1XX/boards.txt b/STM32F1XX/boards.txt index 5d87d4e..e8ebdc4 100644 --- a/STM32F1XX/boards.txt +++ b/STM32F1XX/boards.txt @@ -123,7 +123,7 @@ maple_STM32.upload.auto_reset=true maple_STM32.build.mcu=cortex-m3 maple_STM32.build.f_cpu=72000000L maple_STM32.build.core=maple -maple_STM32.build.extra_flags=-DMCU_STM32F103CB -mthumb -MD -DSTM32_MEDIUM_DENSITY -march=armv7-m -DSerial=Serial1 +maple_STM32.build.extra_flags=-DMCU_STM32F103CB -mthumb -MD -DSTM32_MEDIUM_DENSITY -march=armv7-m maple_STM32.build.ldscript=ld/jtag.ld maple_STM32.build.variant=maple_mini maple_STM32.build.variant_system_lib=libmaple.a diff --git a/STM32F1XX/cores/maple/HardwareSerial.cpp b/STM32F1XX/cores/maple/HardwareSerial.cpp index 3036983..0720fbd 100644 --- a/STM32F1XX/cores/maple/HardwareSerial.cpp +++ b/STM32F1XX/cores/maple/HardwareSerial.cpp @@ -42,25 +42,45 @@ BOARD_USART##n##_TX_PIN, \ BOARD_USART##n##_RX_PIN) -#if BOARD_HAVE_USART1 -DEFINE_HWSERIAL(Serial1, 1); +#ifdef BOOTLOADER_maple + #if BOARD_HAVE_USART1 + DEFINE_HWSERIAL(Serial1, 1); + #endif + #if BOARD_HAVE_USART2 + DEFINE_HWSERIAL(Serial2, 2); + #endif + #if BOARD_HAVE_USART3 + DEFINE_HWSERIAL(Serial3, 3); + #endif + #if BOARD_HAVE_UART4 + DEFINE_HWSERIAL(Serial4, 4); + #endif + #if BOARD_HAVE_UART5 + DEFINE_HWSERIAL(Serial5, 5); + #endif + #if BOARD_HAVE_USART6 + DEFINE_HWSERIAL(Serial6, 6); + #endif +#else + #if BOARD_HAVE_USART1 + DEFINE_HWSERIAL(Serial, 1); + #endif + #if BOARD_HAVE_USART2 + DEFINE_HWSERIAL(Serial1, 2); + #endif + #if BOARD_HAVE_USART3 + DEFINE_HWSERIAL(Serial2, 3); + #endif + #if BOARD_HAVE_UART4 + DEFINE_HWSERIAL(Serial3, 4); + #endif + #if BOARD_HAVE_UART5 + DEFINE_HWSERIAL(Serial4, 5); + #endif + #if BOARD_HAVE_USART6 + DEFINE_HWSERIAL(Serial5, 6); + #endif #endif -#if BOARD_HAVE_USART2 -DEFINE_HWSERIAL(Serial2, 2); -#endif -#if BOARD_HAVE_USART3 -DEFINE_HWSERIAL(Serial3, 3); -#endif -#if BOARD_HAVE_UART4 -DEFINE_HWSERIAL(Serial4, 4); -#endif -#if BOARD_HAVE_UART5 -DEFINE_HWSERIAL(Serial5, 5); -#endif -#if BOARD_HAVE_USART6 -DEFINE_HWSERIAL(Serial6, 6); -#endif - HardwareSerial::HardwareSerial(usart_dev *usart_device, uint8 tx_pin, uint8 rx_pin) { diff --git a/STM32F1XX/cores/maple/Print.cpp b/STM32F1XX/cores/maple/Print.cpp index f6bc0c6..6776b39 100644 --- a/STM32F1XX/cores/maple/Print.cpp +++ b/STM32F1XX/cores/maple/Print.cpp @@ -166,6 +166,25 @@ void Print::println(double n, int digits) { println(); } +#ifdef SUPPORTS_PRINTF +#include +#include +// TWork in progress to support printf. +// Need to implement stream FILE to write individual chars to chosen serial port +int Print::printf (__const char *__restrict __format, ...) + { +FILE *__restrict __stream; + int ret_status = 0; + + + va_list args; + va_start(args,__format); + ret_status = vfprintf(__stream, __format, args); + va_end(args); + return ret_status; + } + #endif + /* * Private methods */ diff --git a/STM32F1XX/cores/maple/wirish/HardwareSerial.h b/STM32F1XX/cores/maple/wirish/HardwareSerial.h index f25362b..ffa6dd0 100644 --- a/STM32F1XX/cores/maple/wirish/HardwareSerial.h +++ b/STM32F1XX/cores/maple/wirish/HardwareSerial.h @@ -80,23 +80,44 @@ private: uint8 rx_pin; }; -#if BOARD_HAVE_USART1 -extern HardwareSerial Serial1; -#endif -#if BOARD_HAVE_USART2 -extern HardwareSerial Serial2; -#endif -#if BOARD_HAVE_USART3 -extern HardwareSerial Serial3; -#endif -#if BOARD_HAVE_UART4 -extern HardwareSerial Serial4; -#endif -#if BOARD_HAVE_UART5 -extern HardwareSerial Serial5; -#endif -#if BOARD_HAVE_USART6 -extern HardwareSerial Serial6; +#ifdef BOOTLOADER_maple + #if BOARD_HAVE_USART1 + extern HardwareSerial Serial1; + #endif + #if BOARD_HAVE_USART2 + extern HardwareSerial Serial2; + #endif + #if BOARD_HAVE_USART3 + extern HardwareSerial Serial3; + #endif + #if BOARD_HAVE_UART4 + extern HardwareSerial Serial4; + #endif + #if BOARD_HAVE_UART5 + extern HardwareSerial Serial5; + #endif + #if BOARD_HAVE_USART6 + extern HardwareSerial Serial6; + #endif +#else + #if BOARD_HAVE_USART1 + extern HardwareSerial Serial; + #endif + #if BOARD_HAVE_USART2 + extern HardwareSerial Serial1; + #endif + #if BOARD_HAVE_USART3 + extern HardwareSerial Serial2; + #endif + #if BOARD_HAVE_UART4 + extern HardwareSerial Serial3; + #endif + #if BOARD_HAVE_UART5 + extern HardwareSerial Serial4; + #endif + #if BOARD_HAVE_USART6 + extern HardwareSerial Serial5; + #endif #endif #endif diff --git a/STM32F1XX/cores/maple/wirish/Print.h b/STM32F1XX/cores/maple/wirish/Print.h index 5fd0b7a..e41273b 100644 --- a/STM32F1XX/cores/maple/wirish/Print.h +++ b/STM32F1XX/cores/maple/wirish/Print.h @@ -59,6 +59,10 @@ public: void println(long long, int=DEC); void println(unsigned long long, int=DEC); void println(double, int=2); +#ifdef SUPPORTS_PRINTF +// Roger Clark. Work in progress to add printf support + int printf(const char * format, ...); +#endif private: void printNumber(unsigned long long, uint8); void printFloat(double, uint8); diff --git a/STM32F1XX/cores/maple/wirish/wirish.h b/STM32F1XX/cores/maple/wirish/wirish.h index 0261aee..4419871 100644 --- a/STM32F1XX/cores/maple/wirish/wirish.h +++ b/STM32F1XX/cores/maple/wirish/wirish.h @@ -39,6 +39,8 @@ Added the block of includes up to avr/interrupt so that stdlib functions like memcpy would be included and could be used. */ #include +#include + #include #include #include