8285 views|7 replies

527

Posts

1

Resources
The OP
 

【ST NUCLEO-H743ZI Review】(2)Converting serial port and Ethernet port data under LWIP [Copy link]

This post was last edited by supermiao123 on 2019-3-1 16:37 Today I bring you the evaluation of serial port and network port data interaction under H7's LWIP. Since H7 has a significant performance improvement compared to previous series, the architecture has become more complex. STM32cube has greatly improved the speed of programming, and today's evaluation is no exception. As shown in the figure below, the relevant settings for ETH are generated. It should be noted that the gray font below means that ETH can only work when the RAM is 0x24000000. So I looked at the manual and saw that 0x24000000 is AXI SRAM, and the default 0x20000000 is DTCM. Looking at the figure below, the architectural positions of the two RAMs are different. Another thing to note is that the ETH IO speed is LOW, so it is best to change it to VERY HIGH. Then configure LWIP. Fixed IPs often collide with each other, or when changing switches, you may encounter 192.168.0.X or 192.168.1.x. Simply use the automatic IP acquisition function, and configure TFT and the serial port to output the IP address when obtaining the IP. Below is the serial port configuration. Then just generate it. Then pay attention to the previous prompts, the compiler has changed two places. Next is the code to implement the interaction.
  1. USART3->CR1 |= USART_CR1_TE |USART_CR1_RE |USART_CR1_RXNEIE; USART3->CR1 |= USART_CR1_UE; HAL_GPIO_WritePin(GPIOC, TFT_BL_Pin, GPIO_PIN_SET); SPI1->CR1 |=SPI_CR1_SPE ; SPI1->CR1 |= SPI_CR1_CSTART; lcd_initial(); dsp_single_colour(WHITE); tcp_server_init();
复制代码
The above is the initialization of the serial port and TFT. The serial port enables the receive interrupt, enables the SPI that controls the TFT, and initializes the TFT. Finally, TCP_SERVER is initialized.
  1. void tcp_server_init(void) { err_t err; tcp_server_pcb = tcp_new(); if(tcp_server_pcb !=NULL) { err = tcp_bind(tcp_server_pcb,IP_ADDR_ANY,7); if(err == ERR_OK) { tcppcbconn = tcp_listen(tcp_server_pcb); tcp_accept(tcppcbconn,tcp_server_accept); } else { memp_free(MEMP_TCP_PCB, tcp_server_pcb); } } }
复制代码
After TCP receives it, the serial port sends it out.
  1. static err_t tcp_server_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p,err_t err) { HAL_UART_Transmit(&huart3,p->payload,p->len,100); pbuf_free(p); return ERR_OK; }
复制代码
The serial port receives data and detects 0xA carriage return and then sends it
  1. void USART3_IRQHandler(void) { /* USER CODE BEGIN USART3_IRQn 0 */ uart3_data[uart3_rx_cnt]=USART3->RDR; if(uart3_data[uart3_rx_cnt]==0xA) { uart3_data_valid=1; //uart3_rx_cnt=0; } else uart3_rx_cnt++; /* USER CODE END USART3_IRQn 0 */ HAL_UART_IRQHandler(&huart3); /* USER CODE BEGIN USART3_IRQn 1 */ /* USER CODE END USART3_IRQn 1 */ }
复制代码
Add the operation of displaying the IP to the TFT and sending it to the serial port in the LWIP handler. And send the code to TCP after receiving the valid command from the serial port.
  1. void MX_LWIP_Process(void) { /* USER CODE BEGIN 4_1 */ unsigned char ip[4]={0}; char ipstr[16]={0}; /* USER CODE END 4_1 */ ethernetif_input(&gnetif); /* USER CODE BEGIN 4_2 */ /* USER CODE END 4_2 */ /* Handle timeouts */ sys_check_timeouts(); /* USER CODE BEGIN 4_3 */ if(gnetif.ip_addr.addr!=0&&!ipget) { ip[3]=(uint8_t)(gnetif.ip_addr.addr>>24); ip[2]=(uint8_t)(gnetif.ip_addr.addr>>16); ip[1]=(uint8_t)(gnetif.ip_addr.addr>>8); ip[0]=(uint8_t)(gnetif.ip_addr.addr); printf("ip_addr : %d.%d.%d.%d \r\n",ip[0],ip[1],ip[2],ip[3]); TFTStrDisplay_lite(0,0,"IP GET",6); sprintf(ipstr,"%d.%d.%d.%d",ip[0],ip[1],ip[2],ip[3]); TFTStrDisplay_lite(1,0,ipstr, 15); ipget=1; } uart_send_tcp_recv(uart3_data_valid,uart3_data,uart3_rx_cnt); if(uart3_data_valid) { memset(uart3_data,0,100); uart3_data_valid=0; uart3_rx_cnt=0; } /* USER CODE END 4_3 */ } void uart_send_tcp_recv(unsigned char flag,unsigned char *data,unsigned char cnt) { if(flag ) { tcp_write(tcp_server_pcb,data,cnt,1); tcp_output(tcp_server_pcb); } }
复制代码
After running, TFT displays the IP address. The serial port also sees the IP address. According to the obtained IP, the running effect is as shown below. This simply completes the network port My level is limited, welcome to exchange and correct, thank you for your browsing! This content is provided by EEWORLD forum user [ size=3]supermiao123Original, if you want to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source



This post is from stm32/stm8

Latest reply

OP, can you share the code, 993960025@qq.com, thank you   Details Published on 2021-11-22 09:00
 

2865

Posts

4

Resources
2
 
I made a separate project according to your instructions. 1. I changed the GPIO speed of ETH to VERY HIGH, but ETH_MDC could not be changed because it only has LOW items. 2. I also changed it according to your diagram when compiling. 3. I added MX_LWIP_Process() to while(1) in main; But it still doesn't work!!!
This post is from stm32/stm8

Comments

First see if you can PING through, or watch to see if there is an IP address in gnetif. Another option is to add __HAL_RCC_D2SRAM3_CLK_ENABLE(); in the initialization.  Details Published on 2019-3-1 20:31
 
 

527

Posts

1

Resources
3
 
bigbat posted on 2019-3-1 20:24 I did a separate project as you said, 1. All GPIO speeds of ETH were changed to VERY HIGH, only ETH_MDC could not be changed because it only has LOW items. 2. ...
First see if PING is possible, or watch to see if there is an IP address in gnetif, and also add __HAL_RCC_D2SRAM3_CLK_ENABLE(); in the initialization to try this.
This post is from stm32/stm8
 
 

2865

Posts

4

Resources
4
 
I added the following code to void SystemClock_Config(void) in main.c:
  1. while ((PWR->D3CR & (PWR_D3CR_VOSRDY)) != PWR_D3CR_VOSRDY) {} __HAL_RCC_D2SRAM3_CLK_ENABLE();
复制代码
But it still doesn’t work. It cannot find the IP with this MAC [00:80:E1:00:00:02] in the DHCP list!


This post is from stm32/stm8

Comments

http://www.stmcu.org.cn/module/forum/thread-615089-1-3.html Then you can look at this post, first disable MPU and CACHE and then PING, then you can enable MPU and CACHE  Details Published on 2019-3-2 19:02
 
 
 

527

Posts

1

Resources
5
 
bigbat posted on 2019-3-2 12:05 I added the code to void SystemClock_Config(void) in main.c: The result still does not work. Unable to find this MAC in the DHCP list ...
http://www.stmcu.org.cn/module/forum/thread-615089-1-3.html Then you can take a look at this post, first disable MPU and CACHE and then PING, you can enable MPU and CACHE later
This post is from stm32/stm8
 
 
 

1

Posts

0

Resources
6
 

Can you please send me a project? I am studying H743 recently. Email: yakun81131@yeah.net

This post is from stm32/stm8
 
 
 

4

Posts

1

Resources
7
 

Can you send me a copy, eczc@qq.com

This post is from stm32/stm8
 
 
 

1

Posts

0

Resources
8
 

OP, can you share the code, 993960025@qq.com, thank you

This post is from stm32/stm8
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list