0

Based on Cortex-M4,GNU compiler. what i want to do is through a store instruction store a word to an address which is belongs a light's GPIOx_ODR(output mode as default).so i can light up led without do any further operation(like RCC or something) when proccessor jump to the reset handler ,it redirect to the .text sections which is only has following instruction:

Reset_Handler:
    movw r0, #0x0800  //stm32's cortex-m4 manul
    movt r0, #0x4800  
    ldr  r1, [r0,#0x14]

i firstly try whether i can load a word from GPIOx_ODR. but when i run it on the qemu it says:

stm32l431rct6_blink_gnu>qemu-system-arm.exe -s -S -M netduinoplus2 -nographic -kernel blink_image.elf
qemu: fatal: Lockup: can't escalate 3 to HardFault (current priority -1)

R00=00000000 R01=00000000 R02=00000000 R03=00000000
R04=00000000 R05=00000000 R06=00000000 R07=00000000
R08=00000000 R09=00000000 R10=00000000 R11=00000000
R12=00000000 R13=464c4558 R14=fffffff9 R15=00000000
XPSR=40000003 -Z-- A handler

I can't even read, how do I write?, In the end, how can I light up an LED with the least amount of operation

ENTRY(Reset_Handler)

MEMORY
{
    RAM (xrw)      : ORIGIN = 0x20000000, LENGTH = 64K  
    FLASH (rx)      : ORIGIN = 0x8000000, LENGTH = 256K 
}

SECTIONS {
    .isr_vector 0x8000004: {
        KEEP(*(.isr_vector))
    } 
    .text 0x8004170: {
        *(.text)
    } 
}

startup

.syntax unified
.cpu cortex-m4
.fpu softvfp
.thumb

.global Reset_Handler   
//  0x4800 0800 - 0x4800 0BFF 1 KB GPIOC
// Address offset: 0x14 GPIOx_ODR
.section .text
Reset_Handler:
    movw r0, #0x0800  //stm32's cortex-m4 manul
    movt r0, #0x4800  
    ldr  r1, [r0,#0x14]
    b .

.section .isr_vector, "a"
    .word Reset_Handler


artless noise
  • 21,212
  • 6
  • 68
  • 105
jack wen
  • 29
  • 5
  • 2
    This has probably failed on startup (the PC value in the register dump is suspicious) and never even got to your instruction to read from the GPIO register. Chances are the bug is in your linker script and/or how you're setting up the vector table, but you haven't given any details about those... – Peter Maydell Apr 27 '23 at 18:10
  • What QEMU version are you using? Your ELF file is loading the vector table at an address which is an alias to the initial vector table base address value (that's 0). Older QEMU versions didn't handle that correctly, so make sure you're using the most recent one. Or change your linker script to put the vector table at address 0x0 (ie reset PC slot at 0x4). – Peter Maydell Apr 28 '23 at 13:54

2 Answers2

1

There are several issues here:

(1) The netduinoplus2 has an STM32F405 SoC, and on that SoC the GPIO is not at the 0x48000800 address you're using

(2) Even if you used the right address, QEMU's model of this SoC doesn't currently implement the GPIO controllers

(3) Even if it did, QEMU doesn't generally model LEDs, so telling the GPIO controller to turn on the LED wouldn't do anything visible

For code running on QEMU, the UART is usually a more useful device to target for "show that something happened" behaviour.

Peter Maydell
  • 9,707
  • 1
  • 19
  • 25
  • about (1) is real,maybe that address is able to read.(i rencently test again,and i founc out the main error is in the startup.s ,when cpu goto the memory ,the address must be bit[0] = 1,indicating is thumb code,if not it will have enter hardfault handler as i run in the real device stm32l431rct6).about make bit[0] =0 ,add`.type Reset_Handler, %function`in the text section. – jack wen Apr 30 '23 at 06:57
0

I can't even read, how do I write?, In the end, how can I light up an LED with the least amount of operation

I would suggest to read the documentation first. The GPIO digital part is NOT enabled after reset as you need to enable the GPIO clock in one of the RCC registers.

0___________
  • 60,014
  • 4
  • 34
  • 74
  • why we need a clock to light up?what i think it just need a high voltage – jack wen Apr 28 '23 at 00:45
  • 2
    @jackwen read the documentation instead asking this kind of question, or call STM design engineers to ask why they designed the chip this way – 0___________ Apr 28 '23 at 07:15