0

in our Computer Science class, we are learning to use the STEM32 - Nucleo-L controller, to code assembler. I'm a bit further than the rest of the class, so my teacher tasked me to experiment with the "HAL_Delay" command, since he ran into some problems, trying to use the command.

I found out, that the command usually works fine, except if the registers R2 or/and R3 are use for other stuff. I also found out, that the "wait_ms" command works perfectly fine, so should we just use that command or has anyone got a solution. It would also be very usefull, if someone knew the exact location of the subprogram "HAL_Dealy" in the code.

.syntax unified
.equ L152,1
.include "../Core/src/regs.s"
.global mainasm
mainasm:


main:
    bl      startup
    ldr     R1,=GPIOA
    ldr     R2,=GPIOC

    gruenwechsel:  //Wechsel von Rot auf Grün
        ldr     R0,[R2,ODR] //Ampel auf rot setzen
        mov     R0,#0b1
        strb    R0,[R2,ODR]
        mov     R0,#500
        bl      wait_ms     //500ms Warten
        ldr     R0,[R2,ODR]
        mov     R0,#0b101   //Rote und Grüne LED geichzeitig an
        strb    R0,[R2,ODR]
        mov     R0,#500     //500ms Warten
        bl      wait_ms
        b       Gruen       //Ampel auf Grün setzen

    Gruen:      //Grüner Loop
        ldr     R0,[R2,ODR]
        mov     R0,#0b10000 //Ampel auf Grün
        strb    R0,[R2,ODR]
        ldr     R0,[R1,IDR]
        tst     R0,Bit10    //Schauen ob PA10 gedrueckt ist
        bne     rotwechsel  //Falls ja, in rotwechsel springen
        b       Gruen


    rotwechsel:
        ldr     R0,[R2,ODR]
        mov     R0,#0b00100 //Grüne und Gelbe LED Gleichzeitig an
        strb    R0,[R2,ODR]
        mov     R0,#1000    //Warte 1 Sekunde
        bl      wait_ms
        ldr     R0,[R2,ODR]
        mov     R0,#0b00001 //Rote LED an
        strb    R0,[R2,ODR]
        b       Rot

    Rot:                    //Roter Loop
        ldr     R0,[R2,ODR]
        mov     R0,#0b000001 //LED Rot an
        strb    R0,[R2,ODR]
        ldr     R0,[R1,IDR]
        tst     R0,Bit10 //Schauen ob PA10 gedrückt ist, falls ja, in Grünwechsel springen
        bne     gruenwechsel
        b       Rot


.end

Thats my code. If I change the "wait_ms" lines to "HAL_Delay" the code compiles without errors and also loads on to the chip, but it won't do anything, when i press the buttons.

2
  • HAL_Delay() relies on systick which works on interrupt. So if you don't enable interrupt this will not work. Now if R2 or R3 is used then why the HAL_Delay doesn"t work, it needs more understanding on the chip you are using Commented Jan 10, 2023 at 14:09
  • @brushtakopo The chip I am using is the STM32 - Nucleo - L 152RE Commented Jan 13, 2023 at 8:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.