|
|
### USARTS
|
|
|
Serial communication can be acheived using the Miosix drivers for one of the open USARTs. To communicate with the USARTs from your PC you will need a USB-TTL driver, or you can do it via the Discovery's USB cable if the feature is enabled in your Discovery board.
|
|
|
|
|
|
In `arch/common/drivers/serial_stm32.cpp` you can find how
|
|
|
the 3 Usarts that Miosix lets you use are configured.
|
|
|
As a default, in the STM32 Discovery boards Miosix opens 3 USARTs: one *default usart* (`printf()` and `scanf()` are redirected here) and two additional ones.
|
|
|
|
|
|
### Open 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 |
|
|
|
|--------|-----|-----|------|-------|
|
... | ... | @@ -9,34 +12,16 @@ the 3 Usarts that Miosix lets you use are configured. |
|
|
| 2 | PA2 | PA3 | PA0 | PA1 |
|
|
|
| 3 | PB10 | PB11 | PB13 | PB14 |
|
|
|
|
|
|
The default serials for the boards are set to:
|
|
|
The **default USART** for the boards are set to:
|
|
|
|
|
|
| BOARD | DEFAULT <br/>USART | AUXTTY |
|
|
|
| BOARD | DEFAULT | AUXTTY |
|
|
|
| ------- | --------------- | -------- |
|
|
|
|STM32F429zi| 3 | / |
|
|
|
|STM32F407vg| 1 | 2 |
|
|
|
|
|
|
### Usage
|
|
|
### Default USART Configuration
|
|
|
|
|
|
Standard input and output (`printf()` and `scanf()`) are redirected to the [default USART](#default-usart).
|
|
|
|
|
|
Other serial ports can be used as follows, but they have to be configured first.
|
|
|
```cpp
|
|
|
#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`
|
|
|
The **default serial** for a certain board is defined in `miosix/config/arch/<your_arch>/<your_board>/board_settings.h`: here you can find the default baudrate and other related configurations:
|
|
|
|
|
|
```cpp
|
|
|
const unsigned int defaultSerial=1;
|
... | ... | @@ -55,8 +40,9 @@ inside `miosix/arch/<your arch>/<your board>/interfaces-impl/bsp.cpp` |
|
|
defaultSerialFlowctrl ? STM32Serial::RTSCTS : STM32Serial::NOFLOWCTRL)));
|
|
|
```
|
|
|
|
|
|
### Auxtty USART
|
|
|
For the f407vg board, there's also **another serial port** that can be opened:
|
|
|
### Auxtty USART Configuration (STM32F407VG only)
|
|
|
For the *f407vg* board, there's also another serial port, called **auxtty**: you need to remove the comment from the `board_settings.h` in order to use it:
|
|
|
|
|
|
```cpp
|
|
|
//#define AUX_SERIAL "auxtty" UNCOMMENT THIS TO OPEN THE SERIAL
|
|
|
const unsigned int auxSerialSpeed=9600;
|
... | ... | @@ -79,4 +65,34 @@ void bspInit2() |
|
|
#endif //AUX_SERIAL
|
|
|
#endif //WITH_FILESYSTEM
|
|
|
}
|
|
|
``` |
|
|
\ No newline at end of file |
|
|
```
|
|
|
|
|
|
### Usage
|
|
|
|
|
|
**Discovery**
|
|
|
|
|
|
To read or write in the default USART, you can use the standard input and output (`printf()` and `scanf()`).
|
|
|
|
|
|
If other serial ports are open, you can use them like in this example:
|
|
|
```cpp
|
|
|
#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!
|
|
|
|
|
|
**PC**
|
|
|
|
|
|
Once your USB-TTL dongle is attached to the PC, you will need to connect the RX and TX of the dongle to the TX and RX of the decided serial port in your Discovery (**ATTENTION:** RX discovery<-->TX usb dongle and vice-versa).
|
|
|
|
|
|
Then you can open a communication using:
|
|
|
|
|
|
- *Putty* in Windows: Select the *Session* tab on the left panel and select *Serial* as "Connection type". You will need to know the COM port to which the Discovery is attached (you can find it out in *Control Pane > Device Manager*).
|
|
|
- *screen* in Linux: *TODO*
|
|
|
|
|
|
In both cases, you will need to set the correct port and baudrate, and you may need install some drivers for the USB dongle to make things work. |
|
|
\ No newline at end of file |