Skip to content

Commit 7804f01

Browse files
author
Owen L - SFE
committed
reorder uart initialization before pin configuration
1 parent c0308f6 commit 7804f01

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

cores/arduino/ard_sup/uart/ap3_uart.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,29 @@ ap3_err_t Uart::_begin(void)
311311
_config.ui32RxBufferSize = sizeof(_rx_linbuff);
312312
_config.ui32TxBufferSize = sizeof(_tx_linbuff);
313313

314+
//User may want to change settings mid-sketch. Only init UART if it's new.
315+
if (_handle == NULL)
316+
{
317+
// Now that pins are initialized start the actual driver
318+
retval = (ap3_err_t)am_hal_uart_initialize(_instance, &_handle);
319+
if (retval != AP3_OK)
320+
{
321+
return ap3_return(retval);
322+
}
323+
}
324+
retval = (ap3_err_t)am_hal_uart_power_control(_handle, AM_HAL_SYSCTRL_WAKE, false);
325+
if (retval != AP3_OK)
326+
{
327+
return ap3_return(retval);
328+
}
329+
retval = (ap3_err_t)am_hal_uart_configure(_handle, &_config);
330+
if (retval != AP3_OK)
331+
{
332+
return ap3_return(retval);
333+
}
334+
335+
UARTn(_instance)->LCRH_b.FEN = 0; // Disable that pesky FIFO
336+
314337
// Check for a valid instance
315338
// Check pins for compatibility with the selcted instance
316339

@@ -383,29 +406,6 @@ ap3_err_t Uart::_begin(void)
383406
pincfg = AP3_GPIO_DEFAULT_PINCFG; // set back to default for use with next pin
384407
}
385408

386-
//User may want to change settings mid-sketch. Only init UART if it's new.
387-
if (_handle == NULL)
388-
{
389-
// Now that pins are initialized start the actual driver
390-
retval = (ap3_err_t)am_hal_uart_initialize(_instance, &_handle);
391-
if (retval != AP3_OK)
392-
{
393-
return ap3_return(retval);
394-
}
395-
}
396-
retval = (ap3_err_t)am_hal_uart_power_control(_handle, AM_HAL_SYSCTRL_WAKE, false);
397-
if (retval != AP3_OK)
398-
{
399-
return ap3_return(retval);
400-
}
401-
retval = (ap3_err_t)am_hal_uart_configure(_handle, &_config);
402-
if (retval != AP3_OK)
403-
{
404-
return ap3_return(retval);
405-
}
406-
407-
UARTn(_instance)->LCRH_b.FEN = 0; // Disable that pesky FIFO
408-
409409
// Enable TX and RX interrupts
410410
NVIC_EnableIRQ((IRQn_Type)(UART0_IRQn + _instance));
411411
am_hal_uart_interrupt_enable(_handle, (AM_HAL_UART_INT_RX | AM_HAL_UART_INT_TX));

0 commit comments

Comments
 (0)