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.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

View File

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

View File

@ -166,6 +166,25 @@ void Print::println(double n, int digits) {
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
*/

View File

@ -80,6 +80,7 @@ private:
uint8 rx_pin;
};
#ifdef BOOTLOADER_maple
#if BOARD_HAVE_USART1
extern HardwareSerial Serial1;
#endif
@ -98,5 +99,25 @@ extern HardwareSerial Serial5;
#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

View File

@ -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);

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.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>