steeven lee
/
NUCLEO_uart_flow_control
Revision 0:77572dc5bb31, committed 2015-05-09
- Comitter:
- steeven
- Date:
- Sat May 09 16:00:37 2015 +0000
- Commit message:
- init
Changed in this revision
diff -r 000000000000 -r 77572dc5bb31 BreathLed.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BreathLed.lib Sat May 09 16:00:37 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/steeven/code/BreathLed/#13c83a6b336f
diff -r 000000000000 -r 77572dc5bb31 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat May 09 16:00:37 2015 +0000 @@ -0,0 +1,58 @@ +#include "mbed.h" +#include "BreathLed/BreathLed.h" +#include "PeripheralPins.h" + +using namespace steeven; + +BreathLed led1(LED1); + +Serial pc(USBTX, USBRX); +Serial uart1(PA_9, PA_10); + +/** NUCLEO_STM32F411RE uart hardware flow control with RTS/CTS +* +* How to test: +* 0. Modify serial_api.c, change flow control type from NONE to: +* UartHandle.Init.HwFlowCtl = UART_HWCONTROL_RTS_CTS; +* 1. Continuesly send or paste large data to USB console +* 2. Connect CTS(PA_11) pin to GND, data should sent with writable(). +* No need to connect a peer uart device. +*/ + + +int main() { + char ch; + int i = 0; + int j = 0; + led1.loop(0.5, 0.2); + pc.baud(115200); + PinMap rts = {PA_12, UART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)}; + PinMap cts = {PA_11, UART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)}; + pin_function(rts.pin, rts.function); + pin_function(cts.pin, cts.function); + pin_mode(rts.pin, PullUp); //output, uart request peer to send + pin_mode(cts.pin, PullUp); //input, peer send 0 to allow uart send + + uart1.baud(115200); + + pc.printf("hello world!\n"); + while (1) { + if (pc.readable()) { + i++; + ch = pc.getc(); + if (uart1.writeable()) { + uart1.putc(ch); + } else { + pc.printf("%d/%d ", i,j); //if + } + if (i%50 == 49){ + pc.printf("\r\n%d lost: %d \r\n", i,i-j); + } + } + if (uart1.readable()) { + ch = uart1.getc(); + j++; + } + } +} +
diff -r 000000000000 -r 77572dc5bb31 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sat May 09 16:00:37 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/8ab26030e058 \ No newline at end of file