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)

This commit is contained in:
Roger Clark 2014-11-01 09:27:18 +11:00
parent 5a79e664af
commit dbabd6fd52
6 changed files with 102 additions and 36 deletions

View File

@ -123,7 +123,7 @@ maple_STM32.upload.auto_reset=true
maple_STM32.build.mcu=cortex-m3 maple_STM32.build.mcu=cortex-m3
maple_STM32.build.f_cpu=72000000L maple_STM32.build.f_cpu=72000000L
maple_STM32.build.core=maple 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.ldscript=ld/jtag.ld
maple_STM32.build.variant=maple_mini maple_STM32.build.variant=maple_mini
maple_STM32.build.variant_system_lib=libmaple.a maple_STM32.build.variant_system_lib=libmaple.a

View File

@ -42,25 +42,45 @@
BOARD_USART##n##_TX_PIN, \ BOARD_USART##n##_TX_PIN, \
BOARD_USART##n##_RX_PIN) BOARD_USART##n##_RX_PIN)
#if BOARD_HAVE_USART1 #ifdef BOOTLOADER_maple
DEFINE_HWSERIAL(Serial1, 1); #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 #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, HardwareSerial::HardwareSerial(usart_dev *usart_device,
uint8 tx_pin, uint8 tx_pin,
uint8 rx_pin) { uint8 rx_pin) {

View File

@ -166,6 +166,25 @@ void Print::println(double n, int digits) {
println(); println();
} }
#ifdef SUPPORTS_PRINTF
#include <stdio.h>
#include <stdarg.h>
// 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 * Private methods
*/ */

View File

@ -80,23 +80,44 @@ private:
uint8 rx_pin; uint8 rx_pin;
}; };
#if BOARD_HAVE_USART1 #ifdef BOOTLOADER_maple
extern HardwareSerial Serial1; #if BOARD_HAVE_USART1
#endif extern HardwareSerial Serial1;
#if BOARD_HAVE_USART2 #endif
extern HardwareSerial Serial2; #if BOARD_HAVE_USART2
#endif extern HardwareSerial Serial2;
#if BOARD_HAVE_USART3 #endif
extern HardwareSerial Serial3; #if BOARD_HAVE_USART3
#endif extern HardwareSerial Serial3;
#if BOARD_HAVE_UART4 #endif
extern HardwareSerial Serial4; #if BOARD_HAVE_UART4
#endif extern HardwareSerial Serial4;
#if BOARD_HAVE_UART5 #endif
extern HardwareSerial Serial5; #if BOARD_HAVE_UART5
#endif extern HardwareSerial Serial5;
#if BOARD_HAVE_USART6 #endif
extern HardwareSerial Serial6; #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
#endif #endif

View File

@ -59,6 +59,10 @@ public:
void println(long long, int=DEC); void println(long long, int=DEC);
void println(unsigned long long, int=DEC); void println(unsigned long long, int=DEC);
void println(double, int=2); void println(double, int=2);
#ifdef SUPPORTS_PRINTF
// Roger Clark. Work in progress to add printf support
int printf(const char * format, ...);
#endif
private: private:
void printNumber(unsigned long long, uint8); void printNumber(unsigned long long, uint8);
void printFloat(double, uint8); void printFloat(double, uint8);

View File

@ -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. Added the block of includes up to avr/interrupt so that stdlib functions like memcpy would be included and could be used.
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h>
#include <string.h> #include <string.h>
#include <avr/pgmspace.h> #include <avr/pgmspace.h>
#include <avr/interrupt.h> #include <avr/interrupt.h>