Skip to content

Commit

Permalink
feat: add uart pin swap configuration option when supported (#296)
Browse files Browse the repository at this point in the history
  • Loading branch information
daantimmer authored Apr 17, 2024
1 parent 66f95b6 commit 0826e3b
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 0 deletions.
12 changes: 12 additions & 0 deletions hal_st/stm32fxxx/UartStm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ namespace hal
uartHandle.Init.OverSampling = UART_OVERSAMPLING_8;
#endif

#if defined(UART_ADVFEATURE_NO_INIT)
uartHandle.AdvancedInit = {};

#if defined(UART_ADVFEATURE_SWAP_INIT)
if (config.swapTxRx)
{
uartHandle.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_SWAP_INIT;
uartHandle.AdvancedInit.Swap = UART_ADVFEATURE_SWAP_ENABLE;
}
#endif
#endif

HAL_UART_Init(&uartHandle);

#if defined(STM32WB)
Expand Down
4 changes: 4 additions & 0 deletions hal_st/stm32fxxx/UartStm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ namespace hal
uint32_t baudrate{ 115200 };
uint32_t parity{ USART_PARITY_NONE };
InterruptPriority priority{ InterruptPriority::Normal };

#if defined(UART_ADVFEATURE_SWAP_INIT)
bool swapTxRx{ false };
#endif
};
}

Expand Down
13 changes: 13 additions & 0 deletions hal_st/stm32fxxx/UartStmDma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ namespace hal
#else
uartHandle.Init.OverSampling = UART_OVERSAMPLING_8;
#endif

#if defined(UART_ADVFEATURE_NO_INIT)
uartHandle.AdvancedInit = {};

#if defined(UART_ADVFEATURE_SWAP_INIT)
if (config.swapTxRx)
{
uartHandle.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_SWAP_INIT;
uartHandle.AdvancedInit.Swap = UART_ADVFEATURE_SWAP_ENABLE;
}
#endif
#endif

HAL_UART_Init(&uartHandle);

peripheralUart[uartIndex]->CR2 &= ~USART_CLOCK_ENABLED;
Expand Down
5 changes: 5 additions & 0 deletions hal_st/stm32fxxx/UartStmDma.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "hal_st/stm32fxxx/DmaStm.hpp"
#include "hal_st/stm32fxxx/GpioStm.hpp"
#include <cstdint>

#include DEVICE_HEADER

namespace hal
Expand All @@ -19,6 +20,10 @@ namespace hal
uint32_t parity{ USART_PARITY_NONE };

hal::InterruptPriority priority{ hal::InterruptPriority::Normal };

#if defined(UART_ADVFEATURE_SWAP_INIT)
bool swapTxRx{ false };
#endif
};
}

Expand Down
12 changes: 12 additions & 0 deletions hal_st/stm32fxxx/UartStmDuplexDma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ namespace hal
uartHandle.Init.OverSampling = UART_OVERSAMPLING_16;
uartHandle.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_ENABLE;

#if defined(UART_ADVFEATURE_NO_INIT)
uartHandle.AdvancedInit = {};

#if defined(UART_ADVFEATURE_SWAP_INIT)
if (config.swapTxRx)
{
uartHandle.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_SWAP_INIT;
uartHandle.AdvancedInit.Swap = UART_ADVFEATURE_SWAP_ENABLE;
}
#endif
#endif

HAL_UART_Init(&uartHandle);

#if defined(STM32WB)
Expand Down
6 changes: 6 additions & 0 deletions hal_st/stm32fxxx/UartStmDuplexDma.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <atomic>
#include <cstdint>

#include DEVICE_HEADER

namespace hal
{
namespace detail
Expand All @@ -16,6 +18,10 @@ namespace hal
{
uint32_t baudrate{ 115200 };
hal::InterruptPriority priority{ hal::InterruptPriority::Normal };

#if defined(UART_ADVFEATURE_SWAP_INIT)
bool swapTxRx{ false };
#endif
};
}

Expand Down

0 comments on commit 0826e3b

Please sign in to comment.