13
13
#include " utils.h"
14
14
15
15
/*
16
- * 1 - Connect Rx/Tx of the desired Serial
17
- * 2 - Define UART_TEST_INSTANCE
18
- * ! Ensure Serial feature is enabled thanks 'U(S)ART support menu'!
19
- * 3 - Optionnal: comment unwanted speed in serialSpeed array.
20
- */
16
+ 1 - Connect Rx/Tx of the desired Serial
17
+ 2 - Define UART_TEST_INSTANCE
18
+ ! Ensure Serial feature is enabled thanks 'U(S)ART support menu'!
19
+ 3 - Optionnal: comment unwanted speed in serialSpeed array.
20
+ */
21
21
#define SERIAL_PORT_TESTED SerialTest
22
- #if defined(SERIAL_UART_INSTANCE) && (SERIAL_UART_INSTANCE != 1)
22
+ #if defined(SERIAL_UART_INSTANCE) && (SERIAL_UART_INSTANCE != 1) && defined(USART1_BASE)
23
23
#define UART_TEST_INSTANCE USART1
24
- #elif defined(USART2_BASE)
24
+ #elif defined(SERIAL_UART_INSTANCE) && (SERIAL_UART_INSTANCE != 2) && defined( USART2_BASE)
25
25
#define UART_TEST_INSTANCE USART2
26
26
#else
27
27
#define UART_TEST_INSTANCE LPUART1
@@ -40,23 +40,23 @@ struct serialTest_s {
40
40
41
41
static serialTest serialConfig[] = {
42
42
#ifdef UART_WORDLENGTH_7B
43
- DECL_CONFIG (SERIAL_7N1),
44
- DECL_CONFIG (SERIAL_7N2),
45
- DECL_CONFIG (SERIAL_6E1),
46
- DECL_CONFIG (SERIAL_6E2),
47
- DECL_CONFIG (SERIAL_6O1),
48
- DECL_CONFIG (SERIAL_6O2),
43
+ DECL_CONFIG (SERIAL_7N1),
44
+ DECL_CONFIG (SERIAL_7N2),
45
+ DECL_CONFIG (SERIAL_6E1),
46
+ DECL_CONFIG (SERIAL_6E2),
47
+ DECL_CONFIG (SERIAL_6O1),
48
+ DECL_CONFIG (SERIAL_6O2),
49
49
#endif
50
- DECL_CONFIG (SERIAL_8N1),
51
- DECL_CONFIG (SERIAL_8N2),
52
- DECL_CONFIG (SERIAL_7E1),
53
- DECL_CONFIG (SERIAL_8E1),
54
- DECL_CONFIG (SERIAL_7E2),
55
- DECL_CONFIG (SERIAL_7O1),
56
- DECL_CONFIG (SERIAL_8O1),
57
- DECL_CONFIG (SERIAL_7O2),
58
- DECL_CONFIG (SERIAL_8O2),
59
- DECL_CONFIG (SERIAL_8E2)
50
+ DECL_CONFIG (SERIAL_8N1),
51
+ DECL_CONFIG (SERIAL_8N2),
52
+ DECL_CONFIG (SERIAL_7E1),
53
+ DECL_CONFIG (SERIAL_8E1),
54
+ DECL_CONFIG (SERIAL_7E2),
55
+ DECL_CONFIG (SERIAL_7O1),
56
+ DECL_CONFIG (SERIAL_8O1),
57
+ DECL_CONFIG (SERIAL_7O2),
58
+ DECL_CONFIG (SERIAL_8O2),
59
+ DECL_CONFIG (SERIAL_8E2)
60
60
};
61
61
62
62
static uint32_t serialSpeed[] = {
@@ -79,14 +79,14 @@ static uint32_t serialSpeed[] = {
79
79
80
80
static uint32_t start_time = 0 ;
81
81
static uint32_t configCur = 0 ;
82
- static uint32_t configNb = sizeof (serialConfig)/ sizeof (serialTest);
83
- static uint32_t speedNb = sizeof (serialSpeed)/ sizeof (uint32_t );
82
+ static uint32_t configNb = sizeof (serialConfig) / sizeof (serialTest);
83
+ static uint32_t speedNb = sizeof (serialSpeed) / sizeof (uint32_t );
84
84
static uint32_t nbTestOK = 0 ;
85
85
static uint32_t nbTestKO = 0 ;
86
86
87
87
uint32_t dataMask (uint32_t config) {
88
88
uint32_t databits = 0 ;
89
- switch (config & 0x07 ) {
89
+ switch (config & 0x07 ) {
90
90
case 0x02 :
91
91
databits = 6 ;
92
92
break ;
@@ -108,32 +108,32 @@ void test_uart(int val)
108
108
int recval = 0 ;
109
109
SERIAL_PORT_TESTED.write (val);
110
110
delay (10 );
111
- while (SERIAL_PORT_TESTED.available ()){
111
+ while (SERIAL_PORT_TESTED.available ()) {
112
112
recval = SERIAL_PORT_TESTED.read ();
113
113
}
114
- if (val == recval) {
114
+ if (val == recval) {
115
115
nbTestOK++;
116
116
}
117
117
else {
118
118
SERIAL_PORT_MONITOR.print (" Send: 0x" );
119
- SERIAL_PORT_MONITOR.print (val,HEX);
119
+ SERIAL_PORT_MONITOR.print (val, HEX);
120
120
SERIAL_PORT_MONITOR.print (" \t Received: 0x" );
121
- SERIAL_PORT_MONITOR.print (recval,HEX);
121
+ SERIAL_PORT_MONITOR.print (recval, HEX);
122
122
SERIAL_PORT_MONITOR.println (" --> KO <--" );
123
123
nbTestKO++;
124
124
}
125
125
}
126
126
127
127
void setup () {
128
128
SERIAL_PORT_MONITOR.begin (115200 );
129
- while (!SERIAL_PORT_MONITOR);
129
+ while (!SERIAL_PORT_MONITOR);
130
130
SERIAL_PORT_MONITOR.print (" SerialLoop test on " );
131
131
SERIAL_PORT_MONITOR.println (XSTR (SERIAL_PORT_TESTED));
132
132
SERIAL_PORT_MONITOR.print (configNb);
133
133
SERIAL_PORT_MONITOR.println (" configs to test." );
134
134
SERIAL_PORT_MONITOR.print (speedNb);
135
135
SERIAL_PORT_MONITOR.println (" speed to test." );
136
- start_time= millis ();
136
+ start_time = millis ();
137
137
}
138
138
139
139
void loop () {
@@ -147,7 +147,7 @@ void loop() {
147
147
SERIAL_PORT_MONITOR.print (" Test duration (ms): " );
148
148
SERIAL_PORT_MONITOR.print (millis () - start_time);
149
149
150
- while (1 ); // End test
150
+ while (1 ); // End test
151
151
}
152
152
153
153
SERIAL_PORT_MONITOR.println (" ########################" );
@@ -156,19 +156,18 @@ void loop() {
156
156
SERIAL_PORT_MONITOR.print (" (0x" );
157
157
SERIAL_PORT_MONITOR.print (serialConfig[configCur].config , HEX);
158
158
SERIAL_PORT_MONITOR.println (" )" );
159
- for (uint32_t s= 0 ; s< speedNb; s++) {
159
+ for (uint32_t s = 0 ; s < speedNb; s++) {
160
160
SERIAL_PORT_MONITOR.print (" Test at " );
161
161
SERIAL_PORT_MONITOR.print (serialSpeed[s]);
162
162
SERIAL_PORT_MONITOR.println (" baud" );
163
- SERIAL_PORT_TESTED.begin (serialSpeed[s],serialConfig[configCur].config );
163
+ SERIAL_PORT_TESTED.begin (serialSpeed[s], serialConfig[configCur].config );
164
164
mask = dataMask (serialConfig[configCur].config );
165
- for (uint32_t i= 0 ; i<= (0xFF & mask); i++)
165
+ for (uint32_t i = 0 ; i <= (0xFF & mask); i++)
166
166
{
167
- test_uart (i& mask);
167
+ test_uart (i & mask);
168
168
}
169
169
SERIAL_PORT_TESTED.end ();
170
170
}
171
171
SERIAL_PORT_MONITOR.println (" End." );
172
172
configCur++;
173
173
}
174
-
0 commit comments