Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
5 years, 2 months ago.
Nucleo-F429ZI restarts after one hour
Hello, I was experiencing some issues (reboot of the board) when I tested on STM32CubeMx, so I’ve tried mbed.
The program is a pure test based on mbed-os using the online ide. the principle one main thread that starts the others. one thread sending udp messages, one thread printing messages, one thread blinking a led, main displays the threads’ status. All is fine during 1 hour and it looks like the board/program restarts. I check the dhcp lease time. I must miss something and do not know where to search. Any help is welcome. Below is the code if it can help.
You will see commented parts, they are experiments with mailbox inter-thread comms. As program crashed at the very beginning, I removed it for now.
#if !FEATURE_LWIP #error [NOT_SUPPORTED] LWIP not supported for this target #endif #include "mbed.h" #include "EthernetInterface.h" #include "Mail.h" #include "cmsis_os.h" #define PO_MAXMSGSIZE 5 typedef struct { uint8_t lg; bool useCrLf; char msg[PO_MAXMSGSIZE]; } poUartMail_t; //Mail<poUartMail_t, 2> uartMail; DigitalOut led2(LED2); EthernetInterface eth; int eth_stat; UDPSocket sock; // this is currently equivalent to printf void uartWrite(char* buf, int lg, bool addCrLf) { printf("%s", buf); return; /* poUartMail_t *mail; mail = uartMail.alloc(0); if (mail != NULL) { mail->lg = strlen(buf); mail->useCrLf = addCrLf; memcpy(mail->msg, buf, mail->lg); mail->msg[mail->lg]=0; uartMail.put(mail); } */ } // show we're still alive void blinkThread() { uartWrite("status Thread started\n", 0, false); while (true) { led2 = !led2; Thread::wait(500); } } // send some udp message to a PC void udpWriterThread() { char buffer[100]; unsigned int i=0; uartWrite("udp Thread started\n", 0, false); while (1) { sprintf(buffer, "msg %d", i); sock.sendto("192.168.20.110", 1700, buffer, strlen(buffer) ); i++; Thread::wait(500); } } // wait for incoming udp message void udpSrvThread() { int i=0; char buf[100]; SocketAddress adr; while (i>=0) { i = sock.recvfrom(&adr, buf, 100); if (i>=0) buf[i]=0; else buf[0]=0; printf("\n\nudpSrvThread: received %d data[%s] bytes from %s:%d\n\n", i, buf, adr.get_ip_address(), adr.get_port() ); } } // write some data on uart via printf void uartWriterThread() { osEvent evt; poUartMail_t *mail; unsigned int i=0; char buf[100]; printf("uart Thread started\n"); while (1) { /* evt = uartMail.get(); if (evt.status == osEventMail) { mail = (poUartMail_t*)evt.value.p; printf("%s", (char*) mail); uartMail.free(mail); } */ sprintf(buf, "uartWriter i=%d\n", i); printf("%s", buf); i++; Thread::wait(1000); } } // init global variables, start the various threads int main() { Thread threadUdp(osPriorityNormal,1000); Thread threadUdpSrv(osPriorityNormal,1000); Thread threadUart(osPriorityNormal,800); Thread threadStatus(osPriorityNormal,800); const char *ip; char buf[200]; //int bufLg; // setup mail system // setup ethernet char mac[6]; mbed_mac_address(mac); printf("Mac: %02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); eth_stat = eth.connect(); ip=eth.get_ip_address(); printf("connect status: %i\n",eth_stat); printf("IP address is %s\n", ip); printf("MAC address is %s\n", eth.get_mac_address()); // setup UDP sock.open(ð); sock.bind(1800); //start threads printf("start uart Thread\n"); threadUart.start(uartWriterThread); uartWrite("start udp Thread\n", 0, false); threadUdp.start(udpWriterThread); uartWrite("start udpSrv Thread\n", 0, false); threadUdpSrv.start(udpSrvThread); uartWrite("start status Thread\n", 0, false); threadStatus.start(blinkThread); while (true) { // uartWrite("in main\n", 0, false); printf("\n---------------------------------------------\n"); printf("uart Thread state=%ld, stack=%ld, free=%ld, used=%ld, max=%ld\n", threadUart.get_state(), threadUart.stack_size(), threadUart.free_stack(), threadUart.used_stack(), threadUart.max_stack()); sprintf(buf, "udp Thread state=%ld, stack=%ld, free=%ld, used=%ld, max=%ld\n", threadUdp.get_state(), threadUdp.stack_size(), threadUdp.free_stack(), threadUdp.used_stack(), threadUdp.max_stack()); uartWrite(buf, 0, false); sprintf(buf, "udpSRV Thread state=%ld, stack=%ld, free=%ld, used=%ld, max=%ld\n", threadUdpSrv.get_state(), threadUdpSrv.stack_size(), threadUdpSrv.free_stack(), threadUdpSrv.used_stack(), threadUdpSrv.max_stack()); uartWrite(buf, 0, false); sprintf(buf, "status Thread state=%ld, stack=%ld, free=%ld, used=%ld, max=%ld\n", threadStatus.get_state(), threadStatus.stack_size(), threadStatus.free_stack(), threadStatus.used_stack(), threadStatus.max_stack()); uartWrite(buf, 0, false); Thread::wait(1200); } }
Hi, you need to edit your code or it's hard to read.
posted by Desmond Chen 30 Aug 2019Hi, <</code>> was missing, sorry for that and thanks for the comment.
posted by serge Bernard 30 Aug 2019