At a Glance
...
- Our development environment
- STM32F072B Discovery board + mini-USB cable
- UART to USB adapter
Info |
---|
If you aren't sure where to get a Discovery board or UART adapter, ask a lead! We have a few in the bay. Otherwise, feel free to just skip the parts that involve UART or STM32. |
Hello World
With our development environment set up, let's make a basic project!First, let's set up our hardware:
Hardware (Optional)
For now, we'll be using STM32 Discovery boards. If you've heard of an Arduino, the Discovery boards are very similar in intention. They're just plug-and-play, no setup required.
To use a Discovery board, just connect the mini-USB cable to the header marked "USB ST-LINK" on the Discovery board and plug the other end into your computer.
For the UART to USB adapter, plug each wire of the adapter into its corresponding pin on the Discovery board.
UART Adapter | Discovery Board |
---|---|
RX (Yellow) | PB6 (TX) |
TX (Orange) | PB7 (RX) |
GND (Black) | GND |
Feature Branches - Git
Code Block |
---|
# Double check - make sure you're in vagrant
vagrant ssh
# Should say "vagrant"
whoami
cd ~/shared/firmware
# Create a new branch off of master
git checkout master
git checkout -b wip_getting_started |
...
Running Code - Hello World
Now, it's time to build and run the project! First, let's try it on x86.
Code Block |
---|
# Build and run the project on x86 make run PROJECT=hello_world PLATFORM=x86 |
Neat! Hopefully, you saw "Hello World" appear in your terminal. Now, if you have the hardware set up, let's try it on STM32!
Running on STM32 - Hello World
Warning |
---|
This will only work if you have the hardware set up properly and you're in the vagrant box! If it isn't working, be sure to ask a lead for help! |
In a new terminal (or tmux pane), open a serial terminal:
Code Block |
---|
# If no device is found, try /dev/tty[tab] or /dev/serial/[tab] where [tab] represents pressing the tab key minicom -D /dev/ttyACM0 |
Back to the old terminal:
Code Block |
---|
# Build and run the project on x86
make run PROJECT=hello_world PLATFORM=x86
# Build and run the project on STM32F0xx (discovery board)
# PLATFORM=stm32f0xx is implied
# PROBE=cmsis is normally implied, override for Discovery boards
make program PROJECT=hello_world PROBE=stlink-v2 |
You If you look at minicom, you should see "hello worldHello World" appear twice - once when running on x86, and once in minicom
! . Try changing the text!
Building for STM32 - Hello World
If you don't have access to hardware, no problem! You can still build the project for STM32. It should compile successfully.
Code Block |
---|
# Just build the project for STM32
make build PROJECT=hello_world |
As you can see, our build system and HAL (hardware abstraction layer) allow us to build applications that can run natively on mutliple platforms. In this case, LOG_DEBUG
is targeted to stdout
on x86 (standard output) and UART1
on STM32. This makes testing a lot easier, and allows us to develop application code even without access to the hardware.
...
With your code workring, we want to make sure your code matches our Coding Standards. We use two tools for that:
...
- Basic Git workflow
- Creating a new projectPrinting over UART
- HAL support for x86 and STM32
- Code cleanliness