Skip to content

Commit 6c601c0

Browse files
committed
Support 250k baud for Xenith module
1 parent e597072 commit 6c601c0

File tree

1 file changed

+32
-11
lines changed

1 file changed

+32
-11
lines changed

main.c

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -629,11 +629,7 @@ app_uart_comm_params_t m_uart_comm_params =
629629
.cts_pin_no = 0,
630630
.flow_control = APP_UART_FLOW_CONTROL_DISABLED,
631631
.use_parity = false,
632-
#if defined (UART_PRESENT)
633-
.baud_rate = NRF_UART_BAUDRATE_115200
634-
#else
635632
.baud_rate = NRF_UARTE_BAUDRATE_115200
636-
#endif
637633
};
638634
gps_uart_comm_params_t m_gpsuart_comm_params =
639635
{
@@ -1237,13 +1233,38 @@ static void uart_init(void) {
12371233
APP_ERROR_CHECK(err_code);
12381234
}
12391235

1236+
enum {
1237+
PIN_STATE_DEFAULT,
1238+
PIN_STATE_XENITH,
1239+
PIN_STATE_REVERSED,
1240+
};
1241+
#define PIN_STATES 3
12401242
static void uart_swap_pins(void) {
1241-
1243+
static int pin_swap_state = PIN_STATE_DEFAULT;
12421244
app_uart_close();
12431245

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+
}
12471268

12481269
packet_reset(PACKET_VESC);
12491270
uart_init();
@@ -1807,10 +1828,10 @@ static void logging_timer_handler(void *p_context) {
18071828
NRF_LOG_FLUSH();
18081829
}
18091830

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)
18121833
{
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.");
18141835
NRF_LOG_FLUSH();
18151836
uart_swap_pins();
18161837
// Reset the countdown

0 commit comments

Comments
 (0)