2 years, 4 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.

    #error [NOT_SUPPORTED] LWIP not supported for this target

#include "mbed.h"
#include "EthernetInterface.h"
#include "Mail.h"
#include "cmsis_os.h"

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);
    poUartMail_t *mail;
    mail = uartMail.alloc(0);
    if (mail != NULL) 
        mail->lg = strlen(buf);
        mail->useCrLf = addCrLf;
        memcpy(mail->msg, buf, mail->lg);

// show we're still alive
void blinkThread()
    uartWrite("status Thread started\n", 0, false);

    while (true) {
        led2 = !led2;

// 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("", 1700, buffer, strlen(buffer) );    

// 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) 
        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);
        sprintf(buf, "uartWriter i=%d\n", i);
        printf("%s", buf);

// 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];
    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();
    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

    //start threads
    printf("start uart Thread\n");

    uartWrite("start udp Thread\n", 0, false);

    uartWrite("start udpSrv Thread\n", 0, false);

    uartWrite("start status Thread\n", 0, false);

    while (true)
//        uartWrite("in main\n", 0, false);

        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);



Hi, you need to edit your code or it's hard to read.

Put your code here
posted by Desmond Chen 30 Aug 2019

Hi, <</code>> was missing, sorry for that and thanks for the comment.

posted by serge Bernard 30 Aug 2019
Be the first to answer this question.