Skip to content

Commit

Permalink
fix(hal_st/stm32fxxx/UartStm & UartDma): registers for stm32f407 (#59)
Browse files Browse the repository at this point in the history
hal_st/stm32fxxx/UartStm and UartStmDma: Fix for STM3F407

Co-authored-by: Ron <45816308+rjaegers@users.noreply.github.com>
  • Loading branch information
richardapeters and rjaegers authored Jan 23, 2023
1 parent 714d922 commit 98ceaf3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
20 changes: 20 additions & 0 deletions hal_st/stm32fxxx/UartStm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,19 @@ namespace hal

void UartStm::Invoke()
{
#if defined(STM32F0) || defined(STM32F3) || defined(STM32F7) || defined(STM32WB)
if (peripheralUart[uartIndex]->ISR & USART_ISR_RXNE)
#else
if (peripheralUart[uartIndex]->SR & USART_SR_RXNE)
#endif
{
infra::BoundedVector<uint8_t>::WithMaxSize<8> buffer;

#if defined(STM32F0) || defined(STM32F3) || defined(STM32F7) || defined(STM32WB)
while (!buffer.full() && (peripheralUart[uartIndex]->ISR & USART_ISR_RXNE))
#else
while (!buffer.full() && (peripheralUart[uartIndex]->SR & USART_SR_RXNE))
#endif
{
uint8_t receivedByte =
#if defined(STM32F0) || defined(STM32F3) || defined(STM32F7) || defined(STM32WB)
Expand All @@ -100,15 +108,23 @@ namespace hal
}

// If buffer is empty then interrupt was raised by Overrun Error (ORE) and we miss data.
#if defined(STM32F0) || defined(STM32F3) || defined(STM32F7) || defined(STM32WB)
really_assert(!(buffer.empty() && peripheralUart[uartIndex]->ISR & USART_ISR_ORE));
#else
really_assert(!(buffer.empty() && peripheralUart[uartIndex]->SR & USART_SR_ORE));
#endif

if (dataReceived != nullptr)
dataReceived(buffer.range());
}

if (sending)
{
#if defined(STM32F0) || defined(STM32F3) || defined(STM32F7) || defined(STM32WB)
while (!sendData.empty() && (peripheralUart[uartIndex]->ISR & USART_ISR_TXE))
#else
while (!sendData.empty() && (peripheralUart[uartIndex]->SR & USART_SR_TXE))
#endif
{
#if defined(STM32F0) || defined(STM32F3) || defined(STM32F7) || defined(STM32WB)
peripheralUart[uartIndex]->TDR = sendData.front();
Expand All @@ -121,7 +137,11 @@ namespace hal
if (sendData.empty())
{
TransferComplete();
#if defined(STM32F0) || defined(STM32F1) || defined(STM32F3) || defined(STM32F7) || defined(STM32WB)
peripheralUart[uartIndex]->CR1 &= ~(1 << (USART_IT_TXE & USART_IT_MASK));
#else
peripheralUart[uartIndex]->CR1 &= ~(USART_IT_TXE & USART_IT_MASK);
#endif
sending = false;
}
}
Expand Down
15 changes: 10 additions & 5 deletions hal_st/stm32fxxx/UartStmDma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,11 @@ namespace hal
{
infra::BoundedVector<uint8_t>::WithMaxSize<8> buffer;

const uint32_t ISR_RXNE = 0x20U;
const uint32_t ISR_ORE = 0x8U;

while (peripheralUart[uartIndex]->ISR & ISR_RXNE)
#if defined(STM32F0) || defined(STM32F3) || defined(STM32F7) || defined(STM32WB)
while (peripheralUart[uartIndex]->ISR & USART_ISR_RXNE)
#else
while (peripheralUart[uartIndex]->SR & USART_SR_RXNE)
#endif
{
uint8_t receivedByte =
#if defined(STM32F0) || defined(STM32F3) || defined(STM32F7) || defined(STM32WB)
Expand All @@ -152,7 +153,11 @@ namespace hal
}

// If buffer is empty then interrupt was raised by Overrun Error (ORE) and we miss data.
really_assert(!(buffer.empty() && peripheralUart[uartIndex]->ISR & ISR_ORE));
#if defined(STM32F0) || defined(STM32F3) || defined(STM32F7) || defined(STM32WB)
really_assert(!(buffer.empty() && peripheralUart[uartIndex]->ISR & USART_ISR_ORE));
#else
really_assert(!(buffer.empty() && peripheralUart[uartIndex]->SR & USART_SR_ORE));
#endif

if (dataReceived != nullptr)
dataReceived(buffer.range());
Expand Down

0 comments on commit 98ceaf3

Please sign in to comment.