|
|
### Usage
|
|
|
|
|
|
Standard input and output (`printf()` and `scanf()`) are redirected to the [default USART](#settings).
|
|
|
|
|
|
Other serial ports can be used as follows, but they have to be configured first.
|
|
|
```cpp
|
|
|
#include <fcntl.h>
|
|
|
//...
|
|
|
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, 10, buffer); //Read 10 chars
|
|
|
write(fd, 10, buffer); //Write 10 chars
|
|
|
```
|
|
|
Pay attention to the baudrate at which the used port is set!
|
|
|
|
|
|
### Settings
|
|
|
The default serial for a certain board is set in `miosix/config/arch/<your_arch>/<your_board>/board_settings.h`
|
|
|
|
|
|
```cpp
|
|
|
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
|
|
|
```
|
|
|
For the f407vg board, there's also another serial port that can be opened:
|
|
|
```cpp
|
|
|
//#define AUX_SERIAL "auxtty" UNCOMMENT THIS TO OPEN THE SERIAL
|
|
|
const unsigned int auxSerialSpeed=9600;
|
|
|
const bool auxSerialFlowctrl=false;
|
|
|
```
|
|
|
|
|
|
The default serial port is opened in the *IRQBspInit()* method
|
|
|
inside `miosix/arch/<your arch>/<your board>/interfaces-impl/bsp.cpp`
|
|
|
|
|
|
```cpp
|
|
|
DefaultConsole::instance().IRQset(intrusive_ref_ptr<Device>(
|
|
|
new STM32Serial(defaultSerial,defaultSerialSpeed,
|
|
|
defaultSerialFlowctrl ? STM32Serial::RTSCTS : STM32Serial::NOFLOWCTRL)));
|
|
|
```
|
|
|
|
|
|
While the other serial ports are opened in the *bspInit2()* method of the same file.
|
|
|
```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
|
|
|
}
|
|
|
``` |
|
|
\ No newline at end of file |