Skip to content

Commit ef60992

Browse files
committed
Merge remote-tracking branch 'upstream/master' into Fix-ifSerial
2 parents c4643b2 + 3c4307e commit ef60992

40 files changed

Lines changed: 317 additions & 255 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ other/maple-bootloader/build
77
other/maple-bootloader/*~
88
*.o
99
tools/src/stm32flash_serial/src/parsers/parsers.a
10+
*.bak
11+
*.1

STM32F1/cores/maple/HardwareSerial.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ size_t HardwareSerial::write(unsigned char ch) {
193193
return 1;
194194
}
195195

196+
/* edogaldo: Waits for the transmission of outgoing serial data to complete (Arduino 1.0 api specs) */
196197
void HardwareSerial::flush(void) {
197-
usart_reset_rx(this->usart_device);
198-
usart_reset_tx(this->usart_device);
198+
while(!rb_is_empty(this->usart_device->wb)); // wait for TX buffer empty
199+
while(!((this->usart_device->regs->SR) & (1<<USART_SR_TC_BIT))); // wait for TC (Transmission Complete) flag set
199200
}

STM32F1/cores/maple/itoa.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,12 @@ extern char* ltoa( long value, char *string, int radix )
120120

121121
return string;
122122
}
123-
123+
#if __GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ > 9 || \
124+
(__GNUC_MINOR__ == 9 && __GNUC_PATCHLEVEL__ > 2)))
125+
extern char* utoa( unsigned value, char *string, int radix )
126+
#else
124127
extern char* utoa( unsigned long value, char *string, int radix )
128+
#endif
125129
{
126130
return ultoa( value, string, radix ) ;
127131
}

STM32F1/cores/maple/itoa.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ extern void itoa( int n, char s[] ) ;
3131

3232
extern char* itoa( int value, char *string, int radix ) ;
3333
extern char* ltoa( long value, char *string, int radix ) ;
34+
#if __GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ > 9 || \
35+
(__GNUC_MINOR__ == 9 && __GNUC_PATCHLEVEL__ > 2)))
36+
extern char* utoa( unsigned value, char *string, int radix ) ;
37+
#else
3438
extern char* utoa( unsigned long value, char *string, int radix ) ;
39+
#endif
3540
extern char* ultoa( unsigned long value, char *string, int radix ) ;
3641
#endif /* 0 */
3742

STM32F1/cores/maple/libmaple/dma_f1.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,6 @@ void dma_set_per_addr(dma_dev *dev, dma_channel channel, __io void *addr) {
341341
* @see dma_attach_interrupt()
342342
* @see dma_enable()
343343
*/
344-
__deprecated
345344
void dma_setup_transfer(dma_dev *dev,
346345
dma_channel channel,
347346
__io void *peripheral_address,

STM32F1/cores/maple/libmaple/gpio_f1.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ gpio_pin_mode gpio_get_mode(gpio_dev *dev, uint8 pin) {
142142
gpio_reg_map *regs = dev->regs;
143143
__io uint32 *cr = &regs->CRL + (pin >> 3);
144144
uint32 shift = (pin & 0x7) * 4;
145-
uint32 tmp = *cr;
146145

147146
uint32 crMode = (*cr>>shift) & 0x0F;
148147

STM32F1/cores/maple/libmaple/spi.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void spi_slave_enable(spi_dev *dev, spi_mode mode, uint32 flags) {
8484
}
8585

8686
/**
87-
* @brief Nonblocking SPI transmit.
87+
* @brief Blocking SPI transmit.
8888
* @param dev SPI port to use for transmission
8989
* @param buf Buffer to transmit. The sizeof buf's elements are
9090
* inferred from dev's data frame format (i.e., are
@@ -93,15 +93,21 @@ void spi_slave_enable(spi_dev *dev, spi_mode mode, uint32 flags) {
9393
* @return Number of elements transmitted.
9494
*/
9595
uint32 spi_tx(spi_dev *dev, const void *buf, uint32 len) {
96-
uint32 txed = 0;
97-
uint8 byte_frame = spi_dff(dev) == SPI_DFF_8_BIT;
98-
while (spi_is_tx_empty(dev) && (txed < len)) {
99-
if (byte_frame) {
100-
dev->regs->DR = ((const uint8*)buf)[txed++];
101-
} else {
102-
dev->regs->DR = ((const uint16*)buf)[txed++];
103-
}
104-
}
96+
uint32 txed = len;
97+
spi_reg_map *regs = dev->regs;
98+
if ( spi_dff(dev) == SPI_DFF_8_BIT ) {
99+
const uint8 * dp8 = (const uint8*)buf;
100+
while ( len-- ) {
101+
while ( (regs->SR & SPI_SR_TXE)==0 ) ; //while ( spi_is_tx_empty(dev)==0 ); // wait Tx to be empty
102+
regs->DR = *dp8++;
103+
}
104+
} else {
105+
const uint16 * dp16 = (const uint16*)buf;
106+
while ( len-- ) {
107+
while ( (regs->SR & SPI_SR_TXE)==0 ) ; //while ( spi_is_tx_empty(dev)==0 ); // wait Tx to be empty
108+
regs->DR = *dp16++;
109+
}
110+
}
105111
return txed;
106112
}
107113

STM32F1/cores/maple/usb_serial.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ static void ifaceSetupHook(unsigned, void*);
5454
*/
5555

5656
#define USB_TIMEOUT 50
57+
#if BOARD_HAVE_SERIALUSB
58+
bool USBSerial::_hasBegun = false;
59+
#endif
5760

5861
USBSerial::USBSerial(void) {
5962
#if !BOARD_HAVE_SERIALUSB
@@ -62,7 +65,12 @@ USBSerial::USBSerial(void) {
6265
}
6366

6467
void USBSerial::begin(void) {
68+
6569
#if BOARD_HAVE_SERIALUSB
70+
if (_hasBegun)
71+
return;
72+
_hasBegun = true;
73+
6674
usb_cdcacm_enable(BOARD_USB_DISC_DEV, BOARD_USB_DISC_BIT);
6775
usb_cdcacm_set_hooks(USB_CDCACM_HOOK_RX, rxHook);
6876
usb_cdcacm_set_hooks(USB_CDCACM_HOOK_IFACE_SETUP, ifaceSetupHook);
@@ -75,6 +83,7 @@ void USBSerial::begin(unsigned long ignoreBaud)
7583
volatile unsigned long removeCompilerWarningsIgnoreBaud=ignoreBaud;
7684

7785
ignoreBaud=removeCompilerWarningsIgnoreBaud;
86+
begin();
7887
}
7988
void USBSerial::begin(unsigned long ignoreBaud, uint8_t ignore)
8089
{
@@ -83,13 +92,16 @@ volatile uint8_t removeCompilerWarningsIgnore=ignore;
8392

8493
ignoreBaud=removeCompilerWarningsIgnoreBaud;
8594
ignore=removeCompilerWarningsIgnore;
95+
begin();
8696
}
8797

8898
void USBSerial::end(void) {
8999
#if BOARD_HAVE_SERIALUSB
90100
usb_cdcacm_disable(BOARD_USB_DISC_DEV, BOARD_USB_DISC_BIT);
91101
usb_cdcacm_remove_hooks(USB_CDCACM_HOOK_RX | USB_CDCACM_HOOK_IFACE_SETUP);
102+
_hasBegun = false;
92103
#endif
104+
93105
}
94106

95107
size_t USBSerial::write(uint8 ch) {

STM32F1/cores/maple/usb_serial.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,31 +59,34 @@ class USBSerial : public Stream {
5959
virtual int read(void);
6060
int availableForWrite(void);
6161
virtual void flush(void);
62-
63-
62+
63+
6464
size_t write(uint8);
6565
size_t write(const char *str);
6666
size_t write(const uint8*, uint32);
6767

6868
uint8 getRTS();
6969
uint8 getDTR();
7070
uint8 pending();
71-
71+
7272
/* SukkoPera: This is the Arduino way to check if an USB CDC serial
7373
* connection is open.
74-
74+
7575
* Used for instance in cardinfo.ino.
7676
*/
7777
operator bool();
78-
78+
7979
/* Old libmaple way to check for serial connection.
8080
*
8181
* Deprecated, use the above.
8282
*/
8383
uint8 isConnected() __attribute__((deprecated("Use !Serial instead"))) { return (bool) *this; }
84+
85+
protected:
86+
static bool _hasBegun;
8487
};
8588

86-
#ifdef SERIAL_USB
89+
#ifdef SERIAL_USB
8790
extern USBSerial Serial;
8891
#endif
8992

STM32F1/cores/maple/wirish_time.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,15 @@
3232

3333
#include <libmaple/libmaple_types.h>
3434
#include <libmaple/delay.h>
35+
#include "Arduino.h"
3536

3637
void delay(unsigned long ms) {
3738
uint32 start = millis();
38-
while (millis() - start < ms)
39-
;
39+
do
40+
{
41+
yield();
42+
}
43+
while (millis() - start < ms);
4044
}
4145

4246
void delayMicroseconds(uint32 us) {

0 commit comments

Comments
 (0)