Forum Discussion
Hi Alen1214
From the address map I see that UART IP is connected to the light-weight F2H and an offset of 0x7000.
The LWF2H start address is 0xFF200000.
Could you try accessing the address 0xFF207000 as your h2p_lw_uart_addr?
Regards
Jingyang, Teh
Hi Jingyang, Teh,
I have transferred data from de10 out of uart pin successfully. But the data retransmitted was wrong when I could transmit the data string data "PLEASE" received as "Ó", received "1234" as "Ê". The device I use to receive is a UArt to usb module (CP2102).
I do the following step by step:
1. Connect hardware:
Connect hardware (1)Connect hardware (2)data received from CP2102 displayed on hercules terminal
2. Add ip into GHRD project
Qsys connectionconfigure IP uart
address map (1)address map (2)address map (3)
3.Assignments pin
File top.v(1)File top.v(2) Assignments pin (GPIO 6 - RX, GPIO7-TX)
4. File hex use for code C
Define for IP UART
5. FILE CODE C: admin, please help me check carefully the C code that has set baudrate and especially send the data, is it correct?
-------------------------------------------
Thank you very much Jingyang. I hope you have amazing day.
Regards,
Alen1214.
- Tarun_Rai2 years ago
New Contributor
Hello!
Hope you are doing well, need your help with the following issue!
Description:
What i am trying to test out receiving and transmitting with the code i have made the qsys design programmed it wrote the c code, etc. everything works fine as soon as i change the main() to take the data i.e., RX and copy it to char array of TX to write it back on the screen in this case putty it doesn't work idk why. Can you please help me this! Thank you very much!
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/mman.h>
#include <sys/time.h>
#include "ARM_A9_HPS.h"
#include <string.h>
//lw bus; uart
#define HW_REGS_BASE 0xff200000
#define HW_REGS_SPAN 0x00001000
#define HW_REGS_MASK ( HW_REGS_SPAN - 1 )
void uart_putc(char c ,unsigned long *h2p_lw_uart_addr)
{
unsigned short uart_status;
do{
uart_status = *(h2p_lw_uart_addr + 2);
}while(!(uart_status & 0x40));
*(h2p_lw_uart_addr + 1) = c;
}
void uart_printf(char *str ,unsigned long *h2p_lw_uart_addr)
{
while(*str != '\0')
{
uart_putc(*str ,h2p_lw_uart_addr);
str++;
}
}
int uart_getc(unsigned long *h2p_lw_uart_addr){
unsigned short uart_status;
do {
uart_status = *(h2p_lw_uart_addr + 2);
} while (!(uart_status & 0x80));
return *(h2p_lw_uart_addr + 0);
}
int uart_scanf(char *p,unsigned long *h2p_lw_uart_addr){
int cnt = 0;
while (1) {
*p = uart_getc(h2p_lw_uart_addr);
cnt++;
if (*p == '\n' || *p == '\r')
return cnt;
else
p++;
}
}// /dev/mem file id
int fd;int main()
{
void *virtual_base;
int i;
unsigned long *h2p_lw_uart_addr;// === get FPGA addresses ==================
// Open /dev/mem
if( ( fd = open( "/dev/mem", ( O_RDWR | O_SYNC ) ) ) == -1 ){
printf( "ERROR: could not open \"/dev/mem\"...\n" );
return( 1 );
}//============================================
// get virtual addr that maps to physical
// for light weight AXI bus
virtual_base = mmap( NULL, HW_REGS_SPAN, ( PROT_READ | PROT_WRITE ), MAP_SHARED, fd, HW_REGS_BASE );
if( virtual_base == MAP_FAILED ){
printf( "ERROR: mmap() failed...\n" );
close( fd );
return( 1 );
}
h2p_lw_uart_addr=(unsigned long*) (virtual_base);//uart
*(h2p_lw_uart_addr + 4) = (int) ((UART_0_FREQ / UART_0_BAUD)-1) ;char c[20]="Transmitting";
char p[20] = "";
while( 1 )
{
uart_scanf(&p[0],h2p_lw_uart_addr);
usleep(100*1000);p = c;
uart_printf(&c[0],h2p_lw_uart_addr);
usleep( 100*1000 );
}
}As just TX works fine (from board) i think qsys implementation is correct and simple too.
Thanks,
Tarun_rai
- Tarun_Rai2 years ago
New Contributor
Hi,
Small clarification i uesd "strcpy(p, c)" to copy the string.
Thanks!