Skip to content

Commit 37661b6

Browse files
authored
Merge pull request stm32duino#255 from fpistm/pr183-review
Add Low Power driver (Rework of PR 183)
2 parents a3d9b45 + 06ea423 commit 37661b6

File tree

40 files changed

+1107
-10
lines changed

40 files changed

+1107
-10
lines changed

cores/arduino/HardwareSerial.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,16 @@ void HardwareSerial::init(void)
182182
_serial.tx_tail = 0;
183183
}
184184

185+
void HardwareSerial::configForLowPower(void)
186+
{
187+
#if defined(HAL_PWR_MODULE_ENABLED) && defined(UART_IT_WUF)
188+
// Reconfigure properly Serial instance to use HSI as clock source
189+
end();
190+
uart_config_lowpower(&_serial);
191+
begin(_serial.baudrate, _config);
192+
#endif
193+
}
194+
185195
// Actual interrupt handlers //////////////////////////////////////////////////////////////
186196

187197
void HardwareSerial::_rx_complete_irq(serial_t* obj)
@@ -226,6 +236,7 @@ void HardwareSerial::begin(unsigned long baud, byte config)
226236
uint32_t databits = 0;
227237

228238
_serial.baudrate = (uint32_t)baud;
239+
_config = config;
229240

230241
// Manage databits
231242
switch(config & 0x07) {

cores/arduino/HardwareSerial.h

+4
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,15 @@ class HardwareSerial : public Stream
125125
void setRx(PinName _rx);
126126
void setTx(PinName _tx);
127127

128+
friend class STM32LowPower;
129+
128130
// Interrupt handlers
129131
static void _rx_complete_irq(serial_t* obj);
130132
static int _tx_complete_irq(serial_t* obj);
131133
private:
134+
uint8_t _config;
132135
void init(void);
136+
void configForLowPower(void);
133137
};
134138

135139
extern HardwareSerial Serial1;

cores/arduino/board.h

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ extern "C"{
1414
#include "digital_io.h"
1515
#include "hal_uart_emul.h"
1616
#include "hw_config.h"
17+
#include "low_power.h"
1718
#include "rtc.h"
1819
#include "spi_com.h"
1920
#include "stm32_eeprom.h"

cores/arduino/stm32/PinNames.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ extern "C" {
99
#endif
1010

1111
typedef enum {
12+
// Not connected
13+
NC = (int)0xFFFFFFFF,
1214

15+
// Pin name definition
1316
PA_0 = (PortA << 4) + 0x00,
1417
PA_1 = (PortA << 4) + 0x01,
1518
PA_2 = (PortA << 4) + 0x02,
@@ -205,8 +208,11 @@ typedef enum {
205208
PK_14 = (PortK << 4) + 0x0E,
206209
PK_15 = (PortK << 4) + 0x0F,
207210
#endif
208-
// Not connected
209-
NC = (int)0xFFFFFFFF
211+
// Specific pin name define in the variant
212+
#if __has_include("PinNamesVar.h")
213+
#include "PinNamesVar.h"
214+
#endif
215+
P_END = NC
210216
} PinName;
211217

212218
#ifdef __cplusplus

0 commit comments

Comments
 (0)