Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of SerialPassthrough_GainspanModule_W7500 by
This is a serial-passthrough example using WIZwiki-W7500 and gainspan-WiFi-module.
With this example, I can issue at-command-sets to the WiFi module with WIZwiki-W7500's serial. UART data flow is shown as below.
[PC Serial Terminal] <=> [WIZwiki-W7500's UIART1/DAP] <=> [WIZwiki-W7500's UIART0] <=> [Gainspan WiFi module]
Connected pins between WIZwiki-W7500 and WiFi-module are only 4 pins.
(3.3V, GND, UART-Tx, UART-Rx)
And, here is a picture.
And here is a captures of test logs. Red box is what I issued.
[PS] ASYNC_DEBUG is for internal-debugging like ISR. You can ignore it.
main.cpp@1:95a26b8d2887, 2015-08-21 (annotated)
- Committer:
- SteveKim
- Date:
- Fri Aug 21 06:57:06 2015 +0000
- Revision:
- 1:95a26b8d2887
- Parent:
- 0:98000a7ccec5
Remove useless parts.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| SteveKim | 0:98000a7ccec5 | 1 | #include "mbed.h" |
| SteveKim | 0:98000a7ccec5 | 2 | #include "CBuffer.h" |
| SteveKim | 0:98000a7ccec5 | 3 | |
| SteveKim | 0:98000a7ccec5 | 4 | DigitalOut led1(LED1); |
| SteveKim | 0:98000a7ccec5 | 5 | DigitalOut led4(LED4); |
| SteveKim | 0:98000a7ccec5 | 6 | |
| SteveKim | 0:98000a7ccec5 | 7 | RawSerial pc(USBTX, USBRX); // tx, rx |
| SteveKim | 0:98000a7ccec5 | 8 | RawSerial dev(D1, D0); // tx, rx for WIZwiki-W75000 |
| SteveKim | 0:98000a7ccec5 | 9 | |
| SteveKim | 1:95a26b8d2887 | 10 | #define ASYNC_DEBUG 0 |
| SteveKim | 1:95a26b8d2887 | 11 | |
| SteveKim | 1:95a26b8d2887 | 12 | #if ASYNC_DEBUG |
| SteveKim | 0:98000a7ccec5 | 13 | //////////////////////////////////////////////////////////////////////////////////////////////// |
| SteveKim | 0:98000a7ccec5 | 14 | // mbed Async Debug |
| SteveKim | 0:98000a7ccec5 | 15 | Timeout timer_buffer_debug; |
| SteveKim | 0:98000a7ccec5 | 16 | CircBuffer<char> async_debugbufer(1024); |
| SteveKim | 0:98000a7ccec5 | 17 | |
| SteveKim | 0:98000a7ccec5 | 18 | void print_debugbuffer() |
| SteveKim | 0:98000a7ccec5 | 19 | { |
| SteveKim | 0:98000a7ccec5 | 20 | char c=0; |
| SteveKim | 0:98000a7ccec5 | 21 | while ( async_debugbufer.available() ) { |
| SteveKim | 0:98000a7ccec5 | 22 | async_debugbufer.dequeue(&c); |
| SteveKim | 0:98000a7ccec5 | 23 | pc.putc(c); |
| SteveKim | 0:98000a7ccec5 | 24 | } |
| SteveKim | 0:98000a7ccec5 | 25 | timer_buffer_debug.attach(&print_debugbuffer, 0.1); |
| SteveKim | 0:98000a7ccec5 | 26 | } |
| SteveKim | 0:98000a7ccec5 | 27 | |
| SteveKim | 0:98000a7ccec5 | 28 | #include <stdarg.h> |
| SteveKim | 0:98000a7ccec5 | 29 | static char debug_line[64]; |
| SteveKim | 0:98000a7ccec5 | 30 | void mbed_async_debug(const char *format, ...) |
| SteveKim | 0:98000a7ccec5 | 31 | { |
| SteveKim | 0:98000a7ccec5 | 32 | va_list args; |
| SteveKim | 0:98000a7ccec5 | 33 | |
| SteveKim | 0:98000a7ccec5 | 34 | va_start(args, format); |
| SteveKim | 0:98000a7ccec5 | 35 | |
| SteveKim | 0:98000a7ccec5 | 36 | vsnprintf(debug_line, sizeof(debug_line), format, args); |
| SteveKim | 0:98000a7ccec5 | 37 | int length = strlen(debug_line); |
| SteveKim | 0:98000a7ccec5 | 38 | |
| SteveKim | 0:98000a7ccec5 | 39 | for (int i=0; i<length; i++) |
| SteveKim | 0:98000a7ccec5 | 40 | async_debugbufer.queue(debug_line[i]); |
| SteveKim | 0:98000a7ccec5 | 41 | |
| SteveKim | 0:98000a7ccec5 | 42 | va_end(args); |
| SteveKim | 0:98000a7ccec5 | 43 | } |
| SteveKim | 0:98000a7ccec5 | 44 | |
| SteveKim | 0:98000a7ccec5 | 45 | // mbed Async Debug Print, You can move below line to mbed-src. |
| SteveKim | 0:98000a7ccec5 | 46 | void (*dbg_f)(const char *format, ...); |
| SteveKim | 0:98000a7ccec5 | 47 | extern void (*dbg_f)(const char *format, ...); |
| SteveKim | 0:98000a7ccec5 | 48 | |
| SteveKim | 1:95a26b8d2887 | 49 | #endif |
| SteveKim | 0:98000a7ccec5 | 50 | |
| SteveKim | 0:98000a7ccec5 | 51 | void dev_recv() |
| SteveKim | 0:98000a7ccec5 | 52 | { |
| SteveKim | 0:98000a7ccec5 | 53 | led1 = !led1; |
| SteveKim | 0:98000a7ccec5 | 54 | while(dev.readable()) { |
| SteveKim | 0:98000a7ccec5 | 55 | pc.putc(dev.getc()); |
| SteveKim | 0:98000a7ccec5 | 56 | } |
| SteveKim | 0:98000a7ccec5 | 57 | } |
| SteveKim | 0:98000a7ccec5 | 58 | |
| SteveKim | 0:98000a7ccec5 | 59 | void pc_recv() |
| SteveKim | 0:98000a7ccec5 | 60 | { |
| SteveKim | 0:98000a7ccec5 | 61 | led4 = !led4; |
| SteveKim | 0:98000a7ccec5 | 62 | while(pc.readable()) { |
| SteveKim | 0:98000a7ccec5 | 63 | dev.putc(pc.getc()); |
| SteveKim | 0:98000a7ccec5 | 64 | } |
| SteveKim | 0:98000a7ccec5 | 65 | } |
| SteveKim | 0:98000a7ccec5 | 66 | |
| SteveKim | 0:98000a7ccec5 | 67 | int main() |
| SteveKim | 0:98000a7ccec5 | 68 | { |
| SteveKim | 0:98000a7ccec5 | 69 | for (int i=0; i<10; i++) |
| SteveKim | 0:98000a7ccec5 | 70 | { |
| SteveKim | 0:98000a7ccec5 | 71 | led1 = !led1; |
| SteveKim | 0:98000a7ccec5 | 72 | led4 = !led4; |
| SteveKim | 0:98000a7ccec5 | 73 | wait(0.1); |
| SteveKim | 0:98000a7ccec5 | 74 | } |
| SteveKim | 0:98000a7ccec5 | 75 | |
| SteveKim | 0:98000a7ccec5 | 76 | pc.baud(115200); |
| SteveKim | 0:98000a7ccec5 | 77 | dev.baud(9600); |
| SteveKim | 0:98000a7ccec5 | 78 | |
| SteveKim | 0:98000a7ccec5 | 79 | pc.printf("Serial Passthrough Started. \r\n"); |
| SteveKim | 0:98000a7ccec5 | 80 | |
| SteveKim | 1:95a26b8d2887 | 81 | #if ASYNC_DEBUG |
| SteveKim | 0:98000a7ccec5 | 82 | dbg_f = &mbed_async_debug; |
| SteveKim | 0:98000a7ccec5 | 83 | timer_buffer_debug.attach(&print_debugbuffer, 0.1); |
| SteveKim | 1:95a26b8d2887 | 84 | #endif |
| SteveKim | 1:95a26b8d2887 | 85 | |
| SteveKim | 0:98000a7ccec5 | 86 | pc.attach(&pc_recv, Serial::RxIrq); |
| SteveKim | 0:98000a7ccec5 | 87 | dev.attach(&dev_recv, Serial::RxIrq); |
| SteveKim | 0:98000a7ccec5 | 88 | |
| SteveKim | 0:98000a7ccec5 | 89 | while(1) { |
| SteveKim | 0:98000a7ccec5 | 90 | wait(1); |
| SteveKim | 0:98000a7ccec5 | 91 | } |
| SteveKim | 0:98000a7ccec5 | 92 | } |
