Skip to content

Commit 5fa03f5

Browse files
Rework GNSS; deprecate STM32L0.wakeup()
1 parent 1cd99de commit 5fa03f5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+686
-876
lines changed

cores/arduino/CDC.cpp

Lines changed: 1 addition & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016-2018 Thomas Roell. All rights reserved.
2+
* Copyright (c) 2016-2020 Thomas Roell. All rights reserved.
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
* of this software and associated documentation files (the "Software"), to
@@ -59,9 +59,6 @@ CDC::CDC(struct _stm32l0_usbd_cdc_t *usbd_cdc, void (*serialEventRun)(void))
5959
_tx_count = 0;
6060
_tx_size = 0;
6161

62-
_tx_data2 = NULL;
63-
_tx_size2 = 0;
64-
6562
if (serialEventRun) {
6663
g_serialEventRun = serialEventRun;
6764
}
@@ -121,10 +118,6 @@ int CDC::availableForWrite(void)
121118
return 0;
122119
}
123120

124-
if (_tx_size2 != 0) {
125-
return 0;
126-
}
127-
128121
return CDC_TX_BUFFER_SIZE - _tx_count;
129122
}
130123

@@ -182,16 +175,6 @@ size_t CDC::write(const uint8_t *buffer, size_t size)
182175
return 0;
183176
}
184177

185-
if (_tx_size2 != 0) {
186-
if (_nonblocking || (__get_IPSR() != 0)) {
187-
return 0;
188-
}
189-
190-
while (_tx_size2 != 0) {
191-
armv6m_core_wait();
192-
}
193-
}
194-
195178
count = 0;
196179

197180
while (count < size) {
@@ -280,49 +263,6 @@ size_t CDC::write(const uint8_t *buffer, size_t size)
280263
return count;
281264
}
282265

283-
bool CDC::write(const uint8_t *buffer, size_t size, void(*callback)(void))
284-
{
285-
return write(buffer, size, Callback(callback));
286-
}
287-
288-
bool CDC::write(const uint8_t *buffer, size_t size, Callback callback)
289-
{
290-
if (!_enabled) {
291-
return false;
292-
}
293-
294-
if (size == 0) {
295-
return false;
296-
}
297-
298-
if (_tx_size2 != 0) {
299-
return false;
300-
}
301-
302-
_completionCallback = callback;
303-
304-
_tx_data2 = buffer;
305-
_tx_size2 = size;
306-
307-
if (!_tx_busy) {
308-
309-
_tx_busy = true;
310-
311-
if (!stm32l0_usbd_cdc_transmit(_usbd_cdc, _tx_data2, _tx_size2, (stm32l0_usbd_cdc_done_callback_t)CDC::_doneCallback, (void*)this)) {
312-
_tx_busy = false;
313-
314-
_completionCallback = Callback();
315-
316-
_tx_data2 = NULL;
317-
_tx_size2 = 0;
318-
319-
return false;
320-
}
321-
}
322-
323-
return true;
324-
}
325-
326266
void CDC::setNonBlocking(bool enabled)
327267
{
328268
_nonblocking = enabled;
@@ -416,36 +356,8 @@ void CDC::_doneCallback(class CDC *self)
416356
self->_tx_size = 0;
417357
self->_tx_count = 0;
418358
self->_tx_read = self->_tx_write;
419-
420-
if (self->_tx_size2 != 0) {
421-
self->_tx_size2 = 0;
422-
self->_tx_data2 = NULL;
423-
424-
self->_completionCallback.queue();
425-
self->_completionCallback = Callback();
426-
}
427-
}
428-
} else {
429-
if (self->_tx_size2 != 0) {
430-
self->_tx_busy = true;
431-
432-
if (!stm32l0_usbd_cdc_transmit(self->_usbd_cdc, self->_tx_data2, self->_tx_size2, (stm32l0_usbd_cdc_done_callback_t)CDC::_doneCallback, (void*)self)) {
433-
self->_tx_busy = false;
434-
435-
self->_tx_size2 = 0;
436-
self->_tx_data2 = NULL;
437-
438-
self->_completionCallback.queue();
439-
self->_completionCallback = Callback();
440-
}
441359
}
442360
}
443-
} else {
444-
self->_tx_size2 = 0;
445-
self->_tx_data2 = NULL;
446-
447-
self->_completionCallback.queue();
448-
self->_completionCallback = Callback();
449361
}
450362
}
451363

cores/arduino/Callback.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
*/
3636

3737
bool Callback::queue() {
38+
stm32l0_system_wakeup();
39+
3840
if (_callback) {
3941
return armv6m_pendsv_enqueue((armv6m_pendsv_routine_t)_callback, _context, 0);
4042
} else {
@@ -43,6 +45,8 @@ bool Callback::queue() {
4345
}
4446

4547
void Callback::call() {
48+
stm32l0_system_wakeup();
49+
4650
if (_callback) {
4751
(*_callback)(_context);
4852
}

cores/arduino/HardwareSerial.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ extern bool Serial_available() __attribute__((weak));
4747

4848
bool Serial_available() { return Serial.available(); }
4949

50-
static stm32l0_uart_t g_Serial;
50+
extern stm32l0_uart_t g_Serial;
5151
extern const stm32l0_uart_params_t g_SerialParams;
5252

5353
Uart Serial(&g_Serial, &g_SerialParams, (serialEvent ? serialEventRun : NULL));

cores/arduino/HardwareSerial1.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ extern void serialEvent1() __attribute__((weak));
3636

3737
bool Serial1_available() { return Serial1.available(); }
3838

39+
#if defined(USBCON)
40+
extern stm32l0_uart_t g_Serial1;
41+
#else
3942
static stm32l0_uart_t g_Serial1;
43+
#endif
4044
extern const stm32l0_uart_params_t g_Serial1Params;
4145

4246
Uart Serial1(&g_Serial1, &g_Serial1Params, (serialEvent1 ? serialEventRun : NULL));

cores/arduino/USBAPI.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016-2018 Thomas Roell. All rights reserved.
2+
* Copyright (c) 2016-2020 Thomas Roell. All rights reserved.
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
* of this software and associated documentation files (the "Software"), to
@@ -96,10 +96,6 @@ class CDC : public HardwareSerial
9696
SPACE_PARITY = 4,
9797
};
9898

99-
// STM32L0 EXTENSTION: asynchronous write with callback
100-
bool write(const uint8_t *buffer, size_t size, void(*callback)(void));
101-
bool write(const uint8_t *buffer, size_t size, Callback callback);
102-
10399
// STM32L0 EXTENSTION: enable/disable non-blocking writes
104100
void setNonBlocking(bool enable);
105101

@@ -119,10 +115,6 @@ class CDC : public HardwareSerial
119115
volatile uint32_t _tx_count;
120116
volatile uint32_t _tx_size;
121117

122-
const uint8_t *_tx_data2;
123-
volatile uint32_t _tx_size2;
124-
125-
Callback _completionCallback;
126118
Callback _receiveCallback;
127119

128120
static void _eventCallback(class CDC *self, uint32_t events);

cores/arduino/Uart.cpp

Lines changed: 14 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ Uart::Uart(struct _stm32l0_uart_t *uart, const struct _stm32l0_uart_params_t *pa
4646
_tx_count = 0;
4747
_tx_size = 0;
4848

49-
_tx_data2 = NULL;
50-
_tx_size2 = 0;
51-
5249
if (serialEventRun) {
5350
g_serialEventRun = serialEventRun;
5451
}
@@ -121,10 +118,6 @@ int Uart::availableForWrite()
121118
return 0;
122119
}
123120

124-
if (_tx_size2 != 0) {
125-
return 0;
126-
}
127-
128121
return UART_TX_BUFFER_SIZE - _tx_count;
129122
}
130123

@@ -182,16 +175,6 @@ size_t Uart::write(const uint8_t *buffer, size_t size)
182175
return 0;
183176
}
184177

185-
if (_tx_size2 != 0) {
186-
if (_nonblocking || (__get_IPSR() != 0)) {
187-
return 0;
188-
}
189-
190-
while (_tx_size2 != 0) {
191-
armv6m_core_wait();
192-
}
193-
}
194-
195178
count = 0;
196179

197180
while (count < size) {
@@ -282,48 +265,6 @@ size_t Uart::write(const uint8_t *buffer, size_t size)
282265
return count;
283266
}
284267

285-
bool Uart::write(const uint8_t *buffer, size_t size, void(*callback)(void))
286-
{
287-
return write(buffer, size, Callback(callback));
288-
}
289-
290-
bool Uart::write(const uint8_t *buffer, size_t size, Callback callback)
291-
{
292-
if (!_enabled) {
293-
return false;
294-
}
295-
296-
if (size == 0) {
297-
return false;
298-
}
299-
300-
if (_tx_size2 != 0) {
301-
return false;
302-
}
303-
304-
_completionCallback = callback;
305-
306-
_tx_data2 = buffer;
307-
_tx_size2 = size;
308-
309-
if (!_tx_busy) {
310-
_tx_busy = true;
311-
312-
if (!stm32l0_uart_transmit(_uart, _tx_data2, _tx_size2, (stm32l0_uart_done_callback_t)Uart::_doneCallback, (void*)this)) {
313-
_tx_busy = false;
314-
315-
_completionCallback = Callback();
316-
317-
_tx_data2 = NULL;
318-
_tx_size2 = 0;
319-
320-
return false;
321-
}
322-
}
323-
324-
return true;
325-
}
326-
327268
void Uart::rts(bool enable)
328269
{
329270
stm32l0_uart_rts_enable(_uart, enable);
@@ -339,13 +280,6 @@ void Uart::setNonBlocking(bool enable)
339280
_nonblocking = enable;
340281
}
341282

342-
void Uart::setWakeup(bool enable)
343-
{
344-
_option = (_option & ~STM32L0_UART_OPTION_WAKEUP) | (enable ? STM32L0_UART_OPTION_WAKEUP : 0);
345-
346-
stm32l0_uart_configure(_uart, _baudrate, _option);
347-
}
348-
349283
void Uart::setFlowControl(enum FlowControl mode)
350284
{
351285
_option = ((_option & ~(STM32L0_UART_OPTION_RTS | STM32L0_UART_OPTION_CTS | STM32L0_UART_OPTION_XONOFF)) |
@@ -365,6 +299,20 @@ void Uart::onReceive(Callback callback)
365299
_receiveCallback = callback;
366300
}
367301

302+
void Uart::enableWakeup()
303+
{
304+
_option |= STM32L0_UART_OPTION_WAKEUP;
305+
306+
stm32l0_uart_configure(_uart, _baudrate, _option);
307+
}
308+
309+
void Uart::disableWakeup()
310+
{
311+
_option &= ~STM32L0_UART_OPTION_WAKEUP;
312+
313+
stm32l0_uart_configure(_uart, _baudrate, _option);
314+
}
315+
368316
void Uart::_eventCallback(class Uart *self, uint32_t events)
369317
{
370318
if (events & STM32L0_UART_EVENT_RECEIVE) {
@@ -408,35 +356,7 @@ void Uart::_doneCallback(class Uart *self)
408356
self->_tx_size = 0;
409357
self->_tx_count = 0;
410358
self->_tx_read = self->_tx_write;
411-
412-
if (self->_tx_size2 != 0) {
413-
self->_tx_size2 = 0;
414-
self->_tx_data2 = NULL;
415-
416-
self->_completionCallback.queue();
417-
self->_completionCallback = Callback();
418-
}
419-
}
420-
} else {
421-
if (self->_tx_size2 != 0) {
422-
self->_tx_busy = true;
423-
424-
if (!stm32l0_uart_transmit(self->_uart, self->_tx_data2, self->_tx_size2, (stm32l0_uart_done_callback_t)Uart::_doneCallback, (void*)self)) {
425-
self->_tx_busy = false;
426-
427-
self->_tx_size2 = 0;
428-
self->_tx_data2 = NULL;
429-
430-
self->_completionCallback.queue();
431-
self->_completionCallback = Callback();
432-
}
433359
}
434360
}
435-
} else {
436-
self->_tx_size2 = 0;
437-
self->_tx_data2 = NULL;
438-
439-
self->_completionCallback.queue();
440-
self->_completionCallback = Callback();
441361
}
442362
}

0 commit comments

Comments
 (0)