stm32-rs / stm32f1xx-hal

A Rust embedded-hal HAL impl for the STM32F1 family based on japarics stm32f103xx-hal
Apache License 2.0
577 stars 181 forks source link

Can't make simple "Hello World" program to work #487

Closed LaineZ closed 4 months ago

LaineZ commented 4 months ago

I followed the instructions in README, and I got no any message in OpenOCD Console from STM32.

$ openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg
Open On-Chip Debugger 0.12.0
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
WARNING: interface/stlink-v2.cfg is deprecated, please switch to interface/stlink.cfg
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : clock speed 1000 kHz
Info : STLINK V2J44S7 (API v2) VID:PID 0483:3748
Info : Target voltage: 3.095141
Info : [stm32f1x.cpu] Cortex-M3 r1p1 processor detected
Info : [stm32f1x.cpu] target has 6 breakpoints, 4 watchpoints
Info : starting gdb server for stm32f1x.cpu on 3333
Info : Listening on port 3333 for gdb connections
Info : accepting 'gdb' connection on tcp/3333
[stm32f1x.cpu] halted due to debug-request, current mode: Handler HardFault
xPSR: 0x61000003 pc: 0x0800019c msp: 0x20004fd4
Info : device id = 0x10006412
Info : flash size = 32 KiB
Warn : Prefer GDB command "target extended-remote :3333" instead of "target remote :3333"
[stm32f1x.cpu] halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08000130 msp: 0x20005000, semihosting
[stm32f1x.cpu] halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08000130 msp: 0x20005000, semihosting

memory.x file:

MEMORY
{
  FLASH : ORIGIN = 0x08000000, LENGTH = 32K
  RAM : ORIGIN = 0x20000000, LENGTH = 20K
}
$ cargo run
warning: `/home/bpm140/projects/stm32/.cargo/config` is deprecated in favor of `config.toml`
note: if you need to support cargo 1.38 or earlier, you can symlink `config` to `config.toml`
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.01s
     Running `/home/bpm140/Downloads/arm-gnu-toolchain-13.3.rel1-x86_64-arm-none-eabi/bin/arm-none-eabi-gdb target/thumbv7m-none-eabi/debug/stm32`
GNU gdb (Arm GNU Toolchain 13.3.Rel1 (Build arm-13.24)) 14.2.90.20240526-git
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "--host=x86_64-pc-linux-gnu --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://bugs.linaro.org/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from target/thumbv7m-none-eabi/debug/stm32...
0x08001cb4 in cortex_m_rt::HardFault_ (ef=0x0) at src/lib.rs:1046
1046        loop {}
semihosting is enabled
semihosting is enabled
Loading section .vector_table, size 0x130 lma 0x8000000
Loading section .text, size 0x1b88 lma 0x8000130
Loading section .rodata, size 0x6a0 lma 0x8001cb8
Start address 0x08000130, load size 9048
Transfer rate: 14 KB/sec, 3016 bytes/write.
Single stepping until exit from function Reset,
which has no line number information.
halted: PC: 0x0800018e
cortex_m_rt::DefaultPreInit () at src/lib.rs:1058
1058    pub unsafe extern "C" fn DefaultPreInit() {}
(gdb) continue
Continuing.

Cargo.toml

[package]
name = "stm32"
version = "0.1.0"
edition = "2021"

[package.metadata]
chip = "STM32F103C6"

[dependencies]
embedded-hal = "0.2.7"
nb = "1"
cortex-m = "0.7.6"
cortex-m-rt = "0.7.1"
panic-halt = "0.2.0"

[dependencies.stm32f1xx-hal]
version = "0.10.0"
features = ["rt", "stm32f103"]

[dependencies.cortex-m-semihosting]
version = "0.5.0"

[dependencies.panic-semihosting]
version = "0.5.0"

Rust version: rustc 1.81.0-nightly (aa1d4f682 2024-07-03) Board and MCU: STM32C6T6A Bluepill Flasher/Probe: STLINK v2 OS: OpenSUSE Tumbleweed

LaineZ commented 4 months ago

Issue resolved! The problem hiding in memory.x linker settings. For STM32C6T6A You need set RAM to 10K instead of 20K.

Here a fixed memory.x file for STM32C6T6:

MEMORY
{
  FLASH : ORIGIN = 0x08000000, LENGTH = 32K
  RAM : ORIGIN = 0x20000000, LENGTH = 10K
}