rust-embedded / cortex-m-semihosting

Semihosting for ARM Cortex-M processors
Apache License 2.0
40 stars 19 forks source link

stm32l475 semihosting doesn't work #30

Closed tasosxak closed 5 years ago

tasosxak commented 5 years ago

Hi everyone,

I am following this tutotial: https://rust-embedded.github.io/book/start/hardware.html but for stm32l475.

First of all, I changed the memory.x for stm32l475:

/* Linker script for the STM32L475VG*/
MEMORY
{
  /* NOTE 1 K = 1 KiBi = 1024 bytes */
  FLASH : ORIGIN = 0x08000000, LENGTH = 1000K /*1MBYTE*/
  RAM : ORIGIN = 0x20000000, LENGTH = 128K /*128KBYTE*/
}

The source code of the program which I want to run on stm32 chip is: hello.rs

use cortex_m_rt::entry;
use cortex_m_semihosting::{hprintln};

#[entry]
fn main() -> ! {

    hprintln!("Hello, world!").unwrap();
    loop {}
}

Then, I run these commands: For compilation: cargo run --example hello For openocd: openocd -f interface/stlink-v2-1.cfg -f target/stm32l4x.cfg

In another terminal, I run the gdb program and commands for flush etc.:

$ gdb-multiarch -q target/thumbv7em-none-eabi/debug/examples/hello
$ (gdb) target remote :3333
$ (gdb) load
$ (gdb) monitor arm semihosting enable
$ semihosting is enabled
$ (gdb) continue
Continuing.

^ the program stucks at this point.

Afterwards, I terminated the program, and Ι reopened a new gdb process. Ι gave the same commands until the command "monitor arm semihosting enable". At this point, I set breakpoint to the main function.

$ break main
$ jump main
Line 33 is not in `HardFault_'.  Jump anyway? (y or n) y
Continuing at 0x8000708.
Note: automatically using hardware breakpoints for read-only addresses.

Breakpoint 1, main () at examples/hello.rs:33
$ continue
$Continuing...

Again, the program stucks at this point. I pressed Ctrl-C and it printed out the command that the program execution is blocked:

0x080008f0 in cortex_m_semihosting::hio::hstdout () at /home/tasosxak/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-semihosting-0.3.2/src/hio.rs:53
53      open(":tt\0", nr::open::W_TRUNC).map(|fd| HStdout { fd })

OS : Ubuntu 18.04.1 LTS rustc version : rustc 1.34.0-nightly (146aa60f3 2019-02-18)

cargo .config file:

[target.thumbv7em-none-eabi]
//noth
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
//noth
rustflags = ["-C", "link-arg=-Tlink.x"]
[build]
target = "thumbv7em-none-eabi"
tasosxak commented 5 years ago

Solved. This is the correct memory.x file:

/* Linker script for the STM32L475VG*/
MEMORY
{
/* NOTE 1 K = 1 KiBi = 1024 bytes */
FLASH : ORIGIN = 0x08000000, LENGTH = 1000K
RAM : ORIGIN = 0x20000000, LENGTH = 96K
}
mattsoftware commented 4 years ago

Hi @tasosxak . Really curious why your length for the flash is 1000K and not 1024K. Also, how did you work out the origin was at 0x8000000 ? I have been pulling out my hair for hours until I cam across this post. Thank you for sharing!