cancel
Showing results for 
Search instead for 
Did you mean: 

Assistance Required: Verifying PPPoS Code for STM32F407 LTE Modem Internet Connectivity

Noushadalik
Associate III

Hello,
I am trying to integrate internet connectivity on the STM32F407 using an LTE modem via the PPPoS protocol(UART). I've successfully established a PPPoS (iusing Ethernet LWIP) connection and obtained the modem IP on the STM32F407. Could you please verify my PPPoS code to ensure it's sufficient for internet access on the STM32F407? My code snippet is provided below.

int LTE_pppos()
{
tcpip_init( NULL, NULL );
enableAllInitCmd();
ppp = pppos_create(&ppp_netif, ppp_output_callback, ppp_status_cb, NULL);
netif_set_default(&ppp_netif);
ppp_connect(ppp,0);
}
static void ppp_status_cb(ppp_pcb *pcb, int err_code, void *ctx)
{
	struct netif *pppif = ppp_netif(pcb);
	LWIP_UNUSED_ARG(ctx);

    printf("GSM: ppp_status_cb: %d\r\n", err_code);

	switch(err_code) 
    {
		case PPPERR_NONE: 
        {
			#if GSM_DEBUG
			printf("GSM: status_cb: Connected\r\n");
			#if PPP_IPV4_SUPPORT
			printf("GSM:    ipaddr    = %s\r\n", ipaddr_ntoa(&pppif->ip_addr));
			printf("GSM:    gateway   = %s\r\n", ipaddr_ntoa(&pppif->gw));
			printf("GSM:    netmask   = %s\r\n", ipaddr_ntoa(&pppif->netmask));
			#endif

			if (netif_is_link_up(&ppp_netif)) {
			    netif_set_up(&ppp_netif);
			} else {
			    netif_set_down(&ppp_netif);
			} // Bring up the Ethernet interface with new IP

			#if PPP_IPV6_SUPPORT
			printf("GSM: ip6addr   = %s", ip6addr_ntoa(netif_ip6_addr(pppif, 0)));
			#endif
			#endif
			osSemaphoreWait(pppos_mutex, PPPOSMUTEX_TIMEOUT);
			gsm_status = GSM_STATE_CONNECTED;
			osSemaphoreRelease(pppos_mutex);
			break;
		}
	,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

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


After successfully connecting to PPPos, I pinged Google using ICMP but did not receive a response. Below is my 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;
		//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);
}

 Output logs:

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.







0 REPLIES 0