8 years, 11 months ago.

Serial Flow Control

Hi,

I've been having difficulty implementing RTSCTS flow control on the STMF401RE on one of my own boards. I've followed the serial base documentation but I'm getting a compiler error when I try to build the program.

Flow Control Code

#define DEVICE_SERIAL_FC true

#define BC_VREGEN   PA_4
#define BC_CTS      PA_0
#define BC_RTS      PA_1
#define BC_RST      PA_5
#define BC_TX       PA_3
#define BC_RX       PA_2

#include "mbed.h"

/*Bluetooth*/
DigitalOut bt_reset(BC_RST);
DigitalOut bt_pair(BC_VREGEN);
Serial bt(BC_RX,BC_TX);

void bt_init(){
    bt_reset=0;
    wait(.1);
    bt_reset=1;
    wait(.1);
    bt.baud(9600);
    bt.set_flow_control(Serial::RTSCTS,BC_RTS,BC_CTS);
}
int main() {
    bt_init();
    while(1) {
        sleep();
    }
}

If I comment out the following line it compiles just fine:

    bt.set_flow_control(Serial::RTSCTS,BC_RTS,BC_CTS);

I'm quite certain the STM32F401RE has hardware handshaking on UART2, which is the UART that I'm using here. Looking at a previously answered question, the syntex appears fine. What am I doing wrong here?

Today I saw a pull-request on mbedmicro on github for universal flow_control support on STM32 devices. https://github.com/mbedmicro/mbed/pull/2095

Certainly it comes late for your project, but for further development it should be available soon. @Erik, does your table updates automatically, or is it mantained by manual work?

posted by Ad Bam 06 Jul 2016

1 Answer

8 years, 11 months ago.

Simple answer: It is not implemented for the F401 (and pretty much any other target).

Accepted Answer

Is there any (easy) way to make it work ?

posted by Maurizio Banfi 02 Jul 2015

You can add it yourself either by writing own serial code (using if you want the ST driver code), or by modifying the mbed-src code (you can delete your mbed lib and import one with that name for full source code). If that is easy is a personal question :P

posted by Erik - 02 Jul 2015

I wish I knew that earlier. Looking at the Serial Handbook page it doesn't seem to be documented that it wasn't implemented. Was it recorded somewhere? I guess that explains why the serial base header file had it set aside:

#if DEVICE_SERIAL_FC
    /** Set the flow control type on the serial port
     *
     *  @param type the flow control type (Disabled, RTS, CTS, RTSCTS)
     *  @param flow1 the first flow control pin (RTS for RTS or RTSCTS, CTS for CTS)
     *  @param flow2 the second flow control pin (CTS for RTSCTS)
     */
    void set_flow_control(Flow type, PinName flow1=NC, PinName flow2=NC);
#endif

I guess I'll check STM32CubeF4 for the relevant driver code and examples.

posted by Krzysztof Sitko 02 Jul 2015

That is not really documented no. Thats why as a personal project I am looking at retrieving this data from the mbed source code automatically. Example: https://developer.mbed.org/media/uploads/Sissors/supported_rbgODUW.htm (You can click on column headers, serial_FC is missing here indeed, also got a version where that one was added). (Yes it is ugly, since I started on that I feel sorry for everyone who has to use CSS). Hopefully something like that is one day added to the platform page.

posted by Erik - 02 Jul 2015

Thanks Erik, Your link is really helpful for figuring out which features are enabled. Any chance you could sticky that somewhere or something? I've love to be able to refer to it in the future.

posted by Krzysztof Sitko 03 Jul 2015

It is on the todo list if it is a bit more mature :). Shouldn't take much longer, first version will probably have less columns (only important ones: No need for example to have both PortIn, PortOut and PortInOut there), will include the ARM core (M0, M3, etc), and I think also the experimental code which uses the scatter files to get the SRAM and Flash sizes.

(If you have any idea how I make the column header lines also at an angle it would be appreciated :D).

posted by Erik - 04 Jul 2015

Check out this example for setting up angled header lines.

posted by Krzysztof Sitko 10 Jul 2015