Browse Source

bsp: k230: fix some cpp_check warnings

Signed-off-by: Chen Wang <unicorn_wang@outlook.com>
Chen Wang 1 week ago
parent
commit
283c2fb94f
2 changed files with 12 additions and 2 deletions
  1. 1 1
      bsp/k230/board/board.c
  2. 11 1
      bsp/k230/drivers/interdrv/uart/drv_uart.c

+ 1 - 1
bsp/k230/board/board.c

@@ -64,7 +64,7 @@ void init_bss(void)
     unsigned int *dst;
 
     dst = &__bss_start;
-    while (dst < &__bss_end)
+    while ((rt_ubase_t)dst < (rt_ubase_t)&__bss_end)
     {
         *dst++ = 0;
     }

+ 11 - 1
bsp/k230/drivers/interdrv/uart/drv_uart.c

@@ -129,7 +129,17 @@ static void _uart_init(void *uart_base)
     dlh = bdiv >> 12;
     dll = (bdiv - (dlh << 12)) / 16;
     dlf = bdiv - (dlh << 12)  - dll * 16;
-    if(dlh == 0 && dll == 0)
+    // dlh can be 0 only if bdiv < 4096 (since we're shifting right by 12 bits)
+    // bdiv = UART_CLK / UART_DEFAULT_BAUDRATE
+    //      = 50000000 / 115200
+    //      = 434.027
+    // so when dlh is 0,
+    // dll = (bdiv - (dlh << 12)) / 16
+    //     = (434.027 - 0) / 16
+    //     = 27.626
+    // which means dll can not reach 0,
+    // so we use 1 as the minimum value for dll
+    if((dlh == 0) && (dll < 1))
     {
         dll = 1;
         dlf = 0;