5 years, 7 months ago.

STM32F4-Discovery "RTC error: LSE clock initialization failed."

Hello, I have compiled NTPClient (mbed os 2) example for ARCH-Max board in online compiler and with little modification in Ethernet library am able to successfully run it on STM32F4-Discovery kit too. But when I am using gcc4mbed setup mbed sdk revision 119 - https://github.com/adamgreen/gcc4mbed/tree/gcc5.0-2015-q4_mbed119 with DISCO_F407VG-device, it gives me error "RTC error: LSE clock initialization failed." Please help me to solve this problem.

main.cpp

#include "mbed.h"                   // Basic Library required for onchip peripherals
#include "EthernetInterface.h"      // Ethernet Library 
#include "NTPClient.h"              // Network Time Protocol client Library
//#include "C12832_lcd.h"             // Library for SPI based LCD

/* Create Objects */  

EthernetInterface eth;  // Initialize Ethernet object
NTPClient ntp;          // Initialize NTP object
Serial pc(PC_6,PC_7);
//Serial pc(USBTX,USBRX);
// For Static IP
static const char* mbedIp       = "192.168.1.160";  //IP
static const char* mbedMask     = "255.255.255.0";  // Mask
static const char* mbedGateway  = "192.168.1.1";  //Gateway

int main()
{
    EthernetInterface eth;
     int s = eth.init(); // For DHCP uncomment this line
//    int s = eth.init(mbedIp,mbedMask,mbedGateway); //Use these parameters for static IP
    if( s != NULL )
    {
        pc.printf( "Could not initialise. Will halt!\n\r" );        
        exit( 0 );
    }    
    s = eth.connect();
    if( s != NULL )
    {
        pc.printf( "Could not connect. Will halt!\n\r" );
        exit( 0 );
    }
    else 
    {
        pc.printf( "IP: %s\n\r", eth.getIPAddress() );    
    }
    pc.printf("Connected! IP Address is %s\r\n", eth.getIPAddress());
    pc.printf("Trying to update time...\r\n");
    if (ntp.setTime("0.pool.ntp.org") == 0) { // ntp server
        pc.printf("Set time successfully\r\n");
        while(1) {
            
            time_t ctTime;
            ctTime = time(NULL);
            pc.printf("%s\r\n", ctime(&ctTime));
            pc.printf("Current Time (UTC)");
            wait(1);
        }
    } else {
        pc.printf("NTP Error\r\n");
    }

    eth.disconnect();

    while(1) {
    }
}

1 Answer

5 years, 7 months ago.

Hi Bhavin,

We don't have any knowledge of the gcc4mbed project so we suggest raising your question as an issue under the GitHub project itself:

https://github.com/adamgreen/gcc4mbed/issues

As that project hasn't been updated in a long time, you're likely hitting some incompatibility with the NTPClient and that old version of gcc or the bundled version of Mbed library.

If you want to take this project offline or use gcc, we suggest moving to the Mbed Command Line Interface (CLI) and install GCC version 6 as described in the markdown document:

https://github.com/ARMmbed/mbed-cli

-Ralph, Team Mbed

Accepted Answer