@@ -150,7 +150,6 @@ STATIC bool uart_init2(pyb_uart_obj_t *uart_obj) {
150150 #endif
151151
152152 #if defined(MICROPY_HW_UART2_PORT ) && defined(MICROPY_HW_UART2_PINS )
153- // USART2 is on PA2/PA3 (CTS,RTS,CK on PA0,PA1,PA4), PD5/PD6 (CK on PD7)
154153 case PYB_UART_2 :
155154 UARTx = USART2 ;
156155 irqn = USART2_IRQn ;
@@ -327,7 +326,7 @@ int uart_rx_char(pyb_uart_obj_t *self) {
327326 return data ;
328327 } else {
329328 // no buffering
330- #if defined(MCU_SERIES_F7 )
329+ #if defined(MCU_SERIES_F7 ) || defined( MCU_SERIES_L4 )
331330 return self -> uart .Instance -> RDR & self -> char_mask ;
332331 #else
333332 return self -> uart .Instance -> DR & self -> char_mask ;
@@ -398,7 +397,7 @@ void uart_irq_handler(mp_uint_t uart_id) {
398397 uint16_t next_head = (self -> read_buf_head + 1 ) % self -> read_buf_len ;
399398 if (next_head != self -> read_buf_tail ) {
400399 // only read data if room in buf
401- #if defined(MCU_SERIES_F7 )
400+ #if defined(MCU_SERIES_F7 ) || defined( MCU_SERIES_L4 )
402401 int data = self -> uart .Instance -> RDR ; // clears UART_FLAG_RXNE
403402 #else
404403 int data = self -> uart .Instance -> DR ; // clears UART_FLAG_RXNE
@@ -571,12 +570,20 @@ STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, mp_uint_t n_args, con
571570 // compute actual baudrate that was configured
572571 // (this formula assumes UART_OVERSAMPLING_16)
573572 uint32_t actual_baudrate ;
574- if (self -> uart .Instance == USART1 || self -> uart .Instance == USART6 ) {
573+ if (self -> uart .Instance == USART1
574+ #if defined(USART6 )
575+ || self -> uart .Instance == USART6
576+ #endif
577+ ) {
575578 actual_baudrate = HAL_RCC_GetPCLK2Freq ();
576579 } else {
577580 actual_baudrate = HAL_RCC_GetPCLK1Freq ();
578581 }
582+ #if defined(MCU_SERIES_L4 )
583+ actual_baudrate = (actual_baudrate << 5 ) / (self -> uart .Instance -> BRR >> 3 );
584+ #else
579585 actual_baudrate /= self -> uart .Instance -> BRR ;
586+ #endif
580587
581588 // check we could set the baudrate within 5%
582589 uint32_t baudrate_diff ;
@@ -716,11 +723,13 @@ STATIC mp_obj_t pyb_uart_deinit(mp_obj_t self_in) {
716723 __UART5_RELEASE_RESET ();
717724 __UART5_CLK_DISABLE ();
718725 #endif
726+ #if defined(UART6 )
719727 } else if (uart -> Instance == USART6 ) {
720728 HAL_NVIC_DisableIRQ (USART6_IRQn );
721729 __USART6_FORCE_RESET ();
722730 __USART6_RELEASE_RESET ();
723731 __USART6_CLK_DISABLE ();
732+ #endif
724733 }
725734 return mp_const_none ;
726735}
@@ -776,7 +785,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_uart_readchar_obj, pyb_uart_readchar);
776785// uart.sendbreak()
777786STATIC mp_obj_t pyb_uart_sendbreak (mp_obj_t self_in ) {
778787 pyb_uart_obj_t * self = self_in ;
779- #if defined(MCU_SERIES_F7 )
788+ #if defined(MCU_SERIES_F7 ) || defined( MCU_SERIES_L4 )
780789 self -> uart .Instance -> RQR = USART_RQR_SBKRQ ; // write-only register
781790 #else
782791 self -> uart .Instance -> CR1 |= USART_CR1_SBK ;
0 commit comments