-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Description
Port, board and/or hardware
MIMXRT1020_EVK or other MIMXRT board
MicroPython version
MicroPython v1.25.0-preview.371.g27699edce.dirty on 2025-03-09; i.MX RT1020 EVK with MIMXRT1021DAG5A
This is based on PR #16876, which enabled PPP on MIMXRT boards.
Reproduction
Run the below ugly test script thrice without longer delays. It behaves weird at the second call and crashes at the third call. If one waits > 10 seconds between the second and third call, the crash does not happen.
"""
# Establish PPP on ESP32 using SIM7608E.
"""
import time
from network import PPP
from machine import UART, Pin
import socket
import ssl
quiet = False
# Set APN. Specific to your cellular carrier.
apn = "internet.telekom"
baud_rate = 115200
# Create UART object for SIM76xx modem. Start with 115200 baud.
uart = UART(1, baudrate=115200, rxbuf=1024, txbuf=1024, timeout=200, timeout_char=200)
def wait_response(port, response):
port.flush()
resp_msg = None
while msg := port.readline():
if not quiet:
print(msg)
if response and msg.startswith(response):
resp_msg = msg
return resp_msg
def get_http_page(url):
s = socket.socket()
try:
i = socket.getaddrinfo(url, 80)[0][-1]
print('Connecting to socket...')
print(s.connect(i))
print('Send...')
print(s.send(b"GET / HTTP/1.0\r\n\r\n"))
print("Get...")
print(s.recv(4096))
except:
print("Connect & xchange failed")
print('Close socket...')
s.close()
# Ping modem until it is on and ready
timeout = 10
while timeout > 0:
uart.write('AT\r\n')
resp = wait_response(uart, b'AT')
if resp:
break
print(".", end="")
time.sleep(2)
timeout -= 1
else:
print("Unable to establish connection with modem. Try the above again, or potentially check that the pinout is correct")
raise Exception("Modem unavailable")
uart.write('AT+SIMCOMATI\r\n')
wait_response(uart, None)
uart.write('AT+CEREG=0\r\n')
wait_response(uart, None)
# Wait for registration, which may take a while
timeout = 120
while timeout > 0:
uart.write('AT+CEREG?\r\n')
resp = wait_response(uart, b"+CEREG")
# Wait for "+CEREG=0,1"
if resp and resp.strip().split(b',')[1] == b"1":
break
time.sleep_ms(1000)
timeout -= 1
else:
print("Cannot register to the network")
raise Exception("Network unavailable")
# disable unsolicited messaged
uart.write('AT+CGEREP=0\r\n')
wait_response(uart, None)
# switch the baud rate
if baud_rate != 115200:
uart.write('AT+IPR={}\r\n'.format(baud_rate))
wait_response(uart, None)
uart.init(baudrate=baud_rate, rxbuf=1024, txbuf=1024)
# Connect to network and establish PPP
uart.write('AT+CGDCONT=1,"IP","{}"\r\n'.format(apn))
wait_response(uart, None)
# Enable PPP
uart.write('ATD*99#\r\n')
resp = wait_response(uart, b"CONNECT")
if resp:
# Hand modem object off to system PPP module
ppp = PPP(uart)
# GPRS.active(True)
resp = ppp.connect(security=PPP.SEC_PAP, user="t-mobile", key="tm")
# This will print out your IP, subnet, gateway, and dns
print(ppp.ifconfig())
# Check that you can use a socket
addr = socket.getaddrinfo('micropython.org', 80)[0][-1]
print(addr)
get_http_page('micropython.org')
#disconnect
ppp.disconnect()
# stop session
print("Stop PPP session")
uart.write('+++')
wait_response(uart, None)
uart.write('ATH\r\n')
resp = wait_response(uart, None)
# Switch the baud rate back if needed
if baud_rate != 115200:
uart.write('AT+IPR=115200\r\n')
wait_response(uart, None)
# Reset the modem to clear the internal states.
# That fixes the non-connect on the second call.
# uart.write('AT+CRESET\r\n')
# wait_response(uart, None)
print("Test finished")
Expected behavior
Runs fine the same ways all three times.
Observed behavior
Crash. The call stack is below. It is every time the same when it crashes.
Edit: Uncommenting the reset modem code at the end of the script prevents the bug, since then the sequence is like starting from power-on reset. But even without reset and strange internal state of the modem the board should not crash.
Additional Information
Behaves the same strange way with a RP2 PICO W and PPP enabled.
Code of Conduct
Yes, I agree