Skip to content

Commit 3ac2d06

Browse files
dhylandsdpgeorge
authored andcommitted
stmhal: Add support for UART5
I tested this on my CERB40 board and it seems to be working fine.
1 parent 18fda7b commit 3ac2d06

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

stmhal/boards/CERB40/mpconfigboard.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
#define MICROPY_HW_UART3_CTS (GPIO_PIN_11)
3939
#define MICROPY_HW_UART4_PORT (GPIOA)
4040
#define MICROPY_HW_UART4_PINS (GPIO_PIN_0 | GPIO_PIN_1)
41+
#define MICROPY_HW_UART5_TX_PORT (GPIOC)
42+
#define MICROPY_HW_UART5_TX_PIN (GPIO_PIN_12)
43+
#define MICROPY_HW_UART5_RX_PORT (GPIOD)
44+
#define MICROPY_HW_UART5_RX_PIN (GPIO_PIN_2)
4145
#define MICROPY_HW_UART6_PORT (GPIOC)
4246
#define MICROPY_HW_UART6_PINS (GPIO_PIN_6 | GPIO_PIN_7)
4347

stmhal/stm32f4xx_it.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,10 @@ void UART4_IRQHandler(void) {
413413
uart_irq_handler(4);
414414
}
415415

416+
void UART5_IRQHandler(void) {
417+
uart_irq_handler(5);
418+
}
419+
416420
void USART6_IRQHandler(void) {
417421
uart_irq_handler(6);
418422
}

stmhal/uart.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,31 @@ STATIC bool uart_init2(pyb_uart_obj_t *uart_obj) {
185185
break;
186186
#endif
187187

188+
#if defined(UART5) && \
189+
defined(MICROPY_HW_UART5_TX_PORT) && \
190+
defined(MICROPY_HW_UART5_TX_PIN) && \
191+
defined(MICROPY_HW_UART5_RX_PORT) && \
192+
defined(MICROPY_HW_UART5_RX_PIN)
193+
case PYB_UART_5:
194+
UARTx = UART5;
195+
irqn = UART5_IRQn;
196+
GPIO_AF_UARTx = GPIO_AF8_UART5;
197+
GPIO_Port = MICROPY_HW_UART5_TX_PORT;
198+
GPIO_Pin = MICROPY_HW_UART5_TX_PIN;
199+
__UART5_CLK_ENABLE();
200+
201+
// The code after the case only deals with the case where the TX & RX
202+
// pins are on the same port. UART5 has them on different ports.
203+
GPIO_InitTypeDef GPIO_InitStructure;
204+
GPIO_InitStructure.Pin = MICROPY_HW_UART5_RX_PIN;
205+
GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
206+
GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
207+
GPIO_InitStructure.Pull = GPIO_PULLUP;
208+
GPIO_InitStructure.Alternate = GPIO_AF_UARTx;
209+
HAL_GPIO_Init(MICROPY_HW_UART5_RX_PORT, &GPIO_InitStructure);
210+
break;
211+
#endif
212+
188213
#if defined(MICROPY_HW_UART6_PORT) && defined(MICROPY_HW_UART6_PINS)
189214
// USART6 is on PC6/PC7 (CK on PC8)
190215
case PYB_UART_6:
@@ -596,6 +621,13 @@ STATIC mp_obj_t pyb_uart_deinit(mp_obj_t self_in) {
596621
__UART4_RELEASE_RESET();
597622
__UART4_CLK_DISABLE();
598623
#endif
624+
#if defined(UART5)
625+
} else if (uart->Instance == UART5) {
626+
HAL_NVIC_DisableIRQ(UART5_IRQn);
627+
__UART5_FORCE_RESET();
628+
__UART5_RELEASE_RESET();
629+
__UART5_CLK_DISABLE();
630+
#endif
599631
} else if (uart->Instance == USART6) {
600632
HAL_NVIC_DisableIRQ(USART6_IRQn);
601633
__USART6_FORCE_RESET();

0 commit comments

Comments
 (0)