Skip to content

reorder uart initialization before pin configuration #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 2, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 22 additions & 23 deletions cores/arduino/ard_sup/uart/ap3_uart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,28 @@ ap3_err_t Uart::_begin(void)
_config.ui32RxBufferSize = sizeof(_rx_linbuff);
_config.ui32TxBufferSize = sizeof(_tx_linbuff);

//User may want to change settings mid-sketch. Only init UART if it's new.
if (_handle == NULL)
{
retval = (ap3_err_t)am_hal_uart_initialize(_instance, &_handle);
if (retval != AP3_OK)
{
return ap3_return(retval);
}
}
retval = (ap3_err_t)am_hal_uart_power_control(_handle, AM_HAL_SYSCTRL_WAKE, false);
if (retval != AP3_OK)
{
return ap3_return(retval);
}
retval = (ap3_err_t)am_hal_uart_configure(_handle, &_config);
if (retval != AP3_OK)
{
return ap3_return(retval);
}

UARTn(_instance)->LCRH_b.FEN = 0; // Disable that pesky FIFO

// Check for a valid instance
// Check pins for compatibility with the selcted instance

Expand Down Expand Up @@ -383,29 +405,6 @@ ap3_err_t Uart::_begin(void)
pincfg = AP3_GPIO_DEFAULT_PINCFG; // set back to default for use with next pin
}

//User may want to change settings mid-sketch. Only init UART if it's new.
if (_handle == NULL)
{
// Now that pins are initialized start the actual driver
retval = (ap3_err_t)am_hal_uart_initialize(_instance, &_handle);
if (retval != AP3_OK)
{
return ap3_return(retval);
}
}
retval = (ap3_err_t)am_hal_uart_power_control(_handle, AM_HAL_SYSCTRL_WAKE, false);
if (retval != AP3_OK)
{
return ap3_return(retval);
}
retval = (ap3_err_t)am_hal_uart_configure(_handle, &_config);
if (retval != AP3_OK)
{
return ap3_return(retval);
}

UARTn(_instance)->LCRH_b.FEN = 0; // Disable that pesky FIFO

// Enable TX and RX interrupts
NVIC_EnableIRQ((IRQn_Type)(UART0_IRQn + _instance));
am_hal_uart_interrupt_enable(_handle, (AM_HAL_UART_INT_RX | AM_HAL_UART_INT_TX));
Expand Down