This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C123GXL ARM SW1/2 Interrupt - Student Question

Hello, 

I am an engineering student doing my Introductory to Assembly course and I am having a play (outside the scope of the subject) with the SW1 and SW2 on the TM4C123GXL.  I am trying to use the onboard switches to cause an interrupt.

Whenever I press either switch the tiva freezes, I can see the GPIO data light up and the RIS register goes high but no interrupt. I added a milestone to my routine and it never reaches it but the main.s routine runs fine. The interrupt does not need to be in the vectors to cause the freeze. I am using keil uvision5.

I was hoping the problem has something to do with the inputs on port F that I have not been taught. Please no C.

parts of my setup are below;

Setup_GPIOF ;Port F0, F4
PUSH {LR, R0-R2}

LDR R0, =SYSCTL_BASE ; Setup Port F
MOV R2, #0x20
LDR R1, [R0, #RCGCGPIO]
ORR R1, R2 ; enable CLOCK
STR R1, [R0, #RCGCGPIO]
Wait_F LDR R1, [R0, #PRGPIO] ; wait for port to ACTIVATE
AND R1, R2 ; clear all but 1 bit
CMP R1, R2 ; call individual bit
BNE Wait_F

LDR R0, =GPIO_F_BASE

LDR R1, =UNLOCK
STR R1, [R0, #GPIO_LOCK]
MOV R1, #0xFF
STR R1, [R0, #GPIO_CR] ;UNLOCK SW2 (PORTF0)

MOV R2, #0x1F
LDR R1, [R0, #GPIO_DIR] ; set port a DIRECTION
BIC R1, #0x11 ; INPUT
ORR R1, #0xE ; OUTPUT
STR R1, [R0, #GPIO_DIR]
LDR R1, [R0, #GPIO_AFSEL] ; set port a FUNCTION (REGULAR)
BIC R1, R2
STR R1, [R0, #GPIO_AFSEL]
LDR R1, [R0, #GPIO_DR2R] ; set port a 2mA DRIVE
ORR R1, #0xE
STR R1, [R0, #GPIO_DR2R]
LDR R1, [R0, #GPIO_PCTL] ; set port a 2mA DRIVE
ORR R1, #0x8
LDR R1, [R0, #GPIO_DEN] ; set port a DIGITAL
ORR R1, R2
STR R1, [R0, #GPIO_DEN]
LDR R1, [R0, #GPIO_PUR]
ORR R1, #0x11
STR R1, [R0, #GPIO_PUR] ;PULL UP RESISTOR
MOV R1, #0x0
STR R1, [R0, #GPIO_LOCK] ;LOCK PF0

POP {LR, R0-R2}
BX LR

SetupF_Interrupts
PUSH {LR, R0-R2}

; BL Inter_SetupD
CPSID i

BL Setup_GPIOF

LDR R0, =GPIO_F_BASE
MOV R2, #0x11 ;PINS 0 and 4
LDR R1, [R0, #GPIO_IM]
BIC R1, #0x1F ;DISABLE
STR R1, [R0, #GPIO_IM]
LDR R1, [R0, #GPIO_IS]
BIC R1, R2 ;EDGE
STR R1, [R0, #GPIO_IS]
LDR R1, [R0, #GPIO_IBE]
BIC R1, R2 ;SINGLE
STR R1, [R0, #GPIO_IBE]
LDR R1, [R0, #GPIO_IEV]
BIC R1, R2 ;FALLING
STR R1, [R0, #GPIO_IEV]
LDR R1, [R0, #GPIO_IM]
ORR R1, #0x10 ;ENABLE
STR R1, [R0, #GPIO_IM]

LDR R0, =NVIC_BASE
LDR R1, [R0, #NVIC_EN0]
ORR R1, #(0x1<<30) ;PORT F
STR R1, [R0, #NVIC_EN0]

LDR R1, [R0, #NVIC_PRI7]
ORR R1, #(0x1<<21) ;PRI 1 #0x2000
BIC R1, #(0x6<<21) ; #0xC000
STR R1, [R0, #NVIC_PRI7]

LDR R0, =GPIO_F_BASE
LDR R1, [R0, #GPIO_ICR]
ORR R1, #0x1F ;clear interrupt
STR R1, [R0, #GPIO_ICR]

CPSIE i

POP {LR, R0-R2}
BX LR

CYCLE LDR R0, =GPIO_F_BASE ; main.s loop

RED MOV R2, #0x2
STR R2, [R0, #0x3FC] ;TURN ON LEDS RED
MOV R4, #333
BL DelayMs

BLUE MOV R2, #0x4
STR R2, [R0, #0x3FC] ;TURN ON LEDS BLUE
MOV R4, #333
BL DelayMs

GREEN MOV R2, #0x8
STR R2, [R0, #0x3FC] ;TURN ON LEDS GREEN
MOV R4, #333
BL DelayMs

B CYCLE

Thanks in advance, 

Greg.

  • Hello Greg

    And you want to debug the assembly code, when almost everyone on the forum uses C? I would ask you to check the FAULTSTAT and FAULTADDR registers first. Also where is the Interrupt Vector Table?
  • Yes, Assembly please, it's what I am learning.

    OK, I had a look in FAULTSTAT and FAULTADDR.

    FAULTSTAT is empty, FAULTADDR READS 0xF403 0020 and 0xF403 0020 is empty.

    Vector is

     where required

    IMPORT/EXPORT GPIO_White

    [in startup.s]

    DCD     GPIOF_White             ;  30: GPIO Port F

    [in .s file]

    GPIOF_White
    PUSH {LR, R0-R2}

    ; LDR R0, =GPIO_F_BASE
    ; LDR R1, [R0, #GPIO_RIS]
    ; AND R1, #0x1 ; mask
    ; CMP R1, #0x1 ;compare for pin
    ; BEQ FFinal
    ;
    ; LDR R1, [R0, #GPIO_RIS]
    ; AND R1, #0x10
    ; CMP R1, #0x10
    ; BEQ FFinal
    ; B FFinal                                              ;this has been commented out for error checking eventually i

    ;will assign different functions


    White LDR R0, =GPIO_F_BASE
    MOV R2, #0xE
    STR R2, [R0, #0x3FC] ;TURN ON ALL LEDS - WHITE
    MOV R4, #500
    BL DelayMs

    LDR R0, =GPIO_F_BASE
    LDR R1, [R0, #GPIO_ICR]
    ORR R1, #0x1F ;clear interrupt
    STR R1, [R0, #GPIO_ICR]

    FFinal
    POP {LR, R0-R2}
    BX LR

  • Hello Greg,

    So no evident bus fault. Also please check the NVIC PEND register to see which interrupt is being triggered.... As I said earlier, I would not be too inclined about debugging ASM, when C provides an easier and more readable code.
  • Hi,

    Did you put the assembler into the correct configuration? (i.e is there the declaration .thumb + some others, depending on your tool chain, unspecified and needed for help).

    Also, original startup file sends you to a main function, is your .s/.S file starting with main/_main?

  • I have been checking the RIS for interrupt

    ; LDR R0, =GPIO_F_BASE
    ; LDR R1, [R0, #GPIO_RIS]
    ; AND R1, #0x1 ; mask
    ; CMP R1, #0x1 ;compare for pin
    ; BEQ White
    ;
    ; LDR R1, [R0, #GPIO_RIS]
    ; AND R1, #0x10
    ; CMP R1, #0x10
    ; BEQ Red
    ; B Final

    its all commented out at the moment just to get the routine running, to no avail.

  • [main.s]
    [start]
    THUMB
    AREA DATA, ALIGN=2
    ALIGN
    AREA |.text|, CODE, READONLY, ALIGN=2

    [fin]
    Spin
    B Spin


    ALIGN
    END

    I'm 95% sure it won't be a formatting error because i can remap the interrupt to PB3/4 for rising and falling edge, jump the 3.3V to the pin and it will work, it seems to be a problem with PF0/4 (SW1/2)
  • Hello Greg

    I would like to see the GPIO registers and NVIC registers in the debugger.