|
|
|
|
|
This is the third tutorial and here you will see how to establish serial communication between the microcontroller and your PC.
|
|
This is the third tutorial and here you will see how to establish serial communication between the microcontroller and your PC.
|
|
|
|
|
|
More details are explained in the [Serial Communication](Serial-Communication) page.
|
|
More details are explained in the [Serial Communication](Serial-Communication) page.
|
|
|
|
|
|
## Introduction
|
|
## Introduction
|
|
|
|
|
|
If you want to visualize the data you read from the sensor on your PC, you can use the _TRACE()_ function: it is basically a _printf()_ during the debugging, but it performs no action when the production code is released. You can use it as normal _printf()_ (it has the same signature). In fact the _printf()_ usage is almost prohibited by our [coding guidelines](Coding-Guidelines).
|
|
If you want to visualize the data you read from the sensor on your PC, you can use the _TRACE()_ function: it is basically a _printf()_ during the debugging, but it performs no action when the production code is released. You can use it as normal _printf()_ (it has the same signature). In fact the _printf()_ usage is almost prohibited by our [coding guidelines](Coding-Guidelines).
|
|
Everytime you call _TRACE()_ in your code, the output data is redirected to the default serial port of the microcontroller. The default serial port for the STM32F407VG microcontroller is the `USART3` (default value set by Miosix), which corresponds to the GPIOs `PB10` (TX) and `PB11` (RX). The baud rate is by default set to `19200`.
|
|
Everytime you call _TRACE()_ in your code, the output data is redirected to the default serial port of the microcontroller. The default serial port for the STM32F407VG microcontroller is the `USART3` (default value set by Miosix), which corresponds to the GPIOs `PB10` (TX) and `PB11` (RX). The baud rate is by default set to `19200`.
|
|
|
|
|
... | @@ -29,14 +29,37 @@ Consider that if you are using a different board, it may be possible that its US |
... | @@ -29,14 +29,37 @@ Consider that if you are using a different board, it may be possible that its US |
|
|
|
|
|
## Create your entrypoint
|
|
## Create your entrypoint
|
|
|
|
|
|
Here we will write an entrypoint that uses the _TRACE()_ function in order to send data to the PC.
|
|
Here we will write an entrypoint that uses the _TRACE()_ function in order to send data to the PC.
|
|
In `src/entrypoints` add a file called `hello-skyward`.cpp`.
|
|
In `src/entrypoints` add a file called `hello-skyward.cpp`.
|
|
Inside it you can put your code:
|
|
Inside it you can put your code:
|
|
|
|
|
|
```cpp
|
|
```cpp
|
|
|
|
/* Copyright (c) <YEAR_HERE> Skyward Experimental Rocketry
|
|
|
|
* Author: <YOUR_NAME_HERE>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
#include <Common.h>
|
|
#include <Common.h>
|
|
|
|
|
|
using namespace miosix;
|
|
using namespace miosix;
|
|
|
|
using namespace Boardcore;
|
|
|
|
|
|
int main()
|
|
int main()
|
|
{
|
|
{
|
... | @@ -52,14 +75,37 @@ int main() |
... | @@ -52,14 +75,37 @@ int main() |
|
}
|
|
}
|
|
```
|
|
```
|
|
|
|
|
|
|
|
|
|
#### Note
|
|
#### Note
|
|
You can also send data from the PC to the microcontroller.
|
|
You can also send data from the PC to the microcontroller.
|
|
This can be done through the _scanf()_ function:
|
|
This can be done through the _scanf()_ function:
|
|
|
|
|
|
```cpp
|
|
```cpp
|
|
|
|
/* Copyright (c) <YEAR_HERE> Skyward Experimental Rocketry
|
|
|
|
* Author: <YOUR_NAME_HERE>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
#include <Common.h>
|
|
#include <Common.h>
|
|
|
|
|
|
using namespace miosix;
|
|
using namespace miosix;
|
|
|
|
using namespace Boardcore;
|
|
|
|
|
|
int main()
|
|
int main()
|
|
{
|
|
{
|
... | @@ -78,29 +124,17 @@ int main() |
... | @@ -78,29 +124,17 @@ int main() |
|
```
|
|
```
|
|
|
|
|
|
## Compile with SBS
|
|
## Compile with SBS
|
|
You should also add the entrypoint configuration to `sbs.conf`.
|
|
You should also add the entrypoint configuration to `CMakeLists.txt`:
|
|
|
|
|
|
First of all we need an `srcfiles` section in which we add the `Debug.cpp` file, on which the _TRACE()_ function depends:
|
|
```cmake
|
|
```config
|
|
add_executable(hello-skyward src/entrypoints/hello-skyward.cpp)
|
|
[trace-include]
|
|
sbs_target(hello-skyward stm32f407vg_stm32f4discovery)
|
|
Type: srcfiles
|
|
|
|
Files: src/shared/Debug.cpp
|
|
|
|
```
|
|
```
|
|
|
|
|
|
Also, in order for the _TRACE()_ function to act as a normal _printf()_, `DEBUG` has to be defined. We can define it in `sbs.conf` by inserting `-DDEBUG` in the defines section of our entrypoint configuration.
|
|
## Run it!
|
|
Notice that all the defines specified in `sbs.conf` start with `-D` followed by the string corresponding to the required define: if we want to define `MYDEF`, we will specify `-DMYDEF` in the SBS configuration file.
|
|
|
|
|
|
|
|
Moreover the _trace-include_ include is needed in order to compile also `Debug.cpp`, on which the _TRACE()_ macro depends.
|
|
In order for the _TRACE()_ function to act as a normal _printf()_, we need to compile the entrypoint with debug enabled. To enable debug you can add the option `-d` when you build with the SBS script:
|
|
|
|
|
|
```config
|
|
```sh
|
|
[hello-skyward]
|
|
./sbs -d -f test-led-driver
|
|
Type: board
|
|
``` |
|
BoardId: stm32f407vg_stm32f4discovery
|
|
\ No newline at end of file |
|
BinName: hello-skyward
|
|
|
|
Include: %trace-include
|
|
|
|
Defines: -DDEBUG
|
|
|
|
Main: hello-skyward
|
|
|
|
```
|
|
|
|
|
|
|
|
## Run it!
|
|
|
|
Same as before: build the entrypoint with `python sbs -b hello-skyward` and [flash the binary on the board](Flashing-on-a-Target-Board). |
|
|
|
\ No newline at end of file |
|
|