Welcome to the second part of the blog(Blink the LEDs of STM32F3-DISCOVERY Board). If you haven’t checked the first one then I recommend you to please go through that.
Okay, talking about this, so in this blog, we are going to build and run our program and will find out the way to install or insert this program inside the hardware(micro-controller).
First, open the terminal and type the command.
$ cargo build
You will find this error while building the code.
This means that our code needs a panic handler to handle the panic error.
To remove this error you need to add the last dependency of the program that is panic-halt.
use panic_halt as _;
Now try again and build the program and you will fall into one more error.
To build the program now, we have to cross-compile our code because the micro-controller has a different architecture than your computer. Cross-compiling in Rust land is as simple as passing an extra
--target flag to
rustc or Cargo.
You should read this to know why we are using a target with our cargo build.
Now my code is accepting this particular target for my architecture so I am using this with my cargo build.
$ cargo build --target thumbv7em-none-eabihf
After this, our program is successfully built but we are still not ready to put our code inside the hardware.
We need some more knowledge about few things before loading the program.
- Memory Layout
- Configuration of linker and target
- Gdb Service
We need to work on all of these to load the code inside the hardware. Don’t worry we have something for this also. Go through this blog and you will pass all these steps easily.
I am sure you have created .cargo/config and memory.x as described in the linked blog and you have gained knowledge about the Openocd and TCP port-3333 we are going to use to connect with the Openocd’s Gdb Server.
By default OpenOCD’s GDB server listens on TCP port 3333 (localhost).
Now open your Openocd and connect to it with port 3333 using the command in another terminal from the same directory.
gdb-multiarch -q -ex "target remote :3333" target/thumbv7em-none-eabihf/debug/led_blink_delay
Note: At last of this command provide the name of your project as mine was led_blink_delay.
Note: Both openocd and gdb must be open from the same directory.
After this command, your Gdb is working and connected to Openocd and your output will look like this in your Gdb terminal.
Great if you have reached till here then you have crossed the major step and finally its time to insert the code inside the hardware(stm32f3-discovery board). For that use a simple command.
You will see something like this on your terminal which means your code is loaded successfully. Now your program is inside the hardware ie: stm32f3-discovery board.
Now you just need one more command to see the magic. Put command “continue” or “c“.
This will block your terminal as the program is now inside the infinite loop playing with the LEDs. Now if you see your board, your led 3(RED) and led 4(BLUE) are blinking with some delay.
Here is the output
This is the end of our blog. I hope now you are able to blink leds of stm32f3-discovery board. If you face any error or issue then you can create an issue on my git repository and I will be happy to help you. Thanks for reading.
If you want to read more content like this? Subscribe to Rust Times Newsletter and receive insights and latest updates, bi-weekly, straight into your inbox. Subscribe to Rust Times Newsletter: https://bit.ly/2Vdlld7.