Skip to content

Commit f6a404c

Browse files
committed
Update Serial menu and defined generic Serial instance
Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent 9df0c97 commit f6a404c

File tree

20 files changed

+162
-69
lines changed

20 files changed

+162
-69
lines changed

boards.txt

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
menu.pnum=Board part number
44

5-
menu.xserial=Extra serial instance
5+
menu.xserial=Serial interface
66
menu.usb=USB interface
77

88
menu.opt=Optimize
@@ -328,37 +328,37 @@ Disco.menu.upload_method.STLink.upload.tool=stlink_upload
328328

329329
################################################################################
330330
# Serialx activation
331-
Nucleo_144.menu.xserial.none=None
332-
Nucleo_144.menu.xserial.SerialAll=All
333-
Nucleo_144.menu.xserial.SerialAll.build.xSerial=-DENABLE_SERIAL1 -DENABLE_SERIAL2
334-
Nucleo_144.menu.xserial.Serial1=Serial1 (if available)
335-
Nucleo_144.menu.xserial.Serial1.build.xSerial=-DENABLE_SERIAL1
336-
Nucleo_144.menu.xserial.Serial2=Serial2 (if available)
337-
Nucleo_144.menu.xserial.Serial2.build.xSerial=-DENABLE_SERIAL2
338-
339-
Nucleo_64.menu.xserial.none=None
340-
Nucleo_64.menu.xserial.SerialAll=All
341-
Nucleo_64.menu.xserial.SerialAll.build.xSerial=-DENABLE_SERIAL1 -DENABLE_SERIAL2
342-
Nucleo_64.menu.xserial.Serial1=Serial1 (if available)
343-
Nucleo_64.menu.xserial.Serial1.build.xSerial=-DENABLE_SERIAL1
344-
Nucleo_64.menu.xserial.Serial2=Serial2 (if available)
345-
Nucleo_64.menu.xserial.Serial2.build.xSerial=-DENABLE_SERIAL2
346-
347-
Nucleo_32.menu.xserial.none=None
348-
Nucleo_32.menu.xserial.SerialAll=All
349-
Nucleo_32.menu.xserial.SerialAll.build.xSerial=-DENABLE_SERIAL1 -DENABLE_SERIAL2
350-
Nucleo_32.menu.xserial.Serial1=Serial1 (if available)
351-
Nucleo_32.menu.xserial.Serial1.build.xSerial=-DENABLE_SERIAL1
352-
Nucleo_32.menu.xserial.Serial2=Serial2 (if available)
353-
Nucleo_32.menu.xserial.Serial2.build.xSerial=-DENABLE_SERIAL2
354-
355-
Disco.menu.xserial.none=None
356-
Disco.menu.xserial.SerialAll=All
357-
Disco.menu.xserial.SerialAll.build.xSerial=-DENABLE_SERIAL1 -DENABLE_SERIAL2
358-
Disco.menu.xserial.Serial1=Serial1 (if available)
359-
Disco.menu.xserial.Serial1.build.xSerial=-DENABLE_SERIAL1
360-
Disco.menu.xserial.Serial2=Serial2 (if available)
361-
Disco.menu.xserial.Serial2.build.xSerial=-DENABLE_SERIAL2
331+
Nucleo_144.menu.xserial.generic=Generic Serial
332+
Nucleo_144.menu.xserial.none=No Serial
333+
Nucleo_144.menu.xserial.none.build.xSerial=-DNO_HWSERIAL
334+
Nucleo_144.menu.xserial.all=All (up to 10)
335+
Nucleo_144.menu.xserial.all.build.xSerial=-DALL_HWSERIAL
336+
Nucleo_144.menu.xserial.third=Enable first third (USART1 to 3 if available)
337+
Nucleo_144.menu.xserial.third.build.xSerial=-DFIRST_THIRD_HWSERIAL
338+
339+
Nucleo_64.menu.xserial.generic=Generic Serial
340+
Nucleo_64.menu.xserial.none=No Serial
341+
Nucleo_64.menu.xserial.none.build.xSerial=-DNO_HWSERIAL
342+
Nucleo_64.menu.xserial.all=All (up to 10)
343+
Nucleo_64.menu.xserial.all.build.xSerial=-DALL_HWSERIAL
344+
Nucleo_64.menu.xserial.third=Enable first third (USART1 to 3 if available)
345+
Nucleo_64.menu.xserial.third.build.xSerial=-DFIRST_THIRD_HWSERIAL
346+
347+
Nucleo_32.menu.xserial.generic=Generic Serial
348+
Nucleo_32.menu.xserial.none=No Serial
349+
Nucleo_32.menu.xserial.none.build.xSerial=-DNO_HWSERIAL
350+
Nucleo_32.menu.xserial.all=All (up to 10)
351+
Nucleo_32.menu.xserial.all.build.xSerial=-DALL_HWSERIAL
352+
Nucleo_32.menu.xserial.third=Enable first third (USART1 to 3 if available)
353+
Nucleo_32.menu.xserial.third.build.xSerial=-DFIRST_THIRD_HWSERIAL
354+
355+
Disco.menu.xserial.generic=Generic Serial
356+
Disco.menu.xserial.none=No Serial
357+
Disco.menu.xserial.none.build.xSerial=-DNO_HWSERIAL
358+
Disco.menu.xserial.all=All (up to 10)
359+
Disco.menu.xserial.all.build.xSerial=-DALL_HWSERIAL
360+
Disco.menu.xserial.third=Enable first third (USART1 to 3 if available)
361+
Disco.menu.xserial.third.build.xSerial=-DFIRST_THIRD_HWSERIAL
362362

363363
# USB connectivity
364364
Nucleo_144.menu.usb.none=None

cores/arduino/HardwareSerial.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,13 @@
3030
#include "Arduino.h"
3131
#include "HardwareSerial.h"
3232

33+
#if !defined(NO_HWSERIAL)
34+
#if defined(HAVE_HWSERIAL1) || defined(HAVE_HWSERIAL2) || defined(HAVE_HWSERIAL3) ||\
35+
defined(HAVE_HWSERIAL4) || defined(HAVE_HWSERIAL5) || defined(HAVE_HWSERIAL6) ||\
36+
defined(HAVE_HWSERIAL7) || defined(HAVE_HWSERIAL8) || defined(HAVE_HWSERIAL8) ||\
37+
defined(HAVE_HWSERIAL10)
3338
// SerialEvent functions are weak, so when the user doesn't define them,
3439
// the linker just sets their address to 0 (which is checked below).
35-
3640
#if defined(HAVE_HWSERIAL1)
3741
HardwareSerial Serial1(USART1);
3842
void serialEvent1() __attribute__((weak));
@@ -367,3 +371,5 @@ void HardwareSerial::setRx(PinName _rx) {
367371
void HardwareSerial::setTx(PinName _tx){
368372
_serial.pin_tx = _tx;
369373
}
374+
#endif // HAVE_HWSERIALx
375+
#endif // !NO_HWSERIAL

cores/arduino/stm32/uart.h

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,42 +41,146 @@
4141

4242
/* Includes ------------------------------------------------------------------*/
4343
#include "stm32_def.h"
44-
#include "PeripheralPins.h"
44+
#include "variant.h"
4545

4646
#ifdef __cplusplus
4747
extern "C" {
4848
#endif
4949

50+
#if !defined(NO_HWSERIAL)
51+
#if defined(ALL_HWSERIAL) || defined(FIRST_THIRD_HWSERIAL)
52+
#define ENABLE_HWSERIAL1
53+
#define ENABLE_HWSERIAL2
54+
#define ENABLE_HWSERIAL3
55+
#if !defined(FIRST_THIRD_HWSERIAL)
56+
#define ENABLE_HWSERIAL4
57+
#define ENABLE_HWSERIAL5
58+
#define ENABLE_HWSERIAL6
59+
#define ENABLE_HWSERIAL7
60+
#define ENABLE_HWSERIAL8
61+
#define ENABLE_HWSERIAL9
62+
#define ENABLE_HWSERIAL10
63+
#endif // FIRST_THIRD_HWSERIAL
64+
#endif // ALL_HWSERIAL || FIRST_THIRD_HWSERIAL
65+
#ifdef SERIAL_UART_INSTANCE
66+
#if SERIAL_UART_INSTANCE == 1
67+
#define ENABLE_HWSERIAL1
68+
#if !defined(Serial)
69+
#define Serial Serial1
70+
#define serialEvent serialEvent1
71+
#endif
72+
#elif SERIAL_UART_INSTANCE == 2
73+
#define ENABLE_HWSERIAL2
74+
#if !defined(Serial)
75+
#define Serial Serial2
76+
#define serialEvent serialEvent2
77+
#endif
78+
#elif SERIAL_UART_INSTANCE == 3
79+
#define ENABLE_HWSERIAL3
80+
#if !defined(Serial)
81+
#define Serial Serial3
82+
#define serialEvent serialEvent3
83+
#endif
84+
#elif SERIAL_UART_INSTANCE == 4
85+
#define ENABLE_HWSERIAL4
86+
#if !defined(Serial)
87+
#define Serial Serial4
88+
#define serialEvent serialEvent4
89+
#endif
90+
#elif SERIAL_UART_INSTANCE == 5
91+
#define ENABLE_HWSERIAL5
92+
#if !defined(Serial)
93+
#define Serial Serial5
94+
#define serialEvent serialEvent5
95+
#endif
96+
#elif SERIAL_UART_INSTANCE == 6
97+
#define ENABLE_HWSERIAL6
98+
#if !defined(Serial)
99+
#define Serial Serial6
100+
#define serialEvent serialEvent6
101+
#endif
102+
#elif SERIAL_UART_INSTANCE == 7
103+
#define ENABLE_HWSERIAL7
104+
#if !defined(Serial)
105+
#define Serial Serial7
106+
#define serialEvent serialEvent7
107+
#endif
108+
#elif SERIAL_UART_INSTANCE == 8
109+
#define ENABLE_HWSERIAL8
110+
#if !defined(Serial)
111+
#define Serial Serial8
112+
#define serialEvent serialEvent8
113+
#endif
114+
#elif SERIAL_UART_INSTANCE == 9
115+
#define ENABLE_HWSERIAL9
116+
#if !defined(Serial)
117+
#define Serial Serial9
118+
#define serialEvent serialEvent9
119+
#endif
120+
#elif SERIAL_UART_INSTANCE == 10
121+
#define ENABLE_HWSERIAL10
122+
#if !defined(Serial)
123+
#define Serial Serial10
124+
#define serialEvent serialEvent10
125+
#endif
126+
#endif // SERIAL_UART_INSTANCE == x
127+
#else
128+
#if !defined(Serial)
129+
#warning "No generic 'Serial' defined!"
130+
#endif
131+
#endif // SERIAL_UART_INSTANCE
132+
#endif // NO_HWSERIAL
133+
134+
#if defined(ENABLE_HWSERIAL1)
50135
#if defined(USART1_BASE)
51136
#define HAVE_HWSERIAL1
52137
#endif
138+
#endif
139+
#if defined(ENABLE_HWSERIAL2)
53140
#if defined(USART2_BASE)
54141
#define HAVE_HWSERIAL2
55142
#endif
143+
#endif
144+
#if defined(ENABLE_HWSERIAL3)
56145
#if defined(USART3_BASE)
57146
#define HAVE_HWSERIAL3
58147
#endif
148+
#endif
149+
#if defined(ENABLE_HWSERIAL4)
59150
#if defined(USART4_BASE) || defined(UART4_BASE)
60151
#define HAVE_HWSERIAL4
61152
#endif
153+
#endif
154+
#if defined(ENABLE_HWSERIAL5)
62155
#if defined(USART5_BASE) || defined(UART5_BASE)
63156
#define HAVE_HWSERIAL5
64157
#endif
158+
#endif
159+
#if defined(ENABLE_HWSERIAL6)
65160
#if defined(USART6_BASE)
66161
#define HAVE_HWSERIAL6
67162
#endif
163+
#endif
164+
#if defined(ENABLE_HWSERIAL7)
68165
#if defined(USART7_BASE) || defined(UART7_BASE)
69166
#define HAVE_HWSERIAL7
70167
#endif
168+
#endif
169+
#if defined(ENABLE_HWSERIAL8)
71170
#if defined(USART8_BASE) || defined(UART8_BASE)
72171
#define HAVE_HWSERIAL8
73172
#endif
173+
#endif
174+
#if defined(ENABLE_HWSERIAL9)
74175
#if defined(UART9_BASE)
75176
#define HAVE_HWSERIAL9
76177
#endif
178+
#endif
179+
#if defined(ENABLE_HWSERIAL10)
77180
#if defined(UART10_BASE)
78181
#define HAVE_HWSERIAL10
79182
#endif
183+
#endif
80184

81185
/* Exported types ------------------------------------------------------------*/
82186
typedef struct serial_s serial_t;

variants/DISCO_F100RB/variant.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ enum {
153153
#define TIMER_SERVO TIM17 //TODO: advanced-control timers don't work
154154

155155
// UART Definitions
156+
#define SERIAL_UART_INSTANCE 2 //Connected to ST-Link
156157
// Default pin used for 'Serial' instance (ex: ST-Link)
157158
// Mandatory for Firmata
158159
#define PIN_SERIAL_RX 8
@@ -166,8 +167,6 @@ enum {
166167
*----------------------------------------------------------------------------*/
167168

168169
#ifdef __cplusplus
169-
#define Serial Serial2 //Connected to ST-Link
170-
171170
// These serial port names are intended to allow libraries and architecture-neutral
172171
// sketches to automatically default to the correct port name for a particular type
173172
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,

variants/DISCO_F407VG/variant.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ enum {
178178
#define TIMER_UART_EMULATED TIM6
179179

180180
// UART Definitions
181+
#define SERIAL_UART_INSTANCE 2 //Connected to ST-Link
181182
// UART Emulation
182183
#define UART_EMUL_RX PE_9
183184
#define UART_EMUL_TX PE_11
@@ -195,8 +196,6 @@ enum {
195196
*----------------------------------------------------------------------------*/
196197

197198
#ifdef __cplusplus
198-
#define Serial Serial2 // Could be connected to ST-Link
199-
200199
// These serial port names are intended to allow libraries and architecture-neutral
201200
// sketches to automatically default to the correct port name for a particular type
202201
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,

variants/DISCO_F746NG/variant.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ enum {
110110
#define TIMER_SERVO TIM2 //TODO: advanced-control timers don't work
111111

112112
// UART Definitions
113+
#define SERIAL_UART_INSTANCE 1 //Connected to ST-Link
113114
// Default pin used for 'Serial' instance (ex: ST-Link)
114115
// Mandatory for Firmata
115116
#define PIN_SERIAL_RX PB7
@@ -123,8 +124,6 @@ enum {
123124
*----------------------------------------------------------------------------*/
124125

125126
#ifdef __cplusplus
126-
#define Serial Serial1 //Connected to ST-Link
127-
128127
// These serial port names are intended to allow libraries and architecture-neutral
129128
// sketches to automatically default to the correct port name for a particular type
130129
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,

variants/DISCO_L475VG_IOT/variant.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ enum {
180180
#define TIMER_SERVO TIM2 //TODO: advanced-control timers don't work
181181

182182
// UART Definitions
183+
#define SERIAL_UART_INSTANCE 1 //Connected to ST-Link
183184
// Default pin used for 'Serial' instance (ex: ST-Link)
184185
// Mandatory for Firmata
185186
#define PIN_SERIAL_RX 0
@@ -193,8 +194,6 @@ enum {
193194
*----------------------------------------------------------------------------*/
194195

195196
#ifdef __cplusplus
196-
#define Serial Serial1 //Connected to ST-Link
197-
198197
// These serial port names are intended to allow libraries and architecture-neutral
199198
// sketches to automatically default to the correct port name for a particular type
200199
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,

variants/NUCLEO_F030R8/variant.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ enum {
151151
#define TIMER_SERVO TIM3 //TODO: advanced-control timers don't work
152152

153153
// UART Definitions
154+
#define SERIAL_UART_INSTANCE 2 //Connected to ST-Link
154155
// Default pin used for 'Serial' instance (ex: ST-Link)
155156
// Mandatory for Firmata
156157
#define PIN_SERIAL_RX 0
@@ -164,8 +165,6 @@ enum {
164165
*----------------------------------------------------------------------------*/
165166

166167
#ifdef __cplusplus
167-
#define Serial Serial2 //Connected to ST-Link
168-
169168
// These serial port names are intended to allow libraries and architecture-neutral
170169
// sketches to automatically default to the correct port name for a particular type
171170
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,

variants/NUCLEO_F091RC/variant.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ enum {
150150
#define TIMER_SERVO TIM2 //TODO: advanced-control timers don't work
151151

152152
// UART Definitions
153+
#define SERIAL_UART_INSTANCE 2 //Connected to ST-Link
153154
// UART Emulation
154155
#define UART_EMUL_RX PB_14
155156
#define UART_EMUL_TX PB_13
@@ -167,8 +168,6 @@ enum {
167168
*----------------------------------------------------------------------------*/
168169

169170
#ifdef __cplusplus
170-
#define Serial Serial2 //Connected to ST-Link
171-
172171
// These serial port names are intended to allow libraries and architecture-neutral
173172
// sketches to automatically default to the correct port name for a particular type
174173
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,

variants/NUCLEO_F103RB/variant.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ enum {
150150
#define TIMER_SERVO TIM2 //TODO: advanced-control timers don't work
151151

152152
// UART Definitions
153+
#define SERIAL_UART_INSTANCE 2 //Connected to ST-Link
153154
// Default pin used for 'Serial' instance (ex: ST-Link)
154155
// Mandatory for Firmata
155156
#define PIN_SERIAL_RX 0
@@ -163,8 +164,6 @@ enum {
163164
*----------------------------------------------------------------------------*/
164165

165166
#ifdef __cplusplus
166-
#define Serial Serial2 //Connected to ST-Link
167-
168167
// These serial port names are intended to allow libraries and architecture-neutral
169168
// sketches to automatically default to the correct port name for a particular type
170169
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,

variants/NUCLEO_F207ZG/variant.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ enum {
195195
#define TIMER_SERVO TIM2 //TODO: advanced-control timers don't work
196196

197197
// UART Definitions
198+
#define SERIAL_UART_INSTANCE 3 //Connected to ST-Link
198199
// Default pin used for 'Serial' instance (ex: ST-Link)
199200
// Mandatory for Firmata
200201
#define PIN_SERIAL_RX PD9
@@ -208,8 +209,6 @@ enum {
208209
*----------------------------------------------------------------------------*/
209210

210211
#ifdef __cplusplus
211-
#define Serial Serial3 //Connected to ST-Link
212-
213212
// These serial port names are intended to allow libraries and architecture-neutral
214213
// sketches to automatically default to the correct port name for a particular type
215214
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,

variants/NUCLEO_F303RE/variant.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ enum {
150150
#define TIMER_SERVO TIM2 //TODO: advanced-control timers don't work
151151

152152
// UART Definitions
153+
#define SERIAL_UART_INSTANCE 2 //Connected to ST-Link
153154
// UART Emulation
154155
#define UART_EMUL_RX PC_1
155156
#define UART_EMUL_TX PC_3
@@ -167,8 +168,6 @@ enum {
167168
*----------------------------------------------------------------------------*/
168169

169170
#ifdef __cplusplus
170-
#define Serial Serial2 //Connected to ST-Link
171-
172171
// These serial port names are intended to allow libraries and architecture-neutral
173172
// sketches to automatically default to the correct port name for a particular type
174173
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,

0 commit comments

Comments
 (0)