Skip to main content
j3lda1
Associate
Sep 30, 2012 9:51 AM UTC
Question

STM32VL - example using interrupts in ASM

Posted on September 30, 2012 at 11:51

Hello, I am new in programming of STM32VL Discovery. I would like to write program in assembler for blinking LEDs using interrupts.

But it is so difficult to find examples in ASM and I can�t find some example in ASM with interrupts. Do you have some example where are used interrupts (handlers,..)?

Can you help me? Thanks a lot 

#books
    This topic has been closed for replies.

    5 replies

    Tesla DeLorean
    Guru
    Oct 1, 2012 3:07 AM UTC
    Posted on October 01, 2012 at 05:07

    Do you have any experience of ARM/Thumb assembler to draw from?

    In Keil, I might use the SysTick to periodically toggle LED3 thusly

    SysTick_Handler PROC
    EXPORT SysTick_Handler
    ldr r0, =0x40011000 ; GPIOC
    ldr r1, =0x200 ; Pin 9, LED3
    ldr r2, [r0, #0xC] ; GPIOC->ODR
    and r2, r2, r1 ; Mask bits to toggle
    lsl r3, r2, #16 ; Get reset bits to high order
    eor r2, r2, r1 ; Invert set in low order
    orr r2, r2, r3 ; Combine
    str r2, [r0, #0x10] ; GPIOC->BSRR
    bx lr
    ENDP

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Andrew Neil
    Super User
    Oct 1, 2012 7:10 AM UTC
    Posted on October 01, 2012 at 09:10

    Any particular reason why it has to be assembly, rather than, say, 'C' ?

    In Assembly, you are dealing directly with the Cortex-M3 instruction set - which is defined by ARM, and not specific to ST or the STM32.

    So the place to start would be the ARM technical reference site: http://infocentre.arm.com

    Get yourself a copy of  ''The Definitive Guide to the ARM Cortex-M3'' by Joseph Yiu 

    eg,

    http://www.amazon.co.uk/The-Definitive-Guide-ARM-Cortex-M3/dp/185617963X/ref=sr_1_1?ie=UTF8&qid=1349075537&sr=8-1

    More ARM Books here:

    http://www.keil.com/books/armbooks.asp

    In the ARM 'Community' section, you will find training providers, consultants, etc:

    http://www.arm.com/community/index.php

    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    j3lda1
    j3lda1Author
    Associate
    Oct 1, 2012 9:05 AM UTC
    Posted on October 01, 2012 at 11:05

    Thank you, LEDs are blinking now. I was trying to use TIM3 handler, but SYStick handler is definitely better (easier to write in ASM). I must write this in ASM because our teacher wants that. We can use ''delay'' function for blinking LEDs, but I want have better solution... 

    j3lda1
    j3lda1Author
    Associate
    Oct 1, 2012 10:49 AM UTC
    Posted on October 01, 2012 at 12:49

    Only one thing is for me still unclear.

    I used code from THE DEFINITIVE GUIDE TO THE ARM CORTEX-M3:

     LDR     R0, =0xE000E010 ; SYSTICK control and status register

     MOV     R1, #0          

     STR     R1, [R0]        ; stop counter to prevent interrupt triggered accidentally

     LDR     R1, =11999999   ; trigger every 12000000 cycles

     STR     R1, [R0,#4]     ; write reload value to reload value register

     STR     R1, [R0,#8]     ; write any value tu current value

     MOV     R1, #0x7        ; enable interrupt, enable SYSTICK counter

     STR     R1, [R0]        ; start counter

    Now, it´s blinking every 1 second (0,5s is shining and 0,5s isn´t shining). I thought that when I want blinking every 2 seconds, I only need set  LDR     R1, =23999999. But it´s blinking even faster! Do you know ,why?

    Tesla DeLorean
    Guru
    Oct 1, 2012 11:25 AM UTC
    Posted on October 01, 2012 at 13:25

    Confirm what SYSCLK is, 8 MHz, 24 MHz

    Check if SysTick is at SYSCLK or SYSCLK/8

    The count is 24-bit, so largest value is 16777216.

    Larger values give slower speeds.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..