Skip to main content
Associate III
October 1, 2024
Solved

Configuring PPP on STM32F407DISC with LTE Modem via USART Using LWIP and Ethernet Without Pin Usage

Hello,
I'm working with an STM32F407DISC and an LTE modem connected via USART. I want to configure PPP communication using LWIP. Could you explain how to set up PPP in this context(ioc file)?
Additionally, is it possible to enable the Ethernet (ETH) interface without using its physical pins, just for PPP over serial?

This topic has been closed for replies.
KDJEM.1
KDJEM.1Best answer
ST Technical Moderator
October 4, 2024

Hello @Noushadalik ,

 

I confirm that the steps shared in this post are developed to set PPP for STM32H747 MCU but you get inspired from these steps to set PPP for STM32F407. The DCache is not available in STM32F407.

To set PPP in STM32F407G-DISC1:

-1- Configure the ethernet as shown in the below figure ( RMII mode for example)

KDJEM1_0-1728029749989.png

2- Enable LWIP

KDJEM1_1-1728029975471.png

  • Use PPP_SUPPORT requires PPPOS_SUPPORT, PPPOE_SUPPORT or PPPOL2TP_SUPPORT turned on.
  • PPP_SUPPORT needs also PPP_IPV4_SUPPORT and/or PPP_IPV6_SUPPORT turned on.

Currently STM32CubeMx do not give possibility to select LwIp Middleware without to have previously selected Ethernet. So, you can enable LWIP only if ETH IP is configured.

 

Thank you.

Kaouthar

To give better visibility on the answered topics, please click on "Best answer" on the reply which solved your issue or answered your question.

6 replies

Associate III
October 2, 2024

Hello,
Any update Today?

KDJEM.1
ST Technical Moderator
October 3, 2024

Hello @Noushadalik ,

According how to set PPP, I advise you to take a look at this post: Solved: Re: how to set PPP with lte modem - STMicroelectronics Community  may help you.

Thank you.

Kaouthar

To give better visibility on the answered topics, please click on "Best answer" on the reply which solved your issue or answered your question.
Associate III
October 3, 2024

hello @ KDJEM.1,

I saw the thread on STM32H747 MCU PPP configuration. Does it apply to the STM32F407 MCU?
I am unable to set the second step, "Enable DCache," in the STM32F407 IOC file.

Are ETH pins unavailable for other functionalities when using only the lwIP PPP?


 
KDJEM.1
KDJEM.1Best answer
ST Technical Moderator
October 4, 2024

Hello @Noushadalik ,

 

I confirm that the steps shared in this post are developed to set PPP for STM32H747 MCU but you get inspired from these steps to set PPP for STM32F407. The DCache is not available in STM32F407.

To set PPP in STM32F407G-DISC1:

-1- Configure the ethernet as shown in the below figure ( RMII mode for example)

KDJEM1_0-1728029749989.png

2- Enable LWIP

KDJEM1_1-1728029975471.png

  • Use PPP_SUPPORT requires PPPOS_SUPPORT, PPPOE_SUPPORT or PPPOL2TP_SUPPORT turned on.
  • PPP_SUPPORT needs also PPP_IPV4_SUPPORT and/or PPP_IPV6_SUPPORT turned on.

Currently STM32CubeMx do not give possibility to select LwIp Middleware without to have previously selected Ethernet. So, you can enable LWIP only if ETH IP is configured.

 

Thank you.

Kaouthar

To give better visibility on the answered topics, please click on "Best answer" on the reply which solved your issue or answered your question.
Associate III
October 8, 2024

Hi  KDJEM.1
Thanks for your valuable support
I have successfully established a PPP connection and obtained an IP address. However, when I attempted an ICMP ping to Google, I did not receive a successful response. Below is my code snippet; could you check if any changes are needed?
PPOS code snippet:

 

void PPPosClientThread()
{
 osSemaphoreWait(pppos_mutex, PPPOSMUTEX_TIMEOUT);
	pppos_task_started = 1;
	osSemaphoreRelease(pppos_mutex);

 int gsmCmdIter = 0;
 int nfail = 0;
 printf("GSM: Starting Modem thread\r\n");

 char* data = (char*) malloc(BUF_SIZE);

 char PPP_ApnATReq[sizeof(CONFIG_GSM_APN) + 24];
 sprintf(PPP_ApnATReq, "AT+CGDCONT=1,\"IP\",\"%s\"\r\n", CONFIG_GSM_APN);
 cmd_APN.cmd = PPP_ApnATReq;
 cmd_APN.cmdSize = strlen(PPP_ApnATReq);


 //_disconnect(1); // Disconnect if connected // FOR testing

	osSemaphoreWait(pppos_mutex, PPPOSMUTEX_TIMEOUT);
 pppos_tx_count = 0;
 pppos_rx_count = 0;
	gsm_status = GSM_STATE_FIRSTINIT;
	osSemaphoreRelease(pppos_mutex);

	// GSM reset pin functionality required

	enableAllInitCmd();

 while (1)
 {
 while (gsmCmdIter < GSM_InitCmdsSize)
 {
 if (GSM_Init[gsmCmdIter]->skip)
 {
 #if GSM_DEBUG
 infoCommand(GSM_Init[gsmCmdIter]->cmd, GSM_Init[gsmCmdIter]->cmdSize, "Skip command:");
 #endif
 gsmCmdIter++;
 continue;
 }
 if (atCmd_waitResponse(GSM_Init[gsmCmdIter]->cmd,
 GSM_Init[gsmCmdIter]->cmdResponseOnOk, NULL,
 GSM_Init[gsmCmdIter]->cmdSize,
 GSM_Init[gsmCmdIter]->timeoutMs, NULL, 0) == 0)
 {
 // * No response or not as expected, start from first initialization command
 #if GSM_DEBUG
 printf("GSM: Wrong response, restarting...\r\n");
 #endif

 nfail++;
 if (nfail > 20)
 goto exit;

 osDelay(3000);
 gsmCmdIter = 0;
 continue;
 }

 if (GSM_Init[gsmCmdIter]->delayMs > 0)
 osDelay(GSM_Init[gsmCmdIter]->delayMs);
 GSM_Init[gsmCmdIter]->skip = 1;
 if (GSM_Init[gsmCmdIter] == &cmd_Reg)
 GSM_Init[gsmCmdIter]->delayMs = 0;
 // Next command
 gsmCmdIter++;
 }

 #if GSM_DEBUG
		printf("GSM: GSM initialized.\r\n");
		#endif

 osSemaphoreWait(pppos_mutex, PPPOSMUTEX_TIMEOUT);
		if(gsm_status == GSM_STATE_FIRSTINIT)
 {
			osSemaphoreRelease(pppos_mutex);

			// ** After first successful initialization create PPP control block
			ppp = pppos_create(&ppp_netif, ppp_output_callback, ppp_status_cb, NULL);

			if (ppp == NULL)
 {
				#if GSM_DEBUG
				printf("GSM: Error initializing PPPoS\r\n");
				#endif
				break; // end task
			}
		}
		else
 osSemaphoreRelease(pppos_mutex);

		//ppp_set_default(ppp);
 netif_set_default(&ppp_netif);
 //ppp_set_auth(ppp, PPPAUTHTYPE_ANY, "", "");

		osSemaphoreWait(pppos_mutex, PPPOSMUTEX_TIMEOUT);
		gsm_status = GSM_STATE_IDLE;
		osSemaphoreRelease(pppos_mutex);
		ppp_connect(ppp,0);

 while(1)
 {
			// === Check if disconnect requested ===
			osSemaphoreWait(pppos_mutex, PPPOSMUTEX_TIMEOUT);
			if (do_pppos_connect <= 0)
 {
				int end_task = do_pppos_connect;
				do_pppos_connect = 1;
				osSemaphoreRelease(pppos_mutex);
				#if GSM_DEBUG
				printf("\r\n");
				printf("GSM: Disconnect requested.\r\n");
				#endif

				ppp_close(ppp, 0);
				int gstat = 1;
				while (gsm_status != GSM_STATE_DISCONNECTED)
 {
					// Handle data received from GSM
					memset(data, 0, BUF_SIZE);
 int len = UART_Read(data, BUF_SIZE, 30);
					if (len > 0)
 {
						pppos_input_tcpip(ppp, (u8_t*)data, len);
						osSemaphoreWait(pppos_mutex, PPPOSMUTEX_TIMEOUT);
					 pppos_tx_count += len;
						osSemaphoreRelease(pppos_mutex);
					}
					osSemaphoreWait(pppos_mutex, PPPOSMUTEX_TIMEOUT);
					gstat = gsm_status;
					osSemaphoreRelease(pppos_mutex);
				}
				osDelay(1000);

				osSemaphoreWait(pppos_mutex, PPPOSMUTEX_TIMEOUT);
				uint8_t rfoff = gsm_rfOff;
				osSemaphoreRelease(pppos_mutex);
				_disconnect(rfoff); // Disconnect GSM if still connected

				#if GSM_DEBUG
				printf("GSM: Disconnected.\r\n");
				#endif

				gsmCmdIter = 0;
				enableAllInitCmd();
				osSemaphoreWait(pppos_mutex, PPPOSMUTEX_TIMEOUT);
				gsm_status = GSM_STATE_IDLE;
				do_pppos_connect = 0;
				osSemaphoreRelease(pppos_mutex);

				if (end_task < 0) goto exit;

				// === Wait for reconnect request ===
				gstat = 0;
				while (gstat == 0)
 {
					osDelay(100);
					osSemaphoreWait(pppos_mutex, PPPOSMUTEX_TIMEOUT);
					gstat = do_pppos_connect;
					osSemaphoreRelease(pppos_mutex);
				}
				#if GSM_DEBUG
				printf("\r\n");
				printf("GSM: Reconnect requested.\r\n");
				#endif
				break;
			}

			// === Check if disconnected ===
			if (gsm_status == GSM_STATE_DISCONNECTED)
 {
				osSemaphoreRelease(pppos_mutex);
				#if GSM_DEBUG
				printf("\r\n");
				printf("GSM: Disconnected, trying again...\r\n");
				#endif
				ppp_close(ppp, 0);
 _disconnect(1);

				enableAllInitCmd();
				gsmCmdIter = 0;
				gsm_status = GSM_STATE_IDLE;
				osDelay(10000);
				break;
			}
			else
 osSemaphoreRelease(pppos_mutex);

			// === Handle data received from GSM ===
			memset(data, 0, BUF_SIZE);
 int len = UART_Read(data, BUF_SIZE, 50);
			if (len > 0)
 {
 //printf("RX: %d\r\n", len);
 //printf("data :%s\r\n",data);
				pppos_input_tcpip(ppp, (u8_t*)data, len);
				osSemaphoreWait(pppos_mutex, PPPOSMUTEX_TIMEOUT);
			 pppos_tx_count += len;
				osSemaphoreRelease(pppos_mutex);
			}

		} // Handle GSM modem responses & disconnects loop
	} // main task loop

exit:
	if (data) free(data); // free data buffer
	if (ppp) ppp_free(ppp);

	osSemaphoreWait(pppos_mutex, PPPOSMUTEX_TIMEOUT);
	pppos_task_started = 0;
	gsm_status = GSM_STATE_FIRSTINIT;
	osSemaphoreRelease(pppos_mutex);
	#if GSM_DEBUG
	printf("GSM: PPPoS TASK TERMINATED\r\n");
	#endif
	//osThreadTerminate(mythread);
}

 

Ping code snippet:

 

void start_ping_action() {
	//get gateway IP from global net interface
	ip_addr_t gw_addr = ppp_netif.ip_addr;
	uint8_t gw_ip_part_1 = ip4_addr1(&gw_addr);
	//check if DHCP already succeeded by checking against non 0 ip part
	int ret = 0;
	if(gw_ip_part_1 != 0) {
		ip_addr_t target_ping_ip;
		//select target:
		//gateway
		//target_ping_ip = gw_addr;
		//static IPs
		//IP_ADDR4(&target_ping_ip, 192,168,1,180);
		IP_ADDR4(&target_ping_ip, 216,58,213,195); //google.com
		//IP_ADDR4(&target_ping_ip, 8, 8, 8, 8); // Google's DNS

		printf("Starting to ping IP: %d.%d.%d.%d.\r\n", (int)ip4_addr1(&target_ping_ip),
				(int)ip4_addr2(&target_ping_ip), (int)ip4_addr3(&target_ping_ip),
				(int)ip4_addr4(&target_ping_ip));
		if((ret = ping_ip(target_ping_ip)) != PING_ERR_OK) {
			printf("Error while sending ping: %d\r\n", ret);
		}
	}
	//every 4 seconds, start a new ping attempt
	sys_timeout(4000, start_ping_action, NULL);
}

void check_ping_result() {
	ping_result_t res;
	memset(&res, 0, sizeof(res));
	int retcode = 0;
	if((retcode = ping_ip_result(&res)) == PING_ERR_OK) {
 if (res.result_code == PING_RES_ECHO_REPLY) {
 printf("Good ping from %s %u ms\r\n", ipaddr_ntoa(&res.response_ip),
 (unsigned) res.response_time_ms);
 } else {
 printf("Bad ping err %d\r\n", res.result_code);
 }
	} else {
		//printf("No ping result available yet: %d\n", retcode);
	}
	sys_timeout(100, check_ping_result, NULL);
}
/* USER CODE END 0 */

/**
 * @brief The application entry point.
 * @retval int
 */

 


Output logs:

 

UART6 init done
GSM: Starting Modem thread
GSM: AT COMMAND: [AT..]
GSM: AT RESPONSE: [..OK..]
GSM: AT COMMAND: [ATD*99#..]
GSM: AT RESPONSE: [..CONNECT 115200..]
GSM: GSM initialized.
GSM: ppp_status_cb: 0
GSM: status_cb: Connected
GSM: ipaddr = 10.220.50.XXX
GSM: gateway = 10.64.64.XX
GSM: netmask = 255.255.255.255
GSM: LTE Init done
Starting StartDefaultTask
IP:10.220.50.142
Starting to ping IP: 216.58.213.XXX.
Ping timed out
 Bad ping err 0
Starting to ping IP: 216.58.213.XXX.
Ping timed out
 Bad ping err 0
Starting to ping IP: 216.58.213.XXX.
Ping timed out
 Bad ping err 0
Starting to ping IP: 216.58.213.XXX.

 





 

KDJEM.1
ST Technical Moderator
October 8, 2024

Hello @Noushadalik ,

 

>I have successfully established a PPP connection and obtained an IP address. However, when I attempted an ICMP ping to Google, I did not receive a successful response. Below is my code snippet; could you check if any changes are needed?

I think your initial request is answered "Could you explain how to set up PPP in this context(ioc file)?".  Could you please create a new thread for receive response issue.

 

Thank you for your contribution in STCommunity.

Kaouthar

To give better visibility on the answered topics, please click on "Best answer" on the reply which solved your issue or answered your question.