Firs of all read The Embedded Rust Book/Hardware!
Will debug with the help of ST-Link included into STM32F0DISCOVERY
evaluation board. To program and debug stm32f042f4p6
with this board remove the 2 jumpers from CN2 (see en.DM00050135.pdf, page 16):
STM32F0DISCOVERY CN3/SWD connector |
STM32F042F4P6 |
---|---|
1 - VDD_TARGET - VDD from target MCU | 16 - VDD and 5 - VDDA |
2 - SWCLK - SWD clock | 20 - PA14 |
3 - GND - Ground | 15 - GND |
4 - SWDIO - SWD data input/output | 19 - PA13 |
5 - NRST - RESET of target MCU | 4 - NRST |
6 - SWO - Reserved | NC |
- Add
udev
rule for theSTMicroelectronics ST-LINK/V2
:
$ sudo vim /etc/udev/rules.d/99-stlink.rules
-------
ATTRS{idVendor}=="0483", ATTRS{idProduct}=="3748", MODE="0666"
-------
$ sudo udevadm trigger
- Build project with one of the following commands:
$ cargo build
$ cargo build --target=thumbv6m-none-eabi
$ cargo build --target=thumbv6m-none-eabi --release
$ cargo +nightly build --target=thumbv6m-none-eabi --release --features nightly
- Run
openocd -f openocd.cfg
- In another terminal run
arm-none-eabi-gdb -x openocd.gdb target/thumbv6m-none-eabi/release/kroneum-bin
| Micro USB
| STM32F042F4P6
|
| ------------------------------------:|
| 1 - VBUS + | NC |
| 2 - DATA - | 09 - PA11 - USB DM |
| 3 - DATA + | 10 - PA12 - USB DP |
| 4 - ID | NC |
| 5 - GND | 15 - GND |
Pin 1 (PB8-BOOT0) should be connected to VDD\VDDA (+3.3V).
Also make sure you read documentation for cargo-binutils and dfu-util.
- Build binary with:
$ cargo build --release -p kroneum-bin
$ $(find $(rustc --print sysroot) -name llvm-objcopy) ./target/thumbv6m-none-eabi/release/kroneum-bin -O binary ./target/fw-upload.bin
Or call the following command from the `./bin` subfolder
$ cargo objcopy --bin kroneum-bin --release -- -O binary ../target/fw-upload.bin
- Upload binary with:
$ dfu-util -a 0 -d 0483:df11 -s 0x08000000:leave -D ./target/fw-upload.bin
- Backup binary with:
$ dfu-util -U fw-from-device.bin -a 0 -d 0483:df11
-
Steps 1-3 above can be replaced with just
$ ./scripts/flash.sh
. -
If binary is too large GDB may fail so try to use
--release
flag withcargo build
. -
To reload program on the MCU use
monitor reset halt
-
RTC & Low Power modes: https://github.com/mattico/stm32f0-Discovery_Tools/blob/master/ST_Example_Projects/Projects/Peripheral_Examples/PWR_CurrentConsumption/stm32f0xx_lp_modes.c