Skip to content

Commit db9746e

Browse files
unicornxRbb666
authored andcommitted
bsp: k230: update uart driver
Signed-off-by: Wang Chen <unicorn_wang@outlook.com>
1 parent 980a376 commit db9746e

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

bsp/k230/drivers/interdrv/uart/drv_uart.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@
1313
#include "board.h"
1414
#include "drv_uart.h"
1515
#include "riscv_io.h"
16-
#include "board.h"
1716

1817
#define UART_DEFAULT_BAUDRATE 115200
1918
#define UART_CLK 50000000
20-
#define UART_ADDR 0x91403000UL
21-
#define UART_IRQ 0x13
19+
#define UART_ADDR UART0_BASE_ADDR
20+
#define UART_IRQ 0x10
2221

2322

2423
#define UART_RBR (0x00) /* receive buffer register */
@@ -94,6 +93,7 @@
9493
struct device_uart
9594
{
9695
rt_ubase_t hw_base;
96+
void* pa_base;
9797
rt_uint32_t irqno;
9898
};
9999

@@ -251,7 +251,7 @@ static rt_err_t uart_control(struct rt_serial_device *serial, int cmd, void *arg
251251
return -RT_ENOMEM;
252252
}
253253

254-
mmap2->ret = lwp_map_user_phy(lwp_self(), RT_NULL, (void*)(uart->hw_base), mmap2->length, 0);
254+
mmap2->ret = lwp_map_user_phy(lwp_self(), RT_NULL, uart->pa_base, mmap2->length, 0);
255255
}
256256
break;
257257
}
@@ -311,12 +311,16 @@ static void rt_hw_uart_isr(int irq, void *param)
311311
}
312312
else if (lsr & (UART_LSR_DR | UART_LSR_BI))
313313
{
314-
#ifdef RT_USING_SERIAL_V2
315314
struct rt_serial_rx_fifo *rx_fifo;
316-
uint8_t data;
317-
318315
rx_fifo = (struct rt_serial_rx_fifo *)serial->serial_rx;
319-
RT_ASSERT(rx_fifo != RT_NULL);
316+
317+
if (rx_fifo == NULL)
318+
{
319+
readb((void*)(uart_base + UART_RBR));
320+
return;
321+
}
322+
#ifdef RT_USING_SERIAL_V2
323+
uint8_t data;
320324

321325
do {
322326
data = readb((void*)(uart_base + UART_RBR));
@@ -352,7 +356,8 @@ int rt_hw_uart_init(void)
352356
serial->config = config;
353357
serial->config.baud_rate = UART_DEFAULT_BAUDRATE;
354358

355-
uart->hw_base = (rt_base_t)rt_ioremap((void *)UART_ADDR, 0x1000);
359+
uart->pa_base = (void *)UART_ADDR;
360+
uart->hw_base = (rt_base_t)rt_ioremap(uart->pa_base, 0x1000);
356361
uart->irqno = UART_IRQ;
357362

358363
_uart_init((void*)(uart->hw_base));

0 commit comments

Comments
 (0)