Ethernet demo for STM32F746NG Discovery

Dependencies:   F7_Ethernet NTPClient mbed-rtos mbed-dev

Committer:
DieterGraef
Date:
Sun Jun 19 16:27:52 2016 +0000
Revision:
0:2110d31ecdf8
Ethernet demo for Discovery STM32F746NG can be used in arm and gcc environment IAC is untested

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DieterGraef 0:2110d31ecdf8 1 #include "mbed.h"
DieterGraef 0:2110d31ecdf8 2 #include "rtos.h"
DieterGraef 0:2110d31ecdf8 3 #include "EthernetInterface.h"
DieterGraef 0:2110d31ecdf8 4 #include "NTPClient.h"
DieterGraef 0:2110d31ecdf8 5 #include <stdio.h>
DieterGraef 0:2110d31ecdf8 6
DieterGraef 0:2110d31ecdf8 7 EthernetInterface eth;
DieterGraef 0:2110d31ecdf8 8
DieterGraef 0:2110d31ecdf8 9 DigitalOut led1(LED1);
DieterGraef 0:2110d31ecdf8 10
DieterGraef 0:2110d31ecdf8 11 int main()
DieterGraef 0:2110d31ecdf8 12 {
DieterGraef 0:2110d31ecdf8 13 NTPClient ntp;
DieterGraef 0:2110d31ecdf8 14 char buff[64];
DieterGraef 0:2110d31ecdf8 15 printf("\n\n*** Ethernet Demo uses NTP to set the clock ***\r\n");
DieterGraef 0:2110d31ecdf8 16
DieterGraef 0:2110d31ecdf8 17 if(eth.init()!=0) //for DHCP Server
DieterGraef 0:2110d31ecdf8 18 {
DieterGraef 0:2110d31ecdf8 19 //if(eth.init(IP,MASK,GATEWAY)!=0) { //for Static IP Address
DieterGraef 0:2110d31ecdf8 20 printf("EthernetInterface Initialize Error \r\n");
DieterGraef 0:2110d31ecdf8 21
DieterGraef 0:2110d31ecdf8 22 while (1)
DieterGraef 0:2110d31ecdf8 23 {
DieterGraef 0:2110d31ecdf8 24 }
DieterGraef 0:2110d31ecdf8 25 }
DieterGraef 0:2110d31ecdf8 26 if(eth.connect()!=0)
DieterGraef 0:2110d31ecdf8 27 {
DieterGraef 0:2110d31ecdf8 28 printf("EthernetInterface Connect Error \r\n");
DieterGraef 0:2110d31ecdf8 29 while (1)
DieterGraef 0:2110d31ecdf8 30 {
DieterGraef 0:2110d31ecdf8 31 }
DieterGraef 0:2110d31ecdf8 32 }
DieterGraef 0:2110d31ecdf8 33 printf("IP Address is %s\r\n", eth.getIPAddress());
DieterGraef 0:2110d31ecdf8 34 printf("NetMask is %s\r\n", eth.getNetworkMask());
DieterGraef 0:2110d31ecdf8 35 printf("Gateway Address is %s\r\n", eth.getGateway());
DieterGraef 0:2110d31ecdf8 36 printf("Ethernet Setup OK\r\n");
DieterGraef 0:2110d31ecdf8 37 printf("Getting time, 10s timeout. \r\n");
DieterGraef 0:2110d31ecdf8 38
DieterGraef 0:2110d31ecdf8 39 if (ntp.setTime("0.uk.pool.ntp.org") == 0)
DieterGraef 0:2110d31ecdf8 40 {
DieterGraef 0:2110d31ecdf8 41 time_t ctTime;
DieterGraef 0:2110d31ecdf8 42 ctTime = time(NULL);
DieterGraef 0:2110d31ecdf8 43 printf("Time is set to : %s \r\n", ctime(&ctTime));
DieterGraef 0:2110d31ecdf8 44 }
DieterGraef 0:2110d31ecdf8 45 else
DieterGraef 0:2110d31ecdf8 46 {
DieterGraef 0:2110d31ecdf8 47 printf("Error getting time \r\n");
DieterGraef 0:2110d31ecdf8 48 }
DieterGraef 0:2110d31ecdf8 49
DieterGraef 0:2110d31ecdf8 50 printf("end of programm\r\n");
DieterGraef 0:2110d31ecdf8 51 while (true) {
DieterGraef 0:2110d31ecdf8 52 led1 = !led1;
DieterGraef 0:2110d31ecdf8 53 Thread::wait(500);
DieterGraef 0:2110d31ecdf8 54 }
DieterGraef 0:2110d31ecdf8 55 }