for hank
Dependencies: mbed-STM32F103C8T6_new
main.cpp@3:30d61fa10b98, 2020-04-18 (annotated)
- Committer:
- hankzhang
- Date:
- Sat Apr 18 06:31:52 2020 +0000
- Revision:
- 3:30d61fa10b98
- Parent:
- 2:f48b0967b6cc
- Child:
- 4:864bb8bde75c
Update for UART Serail send/recv data
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
techneo | 0:217105958c2d | 1 | #include "mbed.h" |
bbw | 1:0fe432e5dfc4 | 2 | #include "stm32f103c8t6.h" |
hankzhang | 3:30d61fa10b98 | 3 | #include "string.h" |
hankzhang | 3:30d61fa10b98 | 4 | #include "main.h" |
bbw | 1:0fe432e5dfc4 | 5 | |
hankzhang | 2:f48b0967b6cc | 6 | DigitalOut led1(PC_13); |
techneo | 0:217105958c2d | 7 | |
hankzhang | 3:30d61fa10b98 | 8 | //Serial pc(PB_10,PB_11); |
hankzhang | 3:30d61fa10b98 | 9 | |
hankzhang | 3:30d61fa10b98 | 10 | UARTSerial *_serial; |
bbw | 1:0fe432e5dfc4 | 11 | |
hankzhang | 3:30d61fa10b98 | 12 | UARTSerial debug_uart(PB_10, PB_11, 115200); |
hankzhang | 3:30d61fa10b98 | 13 | UARTSerial wifi_uart(PA_2, PA_3, 115200); |
hankzhang | 3:30d61fa10b98 | 14 | |
hankzhang | 3:30d61fa10b98 | 15 | char rxBuf[64]; |
hankzhang | 3:30d61fa10b98 | 16 | int i = 0; |
hankzhang | 3:30d61fa10b98 | 17 | |
hankzhang | 3:30d61fa10b98 | 18 | ATCmdParser *_parser; |
hankzhang | 2:f48b0967b6cc | 19 | |
hankzhang | 2:f48b0967b6cc | 20 | void led2_thread() { |
hankzhang | 2:f48b0967b6cc | 21 | while (true) { |
hankzhang | 3:30d61fa10b98 | 22 | debug_uart.write("led2+++", 6); |
hankzhang | 2:f48b0967b6cc | 23 | thread_sleep_for(4000); |
techneo | 0:217105958c2d | 24 | } |
techneo | 0:217105958c2d | 25 | } |
techneo | 0:217105958c2d | 26 | |
hankzhang | 3:30d61fa10b98 | 27 | void debug_uart_recv() { |
hankzhang | 3:30d61fa10b98 | 28 | //rxBuf[i++] = debug_uart.getc(); |
hankzhang | 3:30d61fa10b98 | 29 | debug_uart.read(rxBuf, 5); |
hankzhang | 2:f48b0967b6cc | 30 | } |
bbw | 1:0fe432e5dfc4 | 31 | |
hankzhang | 2:f48b0967b6cc | 32 | void led0_thread() { |
hankzhang | 3:30d61fa10b98 | 33 | int length; |
hankzhang | 3:30d61fa10b98 | 34 | while (1) { |
hankzhang | 3:30d61fa10b98 | 35 | if(debug_uart.readable()) |
hankzhang | 3:30d61fa10b98 | 36 | { |
hankzhang | 3:30d61fa10b98 | 37 | length = debug_uart.read(rxBuf, sizeof(rxBuf)); |
hankzhang | 3:30d61fa10b98 | 38 | debug_uart.write(rxBuf, length); |
hankzhang | 3:30d61fa10b98 | 39 | wifi_uart.write(rxBuf, length); |
hankzhang | 3:30d61fa10b98 | 40 | debug_uart.write("111\r",4); |
hankzhang | 3:30d61fa10b98 | 41 | } |
hankzhang | 3:30d61fa10b98 | 42 | if(wifi_uart.readable()) |
hankzhang | 3:30d61fa10b98 | 43 | { |
hankzhang | 3:30d61fa10b98 | 44 | length = wifi_uart.read(rxBuf, sizeof(rxBuf)); |
hankzhang | 3:30d61fa10b98 | 45 | debug_uart.write(rxBuf, length); |
hankzhang | 3:30d61fa10b98 | 46 | debug_uart.write("222\r",4); |
hankzhang | 3:30d61fa10b98 | 47 | |
hankzhang | 3:30d61fa10b98 | 48 | } |
hankzhang | 3:30d61fa10b98 | 49 | wait(0.5); |
bbw | 1:0fe432e5dfc4 | 50 | } |
bbw | 1:0fe432e5dfc4 | 51 | } |
hankzhang | 3:30d61fa10b98 | 52 | |
hankzhang | 3:30d61fa10b98 | 53 | |
hankzhang | 2:f48b0967b6cc | 54 | int main() { |
hankzhang | 3:30d61fa10b98 | 55 | int length; |
hankzhang | 3:30d61fa10b98 | 56 | led1 = 1; |
hankzhang | 3:30d61fa10b98 | 57 | |
hankzhang | 3:30d61fa10b98 | 58 | wait(2); |
hankzhang | 3:30d61fa10b98 | 59 | |
hankzhang | 3:30d61fa10b98 | 60 | //debug_uart.printf("hello world\r\n"); |
hankzhang | 3:30d61fa10b98 | 61 | debug_uart.write("hello world",11); |
hankzhang | 2:f48b0967b6cc | 62 | |
hankzhang | 3:30d61fa10b98 | 63 | WIFI_PWREN = 1; |
hankzhang | 3:30d61fa10b98 | 64 | #if 0 |
hankzhang | 3:30d61fa10b98 | 65 | while(1){ |
hankzhang | 3:30d61fa10b98 | 66 | if(debug_uart.readable()) |
hankzhang | 3:30d61fa10b98 | 67 | { |
hankzhang | 3:30d61fa10b98 | 68 | length = debug_uart.read(rxBuf, sizeof(rxBuf)); |
hankzhang | 3:30d61fa10b98 | 69 | debug_uart.write(rxBuf, length); |
hankzhang | 3:30d61fa10b98 | 70 | debug_uart.write("test",4); |
hankzhang | 3:30d61fa10b98 | 71 | } |
hankzhang | 3:30d61fa10b98 | 72 | wait(0.5); |
hankzhang | 3:30d61fa10b98 | 73 | } |
hankzhang | 3:30d61fa10b98 | 74 | //wifi_debug(); |
hankzhang | 3:30d61fa10b98 | 75 | |
hankzhang | 3:30d61fa10b98 | 76 | |
hankzhang | 3:30d61fa10b98 | 77 | _serial = new UARTSerial(PA_2, PA_3, 115200); |
hankzhang | 3:30d61fa10b98 | 78 | _parser = new ATCmdParser(_serial); |
hankzhang | 3:30d61fa10b98 | 79 | _parser->debug_on( 1 ); |
hankzhang | 3:30d61fa10b98 | 80 | _parser->set_delimiter("\r\n"); |
hankzhang | 3:30d61fa10b98 | 81 | |
hankzhang | 3:30d61fa10b98 | 82 | debug_uart.printf("\nATCmdParser: Retrieving model"); |
hankzhang | 3:30d61fa10b98 | 83 | _parser->send("model\\r"); |
hankzhang | 3:30d61fa10b98 | 84 | |
hankzhang | 3:30d61fa10b98 | 85 | _parser->recv("%s", model); |
hankzhang | 3:30d61fa10b98 | 86 | debug_uart.printf("model:%s", model); |
hankzhang | 3:30d61fa10b98 | 87 | #endif |
hankzhang | 3:30d61fa10b98 | 88 | |
hankzhang | 2:f48b0967b6cc | 89 | Thread thread0(osPriorityNormal, 512, nullptr, nullptr); |
hankzhang | 3:30d61fa10b98 | 90 | //Thread thread1(osPriorityNormal, 512, nullptr, nullptr); |
hankzhang | 3:30d61fa10b98 | 91 | //Thread thread2(osPriorityNormal, 512, nullptr, nullptr); |
hankzhang | 2:f48b0967b6cc | 92 | |
hankzhang | 2:f48b0967b6cc | 93 | thread0.start(led0_thread); |
hankzhang | 2:f48b0967b6cc | 94 | |
hankzhang | 3:30d61fa10b98 | 95 | //wifi_serial.printf("model\r\n"); |
hankzhang | 3:30d61fa10b98 | 96 | //thread1.start(led1_thread); |
hankzhang | 3:30d61fa10b98 | 97 | //thread2.start(led2_thread); |
hankzhang | 3:30d61fa10b98 | 98 | while(1) |
hankzhang | 3:30d61fa10b98 | 99 | { |
hankzhang | 3:30d61fa10b98 | 100 | debug_uart.write("--main--\r\n",10); |
hankzhang | 3:30d61fa10b98 | 101 | wait(3); |
bbw | 1:0fe432e5dfc4 | 102 | } |
hankzhang | 3:30d61fa10b98 | 103 | |
hankzhang | 2:f48b0967b6cc | 104 | } |