Skip to content

[U(S)ART] hardening #1255

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 3 commits into from
Dec 4, 2020
Merged
Show file tree
Hide file tree
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
18 changes: 14 additions & 4 deletions cores/arduino/HardwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@
#endif

#if defined(HAVE_HWSERIAL10)
HardwareSerial Serial10(UART10);
#if defined(USART10)
HardwareSerial Serial10(USART10);
#else
HardwareSerial Serial10(UART10);
#endif
void serialEvent10() __attribute__((weak));
#endif

Expand Down Expand Up @@ -218,16 +222,22 @@ HardwareSerial::HardwareSerial(void *peripheral, HalfDuplexMode_t halfDuplex)
setTx(PIN_SERIAL8_TX);
} else
#endif
#if defined(PIN_SERIAL9_TX) && defined(UART9)
#if defined(PIN_SERIAL9_TX) && defined(UART9_BASE)
if (peripheral == UART9) {
#if defined(PIN_SERIAL9_RX)
setRx(PIN_SERIAL9_RX);
#endif
setTx(PIN_SERIAL9_TX);
} else
#endif
#if defined(PIN_SERIAL10_TX) && defined(UART10)
if (peripheral == UART10) {
#if defined(PIN_SERIAL10_TX) &&\
(defined(USART10_BASE) || defined(UART10_BASE))
#if defined(USART10_BASE)
if (peripheral == USART10)
#elif defined(UART10_BASE)
if (peripheral == UART10)
#endif
{
#if defined(PIN_SERIAL10_RX)
setRx(PIN_SERIAL10_RX);
#endif
Expand Down
44 changes: 33 additions & 11 deletions cores/arduino/HardwareSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,38 @@ class HardwareSerial : public Stream {
void configForLowPower(void);
};

extern HardwareSerial Serial1;
extern HardwareSerial Serial2;
extern HardwareSerial Serial3;
extern HardwareSerial Serial4;
extern HardwareSerial Serial5;
extern HardwareSerial Serial6;
extern HardwareSerial Serial7;
extern HardwareSerial Serial8;
extern HardwareSerial Serial9;
extern HardwareSerial Serial10;
extern HardwareSerial SerialLP1;
#if defined(USART1)
extern HardwareSerial Serial1;
#endif
#if defined(USART2)
extern HardwareSerial Serial2;
#endif
#if defined(USART3)
extern HardwareSerial Serial3;
#endif
#if defined(UART4) || defined(USART4)
extern HardwareSerial Serial4;
#endif
#if defined(UART5) || defined(USART5)
extern HardwareSerial Serial5;
#endif
#if defined(USART6)
extern HardwareSerial Serial6;
#endif
#if defined(UART7) || defined(USART7)
extern HardwareSerial Serial7;
#endif
#if defined(UART8) || defined(USART8)
extern HardwareSerial Serial8;
#endif
#if defined(UART9)
extern HardwareSerial Serial9;
#endif
#if defined(UART10) || defined(USART10)
extern HardwareSerial Serial10;
#endif
#if defined(LPUART1)
extern HardwareSerial SerialLP1;
#endif

#endif
2 changes: 1 addition & 1 deletion cores/arduino/WSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ WEAK void serialEventRun(void)
}
#endif
#if defined(HAVE_HWSERIAL10)
if (serialEventl10 && Serial10.available()) {
if (serialEvent10 && Serial10.available()) {
serialEvent10();
}
#endif
Expand Down
48 changes: 35 additions & 13 deletions cores/arduino/WSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

#if defined(HAL_UART_MODULE_ENABLED) && !defined(HAL_UART_MODULE_ONLY)
#if !defined(HWSERIAL_NONE) && defined(SERIAL_UART_INSTANCE)
#if SERIAL_UART_INSTANCE == 0
#if SERIAL_UART_INSTANCE == 0 || SERIAL_UART_INSTANCE == 101
#define ENABLE_HWSERIALLP1
#if !defined(Serial)
#define Serial SerialLP1
Expand Down Expand Up @@ -164,22 +164,44 @@
#endif
#endif
#if defined(ENABLE_HWSERIAL10)
#if defined(UART10_BASE)
#if defined(USART10_BASE) || defined(UART10_BASE)
#define HAVE_HWSERIAL10
#endif
#endif

extern void serialEvent1(void) __attribute__((weak));
extern void serialEvent2(void) __attribute__((weak));
extern void serialEvent3(void) __attribute__((weak));
extern void serialEvent4(void) __attribute__((weak));
extern void serialEvent5(void) __attribute__((weak));
extern void serialEvent6(void) __attribute__((weak));
extern void serialEvent7(void) __attribute__((weak));
extern void serialEvent8(void) __attribute__((weak));
extern void serialEvent9(void) __attribute__((weak));
extern void serialEvent10(void) __attribute__((weak));
extern void serialEventLP1(void) __attribute__((weak));
#if defined(HAVE_HWSERIAL1)
extern void serialEvent1(void) __attribute__((weak));
#endif
#if defined(HAVE_HWSERIAL2)
extern void serialEvent2(void) __attribute__((weak));
#endif
#if defined(HAVE_HWSERIAL3)
extern void serialEvent3(void) __attribute__((weak));
#endif
#if defined(HAVE_HWSERIAL4)
extern void serialEvent4(void) __attribute__((weak));
#endif
#if defined(HAVE_HWSERIAL5)
extern void serialEvent5(void) __attribute__((weak));
#endif
#if defined(HAVE_HWSERIAL6)
extern void serialEvent6(void) __attribute__((weak));
#endif
#if defined(HAVE_HWSERIAL7)
extern void serialEvent7(void) __attribute__((weak));
#endif
#if defined(HAVE_HWSERIAL8)
extern void serialEvent8(void) __attribute__((weak));
#endif
#if defined(HAVE_HWSERIAL9)
extern void serialEvent9(void) __attribute__((weak));
#endif
#if defined(HAVE_HWSERIAL10)
extern void serialEvent10(void) __attribute__((weak));
#endif
#if defined(HAVE_HWSERIALLP1)
extern void serialEventLP1(void) __attribute__((weak));
#endif
#endif /* HAL_UART_MODULE_ENABLED && !HAL_UART_MODULE_ONLY */

extern void serialEventRun(void);
Expand Down
1 change: 1 addition & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,7 @@ USART7 LITERAL1
UART8 LITERAL1
UART9 LITERAL1
UART10 LITERAL1
USART10 LITERAL1
LPUART1 LITERAL1

# Port
Expand Down
31 changes: 30 additions & 1 deletion libraries/SrcWrapper/src/stm32/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ typedef enum {
#if defined(UART9_BASE)
UART9_INDEX,
#endif
#if defined(UART10_BASE)
#if defined(UART10_BASE) || defined(USART10_BASE)
UART10_INDEX,
#endif
#if defined(LPUART1_BASE)
Expand Down Expand Up @@ -284,6 +284,15 @@ void uart_init(serial_t *obj, uint32_t baudrate, uint32_t databits, uint32_t par
obj->irq = UART10_IRQn;
}
#endif
#if defined(USART10_BASE)
else if (obj->uart == USART10) {
__HAL_RCC_USART10_FORCE_RESET();
__HAL_RCC_USART10_RELEASE_RESET();
__HAL_RCC_USART10_CLK_ENABLE();
obj->index = UART10_INDEX;
obj->irq = USART10_IRQn;
}
#endif

#if defined(STM32F091xC) || defined (STM32F098xx)
/* Enable SYSCFG Clock */
Expand Down Expand Up @@ -487,6 +496,13 @@ void uart_deinit(serial_t *obj)
__HAL_RCC_UART10_RELEASE_RESET();
__HAL_RCC_UART10_CLK_DISABLE();
break;
#endif
#if defined(USART10_BASE)
case UART10_INDEX:
__HAL_RCC_USART10_FORCE_RESET();
__HAL_RCC_USART10_RELEASE_RESET();
__HAL_RCC_USART10_CLK_DISABLE();
break;
#endif
}

Expand Down Expand Up @@ -1062,6 +1078,19 @@ void UART10_IRQHandler(void)
}
#endif

/**
* @brief USART 10 IRQ handler
* @param None
* @retval None
*/
#if defined(USART10_BASE)
void USART10_IRQHandler(void)
{
HAL_NVIC_ClearPendingIRQ(USART10_IRQn);
HAL_UART_IRQHandler(uart_handlers[UART10_INDEX]);
}
#endif

/**
* @brief HAL UART Call Back
* @param UART handler
Expand Down