armembedqemucortex-mstartupscript

Can I light up the LED at the reset interrupt point


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



Solution

  • 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.