Skip to content

Commit 03f46c6

Browse files
diskwuGuozhanxin
andauthored
避免警告,变量可能未初始化就使用 (#5544)
* 避免警告,变量可能未初始化就使用 * 避免警告,变量可能未初始化就使用 * 避免警告,变化可能未初始化就使用。 * Update bsp/stm32/libraries/HAL_Drivers/drv_usart.c Co-authored-by: guo <[email protected]> * Update bsp/stm32/libraries/HAL_Drivers/drv_usart_v2.c Co-authored-by: guo <[email protected]> Co-authored-by: guo <[email protected]>
1 parent b5de986 commit 03f46c6

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

bsp/stm32/libraries/HAL_Drivers/drv_usart.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,14 +918,15 @@ static void stm32_dma_config(struct rt_serial_device *serial, rt_ubase_t flag)
918918
struct stm32_uart *uart;
919919

920920
RT_ASSERT(serial != RT_NULL);
921+
RT_ASSERT(flag == RT_DEVICE_FLAG_DMA_TX || flag == RT_DEVICE_FLAG_DMA_RX);
921922
uart = rt_container_of(serial, struct stm32_uart, serial);
922923

923924
if (RT_DEVICE_FLAG_DMA_RX == flag)
924925
{
925926
DMA_Handle = &uart->dma_rx.handle;
926927
dma_config = uart->config->dma_rx;
927928
}
928-
else if (RT_DEVICE_FLAG_DMA_TX == flag)
929+
else /* RT_DEVICE_FLAG_DMA_TX == flag */
929930
{
930931
DMA_Handle = &uart->dma_tx.handle;
931932
dma_config = uart->config->dma_tx;

bsp/stm32/libraries/HAL_Drivers/drv_usart_v2.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -959,14 +959,15 @@ static void stm32_dma_config(struct rt_serial_device *serial, rt_ubase_t flag)
959959
struct stm32_uart *uart;
960960

961961
RT_ASSERT(serial != RT_NULL);
962+
RT_ASSERT(flag == RT_DEVICE_FLAG_DMA_TX || flag == RT_DEVICE_FLAG_DMA_RX);
962963
uart = rt_container_of(serial, struct stm32_uart, serial);
963964

964965
if (RT_DEVICE_FLAG_DMA_RX == flag)
965966
{
966967
DMA_Handle = &uart->dma_rx.handle;
967968
dma_config = uart->config->dma_rx;
968969
}
969-
else if (RT_DEVICE_FLAG_DMA_TX == flag)
970+
else /* RT_DEVICE_FLAG_DMA_TX == flag */
970971
{
971972
DMA_Handle = &uart->dma_tx.handle;
972973
dma_config = uart->config->dma_tx;

0 commit comments

Comments
 (0)