| 77 | */ |
| 78 | |
| 79 | void run() { |
| 80 | |
| 81 | // declare an instance of the USART and the stream that we'll use to write to it |
| 82 | |
| 83 | _usart=new MyUsart(57600); |
| 84 | _outputStream=new UsartPollingOutputStream(*_usart); |
| 85 | |
| 86 | // declare the RTC that that stack requires. it's used for cache timeouts, DHCP lease expiry |
| 87 | // and such like so it does not have to be calibrated for accuracy. A few seconds here or there |
| 88 | // over a 24 hour period isn't going to make any difference. Start it ticking at zero which is |
| 89 | // some way back in 2000 but that doesn't matter to us |
| 90 | |
| 91 | Rtc<RtcLsiClockFeature<Rtc32kHzLsiFrequencyProvider>,RtcSecondInterruptFeature> rtc; |
| 92 | rtc.setTick(0); |
| 93 | |
| 94 | // declare an instance of the network stack |
| 95 | |
| 96 | MyNetworkStack::Parameters params; |
| 97 | _net=new MyNetworkStack; |
| 98 | |
| 99 | // the stack requires the RTC |
| 100 | |
| 101 | params.base_rtc=&rtc; |
| 102 | |
| 103 | // It's nice to give the DHCP client a host name because then it'll show up in DHCP |
| 104 | // 'active leases' page. In a home router this is often called 'attached devices' |
| 105 | |
| 106 | params.dhcp_hostname="stm32plus"; |
| 107 | |
| 108 | // subscribe to error events from the network stack |
| 109 | |
| 110 | _net->NetworkErrorEventSender.insertSubscriber(NetworkErrorEventSourceSlot::bind(this,&NetHttpClientTest::onError)); |
| 111 | |
| 112 | // Initialise the stack. This will reset the PHY, initialise the MAC |
| 113 | // and attempt to create a link to our link partner. Ensure your cable |
| 114 | // is plugged in when you run this or be prepared to handle the error |
| 115 | |
| 116 | if(!_net->initialise(params)) |
| 117 | error(); |
| 118 | |
| 119 | // start the ethernet MAC Tx/Rx DMA channels |
| 120 | // this will trigger the DHCP transaction |
| 121 | |
| 122 | if(!_net->startup()) |
| 123 | error(); |
| 124 | |
| 125 | // look up the IP address for www.st.com |
| 126 | |
| 127 | *_outputStream << "Looking up the DNS address for www.st.com\r\n"; |
| 128 | |
| 129 | IpAddress address; |
| 130 | if(!_net->dnsHostnameQuery("www.st.com",address)) { |
| 131 | *_outputStream << "Failed to look up www.st.com\r\n"; |
| 132 | error(); |
| 133 | } |
| 134 | |
| 135 | *_outputStream << "Connecting to www.st.com:80\r\n"; |
| 136 |
no test coverage detected