Notifications
Clear all

外设uart模块doc文件夹下的说明文档对寄存器地址的描述与bsp包里的bsp_printf.c中描述的寄存器地址不一致?The description of the register addresses in the documentation under the doc folder of the peripheral uart module does not match the register addresses described in bsp_printf.c in the bsp ...

 

(@my123)
Eminent Member
Joined: 3 years ago
Posts: 43
Topic starter  

      亲爱的Robert Owen先生,您好!我们在使用uart模块进行数据收发时,发现uart模块doc文件夹下的参考手册UART_spec.pdf中对寄存器地址的描述不清楚。

1,按照正常逻辑,如果要发送一个字节的数据到pc端,那么需要判断发送寄存器是否为空,若为空,则把数据赋值给发送寄存器即可,接受时也是类似。但在uart说明文档中,接收和发送寄存器的地址偏移量均为0(图 uart寄存器.png),这是否说明接受和发送是同一个寄存器?如果是的话,那该如何控制uart处于发送状态还是接收状态?

2,当我们查看bsp包里的bsp_printf.c中对接收和发送寄存器的地址定义时发现:UART_RX_DATA发送寄存器地址为基地址 + 0x0个偏移量,而UART_TX_DATA接收寄存器地址为基地址 + 0x4个偏移量,为什么与UART_spec.pdf中定义的不符合?M_UART_WR_REG_*地址偏移量有4*0x03、4*0x05,这超过了UART_spec.pdf中寄存器最高偏移量,请问这些是什么原因?(图 bsp_printf.png)

3,图uart_test.c为我们根据自己的理解写的uart传输测试程序,该程序从pc端接收一个字符,并将接收到的字符ascll码加1,然后传回pc端,但是未能成功,不知道问题出在哪里。

      我们提出的问题可能比较繁琐,还请Robert Owen先生能在百忙之中为我们解答疑问,我们在这个问题上花了很多时间但仍未解决,所以非常感谢Robert Owen先生看一下问题出在哪里。

 

Translation:

Dear Mr. Robert Owen, Hello! When we use uart module to send and receive data, we found that the description of register address in the reference manual UART_spec.pdf under the doc folder of uart module is not clear.

1, according to the normal logic, if we want to send a byte of data to the pc side, then we need to judge whether the send register is empty or not, if it is empty, then we can assign the data to the send register, and it is similar when accepting. But in the uart description document, the address offset of both receive and send registers is 0 (Figure uart register.png), does this mean that receive and send are the same register? If so, how to control whether the uart is in the transmit or receive state?

2, when we look at the definition of receive and transmit registers in bsp_printf.c in bsp package, we find that: UART_RX_DATA transmit register address is base address + 0x0 offset, while UART_TX_DATA receive register address is base address + 0x4 offset, why does it not match with the definition in UART_spec.pdf? The address offset of M_UART_WR_REG_* has 4*0x03 and 4*0x05, which exceeds the highest register offset in UART_spec.pdf, what are the reasons for these? (Figure bsp_printf.png)

3, Figure uart_test.c is the uart transmission test program we wrote according to our own understanding. The program receives a character from the pc side and adds 1 to the received character ascll code and then passes it back to the pc side, but it fails to work, I don't know what the problem is.

We have spent a lot of time on this problem but it is still not solved, so thank you very much Mr. Robert Owen to see what the problem is.

This topic was modified 3 years ago 2 times by guanyang.he

   
Quote
(@my123)
Eminent Member
Joined: 3 years ago
Posts: 43
Topic starter  

uart寄存器.png


   
ReplyQuote
(@my123)
Eminent Member
Joined: 3 years ago
Posts: 43
Topic starter  

bsp_printf.png


   
ReplyQuote
(@my123)
Eminent Member
Joined: 3 years ago
Posts: 43
Topic starter  

#define uart_data (*(volatile unsigned int *)0x80002000)
#define uart_lsr (*(volatile unsigned int *)0x80002005)

#define uart_lsr_r_mask 0x01
#define uart_lsr_w_mask 0x80

char uart_getchar(void)
{
char c;
while(!(uart_lsr_r_mask & uart_lsr));
c = uart_data;

return c;
}

void uart_putchar(char c)
{
while(!(uart_lsr_w_mask & uart_lsr));
uart_data = c;

return 0;
}

int main(void)
{
char c;
while(1)
{
c = char uart_getchar();
c++;
void uart_putchar(char c);
}

return 0;
}


   
ReplyQuote
dchaver
(@dchaver)
Member Admin
Joined: 3 years ago
Posts: 80
 

Hi @my123

Please check the following code:

 

#if defined(D_NEXYS_A7)
#include <bsp_printf.h>
#include <bsp_mem_map.h>
#include <bsp_version.h>
#else
PRE_COMPILED_MSG("no platform was defined")
#endif
#include <psp_api.h>

 

#define uart_data (*(volatile unsigned int *)0x80002000)
#define uart_lsr (*(volatile unsigned int *)0x80002014)

 

#define uart_lsr_r_mask 0x01
#define uart_lsr_w_mask 0x20

 

char uart_getchar(void)
{
char c;
while((uart_lsr_r_mask & uart_lsr) == 0);
c = uart_data;
return c;
}

 

int uart_putchar(char c)
{
/* Check for space in UART FIFO */
while((uart_lsr_w_mask & uart_lsr) == 0);
//write char
uart_data = c;
return 0;
}

 

int main(void)
{
char c;
uartInit();
while(1)
{
c = uart_getchar();
uart_putchar(c);
}
return 0;
}

   
ReplyQuote
(@my123)
Eminent Member
Joined: 3 years ago
Posts: 43
Topic starter  

      亲爱的Prof. Daniel,您好!我们使用您修改后的uart_test.c程序后发现该程序是可以正常接收和发送数据的,说明没有问题,这让我们很高兴。可是仍有些问题让我们很费解,为什么您将uart_lsr寄存器地址改为0x80002014(基地址 + 20),可UART_spec.pdf中给出uart_lsr寄存器地址偏移量为5。我想理解这一点对我们后面继续开发至关重要,所以您是否可以解答我们的疑惑,有没有可能UART_spec.pdf的内容本身就是错误的呢?非常期待您的回复!

Dear Prof. Daniel, Hello! We are very happy to find that the uart_test.c program can receive and send data normally after using your modified program, which means there is no problem. However, we still have some questions which make us confused, why you change the uart_lsr register address to 0x80002014 (base address + 20), but the UART_spec.pdf gives the uart_lsr register address offset as 5. I think understanding this point is crucial for us to continue the development later, so can you answer our doubts, is there Is it possible that the content of uart_spec.pdf itself is wrong? I'm looking forward to your reply!

This post was modified 3 years ago by guanyang.he

   
ReplyQuote
dchaver
(@dchaver)
Member Admin
Joined: 3 years ago
Posts: 80
 

Yes, I think that the table that specifies the "Registers list" in Chapter 4 is very confusing: the Address column should be multiplied by 4. You can verify the register addresses for UART in file: .platformio/packages/framework-wd-riscv-sdk/board/nexys_a7_eh1/bsp/bsp_printf.c.


   
ReplyQuote