Intel® SoC FPGA Embedded Development Suite
Support for SoC FPGA Software Development, SoC FPGA HPS Architecture, HPS SoC Boot and Configuration, Operating Systems
466 Discussions

De10 standard connects to esp8266 via uart communication by IP uart (rs-232 serial port)

Alen1214
Beginner
3,709 Views

Hi, I need to communicate between de10 and esp8266 to send data to the cloud, but first I need to connect these 2 kits base on project GHRD. I see they can connect with each other by IP uart rs232 and I can do the steps:

build qsys => modify file top.v =>run quartus=>generate file hex.

And now i need code use hps control it send data, example send "abcde" to tx port with baund rate 9600 or 115200. But i don't know how to do it ?. So I really need your help. I attached 3 pictures I made.Thank you very much. 

QSYSQSYSadd external port for uart rs232add external port for uart rs232file hex contain rs232_0_basefile hex contain rs232_0_base

Labels (1)
0 Kudos
1 Solution
JingyangTeh
Employee
3,234 Views

Hi Allen


Do you have a scope available to measure the signals coming out from the pins?

Do you have the specification for the USB transceiver that you are using? What operating signal logic it is able to capture?

The signals coming out from the GPIO are 3.3Vs.


Regards

Jingyang, Teh


View solution in original post

0 Kudos
21 Replies
Alen1214
Beginner
3,424 Views

Sorry i had a important update with all image. You will follow new image i update and I don't know why my code is like this but esp8266 doesn't receive data? You help me check it. Thank you very much for your help.

QSYSQSYSadd external port for uart rs232 serial portadd external port for uart rs232 serial portcode rx for esp8266 (1)code rx for esp8266 (1)code rx for esp8266 (2)code rx for esp8266 (2)file hex contain  UART_0_BASEfile hex contain UART_0_BASEcode tx for de10 (1)code tx for de10 (1)code tx for de10(2)code tx for de10(2)code tx for de10 (3)code tx for de10 (3)

0 Kudos
JingyangTeh
Employee
3,381 Views

Hi Alen1214


What error are you experiencing when running the code on the HPS?

Can you please share the run logs for the code in the HPS.


Could you share a screenshot of your Address Map in Qsys?

I think it could be related to the address value that you set for the uart.

Could you print out what is the exact value of h2p_lw_uart_addr?


Regards

Jingyang, Teh


0 Kudos
Alen1214
Beginner
3,360 Views

Thank a lot Jingyang, Teh.

when running the core on the HPS, I has no error and in terminal has a long string "hello hello ...." but ESP8266 is not getting any character.

Then I share with you some screenshot of your Address Map in QsysAddress map in Qsys (1)Address map in Qsys (1)Address map in Qsys (2)Address map in Qsys (2)Address map in Qsys (3)Address map in Qsys (3)

I will print out the exact address value of h2p_lw_uart_addr as soon as I can. And I hope you check for me with some information I provided.

I thank you very much for your help and I hope you have amazing date!!!

Regards,

Alen1214

0 Kudos
JingyangTeh
Employee
3,283 Views

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



Alen1214
Beginner
3,262 Views

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 (1)Connect hardware (2)Connect hardware (2)data received from CP2102 displayed on hercules terminaldata received from CP2102 displayed on hercules terminal

2. Add ip into GHRD project 

Qsys connectionQsys connectionconfigure IP uartconfigure IP uart

address map (1)address map (1)address map (2)address map (2)address map (3)address map (3)

3.Assignments pin

File top.v(1)File top.v(1)File top.v(2)File top.v(2) Assignments pin (GPIO 6 - RX, GPIO7-TX)Assignments pin (GPIO 6 - RX, GPIO7-TX)

4. File hex use for code C

Define for IP UARTDefine 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? 

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include "hwlib.h"
#include "socal/socal.h"
#include "socal/hps.h"
#include "socal/alt_gpio.h"
#include "hps_0.h"
#include <string.h>
#define HW_REGS_BASE ( ALT_STM_OFST )
#define HW_REGS_SPAN ( 0x04000000 )
#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') 
                     return cnt; 
             else
                      p++; 
       } 
}
int main() {
 
void *virtual_base;
int fd;
 
int i;
unsigned long *h2p_lw_uart_addr;
// map the address space for the LED registers into user space so we can interact with them.
// we'll actually map in the entire CSR span of the HPS since we want to access various registers within that span
if( ( fd = open( "/dev/mem", ( O_RDWR | O_SYNC ) ) ) == -1 ) {
         printf( "ERROR: could not open \"/dev/mem\"...\n" );
         return( 1 );
}
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 + ( ( unsigned long  )( ALT_LWFPGASLVS_OFST + UART_0_BASE ) & ( unsigned long)( HW_REGS_MASK ) ));//uart
//h2p_lw_uart_addr=(unsigned long *)(virtual_base + ( ( unsigned long  )( ALT_LWFPGASLVS_OFST + UART_0_BASE ) & ( unsigned long)( HW_REGS_MASK )));//uart
// toggle the LEDs a bit
    *(h2p_lw_uart_addr + 4) = (int) ((UART_0_FREQ / UART_0_BAUD)-1) ;
    //*(h2p_lw_uart_addr + 4) = (int) ((UART_0_FREQ / UART_0_BAUD)+1) ; I tried but not correct
    //*(h2p_lw_uart_addr + 4) = (int) (UART_0_FREQ / UART_0_BAUD + 0.5); I tried but not correct
 
char c[20]="PLEASE";
while( 1 ) {
        // control led
        // wait 100ms
        uart_printf(&c[0],h2p_lw_uart_addr);
        usleep( 100*1000 );
 
 
} // while
// clean up our memory mapping and exit
if( munmap( virtual_base, HW_REGS_SPAN ) != 0 ) {
        printf( "ERROR: munmap() failed...\n" );
        close( fd );
        return( 1 );
}
 
close( fd );
 
return( 0 );
}

 

-------------------------------------------

Thank you very much Jingyang. I hope you have amazing day.

Regards,

Alen1214.

 
 
 
0 Kudos
Alen1214
Beginner
3,162 Views

Hi,

I added more about the implementation step:

Connect hardwareConnect hardware

I have looked for examples of uart of this IP but there are very few examples and only got 1 example made with the GHRD project from this links:
   1. https://blog.csdn.net/weixin_43649647/article/details/121069892

   2. Page 140 to page 155:  https://www.intel.com/programmable/technical-pdfs/683130.pdf

   3. Project example for Nios (but I must use with GHRD): https://www.intel.com/content/www/us/en/design-example/715139/cyclone-v-uart-rs-232-maximum-baud-rate-reference-design.html?wapkw=uart

Also, I think this problem may be caused by asynchronous transfer speed (baundrate) of the two devices or another error? But I don't know how to fit it. please help me to fix this error of wrong data transmission.

Thanks, 

Alen1214

0 Kudos
Alen1214
Beginner
3,144 Views
0 Kudos
JingyangTeh
Employee
3,101 Views

Hi Allen


For the baud rate settings, you do not need to write to the divisor register as you have selected "Fixed Baudrate" in the IP Configuration.

Writing to the divisor register as no effect.

Gone through the code that you shared, it looks fine with all the condition checking before sending.


One thing I can think of is the stop bit settings. The tool that you are using to write and read from the UART does not have a settings to set the Stop bits.

Could you try with another tool such as Putty? In putty there is a Stop bits settings, with that set the Stop bit to 1 same as the IP configuration.


Regards

Jingyang,Teh


0 Kudos
JingyangTeh
Employee
3,058 Views

Hi Alen


Have you tried using a different tool that supports setting stop bit?

There are a few that I have used before: Teraterm & putty.


Regards

Jingyang, Teh


0 Kudos
Alen1214
Beginner
3,047 Views

hi,I have tried using putty but it's not correct. 

puttyputtyputtyputtyterminalterminal

Tomorrow, I will try with configure some parameters : not "fixed baud rate" or  "baud =9600". sometime, I think With clock 50M and baud 115200 maybe make larger speed error.

regards, 

Alen

 

0 Kudos
JingyangTeh
Employee
3,235 Views

Hi Allen


Do you have a scope available to measure the signals coming out from the pins?

Do you have the specification for the USB transceiver that you are using? What operating signal logic it is able to capture?

The signals coming out from the GPIO are 3.3Vs.


Regards

Jingyang, Teh


0 Kudos
Alen1214
Beginner
2,960 Views

hi JingyangTeh, 

Thank you so much for your support. I succeeded in this application. The problem :  the baudrate of IP in the manual is not true to reality.

 

regards, 

alen

0 Kudos
JingyangTeh
Employee
2,950 Views

Hi Alen


That is weird that the baudrate are different from set.

How much difference was it?

How did you correct the difference?


Regards

JIngyang, Teh


0 Kudos
Alen1214
Beginner
2,920 Views

Hi JingyangTeh, 

When I found the error, I felt strange.

When I set baudrate = 9600, the real baudrate is 12500 (time per bit is 80us). And I used oscilloscope to measure and detect that.

 

Regards,

Alen (Phan Quang Kỳ)

0 Kudos
JingyangTeh
Employee
2,849 Views

Hi Alen


Glad that you are able to get your project working.


Could you please share the wave form that you have and a screenshot of the settings that you done in the IP?

What version of the quartus that you are using currently?

I will raise this up to the engineering team to investigate this issue further as this is not an expected behaviour.


Regards

Jingyang, Teh


0 Kudos
JingyangTeh
Employee
2,816 Views

Hi Allen


Any update on this case?

It would be great if you could share me a screenshot of the waveform captured.

Thanks in advance!


Regards

Jingyang, Teh


0 Kudos
Alen1214
Beginner
2,812 Views

Hi JingyangTeh,

Please wait a few weeks, I have some reports to report once completed, I will send them to you.

 

Regards, 

Alen

0 Kudos
JingyangTeh
Employee
2,737 Views

Hi Alen


Thanks for the sharing.

Hope to hear from you regarding the waveform.


Regards

Jingyang, Teh


0 Kudos
JingyangTeh
Employee
2,549 Views

Hi Alen


Did you manage to get the waveform for the uart baud rate?


Regards

Jingyang, Teh



0 Kudos
Alen1214
Beginner
2,540 Views

Hi Jingyang, Teh

I send you some waveforms corresponding to some cases.

1. configure set fixed baudrate 9600 in qsys:

waveform correct with data "57" but baudrate is not correct (a)waveform correct with data "57" but baudrate is not correct (a)waveform correct with data "57" but baudrate is not correct (b)waveform correct with data "57" but baudrate is not correct (b)
2. uncheck set fixed baudrate in qsys: 

when i set clock = 50M and divisor = 7400 then it correct all. 

waveform when i set divisor = 7400waveform when i set divisor = 7400

I hope with the information I provided you can find the source of the error.

 

Regards

Alen (Phan Quang Ky)

0 Kudos
Reply