disable semihost for Arch Pro
Dependencies: EthernetInterface mbed-rtos mbed-src
main.cpp@0:61973ed15ae1, 2014-01-17 (annotated)
- Committer:
- yihui
- Date:
- Fri Jan 17 03:21:00 2014 +0000
- Revision:
- 0:61973ed15ae1
bug fix: Arch Pro hangs up when calling semihost function
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yihui | 0:61973ed15ae1 | 1 | #include "mbed.h" |
yihui | 0:61973ed15ae1 | 2 | #include "EthernetInterface.h" |
yihui | 0:61973ed15ae1 | 3 | |
yihui | 0:61973ed15ae1 | 4 | |
yihui | 0:61973ed15ae1 | 5 | |
yihui | 0:61973ed15ae1 | 6 | Serial uart(USBTX, USBRX); |
yihui | 0:61973ed15ae1 | 7 | DigitalOut led(LED4); |
yihui | 0:61973ed15ae1 | 8 | |
yihui | 0:61973ed15ae1 | 9 | void led_thread(void const *args) |
yihui | 0:61973ed15ae1 | 10 | { |
yihui | 0:61973ed15ae1 | 11 | while (true) { |
yihui | 0:61973ed15ae1 | 12 | led = !led; |
yihui | 0:61973ed15ae1 | 13 | Thread::wait(1000); |
yihui | 0:61973ed15ae1 | 14 | } |
yihui | 0:61973ed15ae1 | 15 | } |
yihui | 0:61973ed15ae1 | 16 | |
yihui | 0:61973ed15ae1 | 17 | int main() { |
yihui | 0:61973ed15ae1 | 18 | Thread thread(led_thread); |
yihui | 0:61973ed15ae1 | 19 | |
yihui | 0:61973ed15ae1 | 20 | uart.baud(115200); |
yihui | 0:61973ed15ae1 | 21 | uart.printf("------------ Ethernet ------------\n"); |
yihui | 0:61973ed15ae1 | 22 | |
yihui | 0:61973ed15ae1 | 23 | EthernetInterface eth; |
yihui | 0:61973ed15ae1 | 24 | eth.init(); //Use DHCP |
yihui | 0:61973ed15ae1 | 25 | eth.connect(); |
yihui | 0:61973ed15ae1 | 26 | printf("IP Address is %s\n", eth.getIPAddress()); |
yihui | 0:61973ed15ae1 | 27 | |
yihui | 0:61973ed15ae1 | 28 | TCPSocketConnection sock; |
yihui | 0:61973ed15ae1 | 29 | sock.connect("mbed.org", 80); |
yihui | 0:61973ed15ae1 | 30 | |
yihui | 0:61973ed15ae1 | 31 | char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n"; |
yihui | 0:61973ed15ae1 | 32 | sock.send_all(http_cmd, sizeof(http_cmd)-1); |
yihui | 0:61973ed15ae1 | 33 | |
yihui | 0:61973ed15ae1 | 34 | char buffer[300]; |
yihui | 0:61973ed15ae1 | 35 | int ret; |
yihui | 0:61973ed15ae1 | 36 | while (true) { |
yihui | 0:61973ed15ae1 | 37 | ret = sock.receive(buffer, sizeof(buffer)-1); |
yihui | 0:61973ed15ae1 | 38 | if (ret <= 0) |
yihui | 0:61973ed15ae1 | 39 | break; |
yihui | 0:61973ed15ae1 | 40 | buffer[ret] = '\0'; |
yihui | 0:61973ed15ae1 | 41 | printf("Received %d chars from server:\n%s\n", ret, buffer); |
yihui | 0:61973ed15ae1 | 42 | } |
yihui | 0:61973ed15ae1 | 43 | |
yihui | 0:61973ed15ae1 | 44 | sock.close(); |
yihui | 0:61973ed15ae1 | 45 | |
yihui | 0:61973ed15ae1 | 46 | eth.disconnect(); |
yihui | 0:61973ed15ae1 | 47 | |
yihui | 0:61973ed15ae1 | 48 | while(1) {} |
yihui | 0:61973ed15ae1 | 49 | } |