File tree Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -384,8 +384,32 @@ void serial_baud(serial_t *obj, int baudrate)
384
384
385
385
obj_s -> baudrate = baudrate ;
386
386
if (init_uart (obj ) != HAL_OK ) {
387
- debug ("Cannot initialize UART with baud rate %u\n" , baudrate );
387
+
388
+ #if defined(LPUART1_BASE )
388
389
/* Note that LPUART clock source must be in the range [3 x baud rate, 4096 x baud rate], check Ref Manual */
390
+ if (obj_s -> uart == LPUART_1 ) {
391
+ /* Try to change LPUART clock source */
392
+ RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0 };
393
+ if (baudrate == 9600 ) {
394
+ PeriphClkInitStruct .PeriphClockSelection = RCC_PERIPHCLK_LPUART1 ;
395
+ PeriphClkInitStruct .Lpuart1ClockSelection = RCC_LPUART1CLKSOURCE_LSE ;
396
+ HAL_RCCEx_PeriphCLKConfig (& PeriphClkInitStruct );
397
+ if (init_uart (obj ) == HAL_OK ){
398
+ return ;
399
+ }
400
+ }
401
+ else {
402
+ PeriphClkInitStruct .PeriphClockSelection = RCC_PERIPHCLK_LPUART1 ;
403
+ PeriphClkInitStruct .Lpuart1ClockSelection = RCC_LPUART1CLKSOURCE_SYSCLK ;
404
+ HAL_RCCEx_PeriphCLKConfig (& PeriphClkInitStruct );
405
+ if (init_uart (obj ) == HAL_OK ){
406
+ return ;
407
+ }
408
+ }
409
+ }
410
+ #endif /* LPUART1_BASE */
411
+
412
+ debug ("Cannot initialize UART with baud rate %u\n" , baudrate );
389
413
}
390
414
}
391
415
You can’t perform that action at this time.
0 commit comments