USARTS
In arch/common/drivers/serial_stm32.cpp
you can find how
the 3 Usarts that Miosix lets you use are configured.
USART | TX | RX | CTS | RTS |
---|---|---|---|---|
1 | PA9 | PA10 | PA11 | PA12 |
2 | PA2 | PA3 | PA0 | PA1 |
3 | PB10 | PB11 | PB13 | PB14 |
The default serials for the boards are set to:
BOARD | DEFAULT USART |
AUXTTY |
---|---|---|
STM32F429zi | 3 | / |
STM32F407vg | 1 | 2 |
Usage
Standard input and output (printf()
and scanf()
) are redirected to the default USART.
Other serial ports can be used as follows, but they have to be configured first.
#include <fcntl.h>
//...
int fd=open("/dev/auxtty",O_RDWR); //open serial port named auxtty
if(fd<0) printf("Cannot open /dev/auxtty");
char buffer[11]; //Buffer is 10 chars + '\0'
read(fd, buffer, 10); //Read 10 chars
write(fd, buffer, 10); //Write 10 chars
Pay attention to the baudrate at which the used port is set!
Default USART
The default serial for a certain board is set in miosix/config/arch/<your_arch>/<your_board>/board_settings.h
const unsigned int defaultSerial=1;
const unsigned int defaultSerialSpeed=19200; //baudrate
const bool defaultSerialFlowctrl=false; //use rts/cts
#define SERIAL_1_DMA //use the DMA
The default serial port is opened in the IRQBspInit() method
inside miosix/arch/<your arch>/<your board>/interfaces-impl/bsp.cpp
DefaultConsole::instance().IRQset(intrusive_ref_ptr<Device>(
new STM32Serial(defaultSerial,defaultSerialSpeed,
defaultSerialFlowctrl ? STM32Serial::RTSCTS : STM32Serial::NOFLOWCTRL)));
Auxtty USART
For the f407vg board, there's also another serial port that can be opened:
//#define AUX_SERIAL "auxtty" UNCOMMENT THIS TO OPEN THE SERIAL
const unsigned int auxSerialSpeed=9600;
const bool auxSerialFlowctrl=false;
This port is opened in the bspInit2() method
inside miosix/arch/<your arch>/<your board>/interfaces-impl/bsp.cpp
void bspInit2()
{
#ifdef WITH_FILESYSTEM
#ifdef AUX_SERIAL
intrusive_ref_ptr<DevFs> devFs=basicFilesystemSetup(SDIODriver::instance());
devFs->addDevice(AUX_SERIAL,
intrusive_ref_ptr<Device>(new STM32Serial(2,auxSerialSpeed,
auxSerialFlowctrl ? STM32Serial::RTSCTS : STM32Serial::NOFLOWCTRL)));
#else //AUX_SERIAL
basicFilesystemSetup(SDIODriver::instance());
#endif //AUX_SERIAL
#endif //WITH_FILESYSTEM
}