@@ -629,11 +629,7 @@ app_uart_comm_params_t m_uart_comm_params =
629
629
.cts_pin_no = 0 ,
630
630
.flow_control = APP_UART_FLOW_CONTROL_DISABLED ,
631
631
.use_parity = false,
632
- #if defined (UART_PRESENT )
633
- .baud_rate = NRF_UART_BAUDRATE_115200
634
- #else
635
632
.baud_rate = NRF_UARTE_BAUDRATE_115200
636
- #endif
637
633
};
638
634
gps_uart_comm_params_t m_gpsuart_comm_params =
639
635
{
@@ -1237,13 +1233,38 @@ static void uart_init(void) {
1237
1233
APP_ERROR_CHECK (err_code );
1238
1234
}
1239
1235
1236
+ enum {
1237
+ PIN_STATE_DEFAULT ,
1238
+ PIN_STATE_XENITH ,
1239
+ PIN_STATE_REVERSED ,
1240
+ };
1241
+ #define PIN_STATES 3
1240
1242
static void uart_swap_pins (void ) {
1241
-
1243
+ static int pin_swap_state = PIN_STATE_DEFAULT ;
1242
1244
app_uart_close ();
1243
1245
1244
- uint32_t old_rx_pin = m_uart_comm_params .rx_pin_no ;
1245
- m_uart_comm_params .rx_pin_no = m_uart_comm_params .tx_pin_no ;
1246
- m_uart_comm_params .tx_pin_no = old_rx_pin ;
1246
+ if (++ pin_swap_state == PIN_STATES ) {
1247
+ pin_swap_state = PIN_STATE_DEFAULT ;
1248
+ }
1249
+
1250
+ switch (pin_swap_state )
1251
+ {
1252
+ case PIN_STATE_DEFAULT :
1253
+ m_uart_comm_params .baud_rate = NRF_UARTE_BAUDRATE_115200 ;
1254
+ m_uart_comm_params .rx_pin_no = UART_RX ;
1255
+ m_uart_comm_params .tx_pin_no = UART_TX ;
1256
+ break ;
1257
+ case PIN_STATE_XENITH :
1258
+ m_uart_comm_params .baud_rate = NRF_UARTE_BAUDRATE_250000 ;
1259
+ m_uart_comm_params .rx_pin_no = UART_RX ;
1260
+ m_uart_comm_params .tx_pin_no = UART_TX ;
1261
+ break ;
1262
+ case PIN_STATE_REVERSED :
1263
+ m_uart_comm_params .baud_rate = NRF_UARTE_BAUDRATE_115200 ;
1264
+ m_uart_comm_params .rx_pin_no = UART_TX ;
1265
+ m_uart_comm_params .tx_pin_no = UART_RX ;
1266
+ break ;
1267
+ }
1247
1268
1248
1269
packet_reset (PACKET_VESC );
1249
1270
uart_init ();
@@ -1807,10 +1828,10 @@ static void logging_timer_handler(void *p_context) {
1807
1828
NRF_LOG_FLUSH ();
1808
1829
}
1809
1830
1810
- // Check if the ESC has not responded in 3 seconds and try swapping the TX and RX pins
1811
- if (currentTime - time_esc_last_responded > 3 )
1831
+ // Check if the ESC has not responded in 1 second and try swapping the UART pin configuration
1832
+ if (currentTime - time_esc_last_responded > 1 )
1812
1833
{
1813
- NRF_LOG_INFO ("ESC has not responded in 3 seconds. Swapping UART TX and RX pins " );
1834
+ NRF_LOG_INFO ("ESC has not responded in > 1 second. Trying next UART configuration. " );
1814
1835
NRF_LOG_FLUSH ();
1815
1836
uart_swap_pins ();
1816
1837
// Reset the countdown
0 commit comments