Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AM335x FreeRTOS port, unable to handle IRQs and SWI

I'm currently trying to port FreeRTOS to the TI AM335x processor, best known for being used on the BeagleBones. I am able to boot, run GPIOs and setup a compare match timer for running the system ticks. If I disable interrupts, i can see how the interrupt get set after a correct amount of time after the timer was started. And if I enable interrupts, my application dies after that same given time. The application also dies if I try to yield a task, aka calling the SWI handler. This makes me belive that the vector table is unavailable or incorrectly setup. The ROM Exception Vectors for SWI and IRQ has the contenct 4030CE08h and 4030CE18h. Which again in RAM executes some branching, the TRM says:

User code can redirect any exception to a custom handler either by writing its address to the appropriate location from 4030CE24h to 4030CE3Ch or by overriding the branch (load into PC) instruction between addresses from 4030CE04h to 4030CE1Ch.

My vIRQHandler function address is therefore written to 4030CE38h. One would hope this was enough, but sadly no. I suspect that there is something wrong in my boot.s file, however my assembly has never been that great and i'm struggling to understand the code. The boot.s and the rest of the project was started from a OMAP3 port. Boot.s:

.section .startup,"ax"
         .code 32
         .align 0

    b     _start                        /* reset - _start           */
    ldr   pc, _undf                     /* undefined - _undf        */
    ldr   pc, _swi                      /* SWI - _swi               */
    ldr   pc, _pabt                     /* program abort - _pabt    */
    ldr   pc, _dabt                     /* data abort - _dabt       */
    nop                                 /* reserved                 */
    ldr   pc, _irq              /* IRQ - read the VIC       */
    ldr   pc, _fiq                      /* FIQ - _fiq               */

_undf:  .word 0x4030CE24 /* undefined               */
_swi:   .word 0x4030CE28 /* SWI                     */
_pabt:  .word 0x4030CE2C /* program abort           */
_dabt:  .word 0x4030CE30 /* data abort              */
_irq:  .word 0x4030CE38
_fiq:   .word 0x4030CE3C /* FIQ                     */

The branch to start sets up a stack for each mode and clears the bss, not sure if that is relevant. This is the code which seems relevant to me, and I have updated the words to fit the AM335 instead of the OMAP3.

The setting IRQ handler:

#define E_IRQ                   (*(REG32 (0x4030CE38)))
....
/* Setup interrupt handler */
E_IRQ = ( long ) vIRQHandler;

If anyone have any pointers to an assembly newbie it would be much appriciated, because i'm completely stuck :)

like image 211
henfos Avatar asked Oct 31 '22 22:10

henfos


1 Answers

U-boot had moved the exception vector table. However, instead of recompiling u-boot I just reset the exception vector table in my own start script.

Added this right before branching to main:

/* Set V=0 in CP15 SCTRL register - for VBAR to point to vector */
mrc    p15, 0, r0, c1, c0, 0    @ Read CP15 SCTRL Register
bic    r0, #(1 << 13)       @ V = 0
mcr    p15, 0, r0, c1, c0, 0    @ Write CP15 SCTRL Register

/* Set vector address in CP15 VBAR register */
ldr     r0, =_vector_table
mcr     p15, 0, r0, c12, c0, 0  @Set VBAR

bl      main

And put in the _vector_table label at the start of my exception vector table:

.section .startup,"ax"
         .code 32
         .align 0
_vector_table:  b     _start    /* reset - _start       */
        ldr   pc, _undf         /* undefined - _undf        */
        ldr   pc, _swi          /* SWI - _swi               */
        ldr   pc, _pabt     /* program abort - _pabt    */
        ldr   pc, _dabt     /* data abort - _dabt       */
        nop                 /* reserved             */
        ldr   pc, _irq      /* IRQ - read the VIC       */
        ldr   pc, _fiq      /* FIQ - _fiq               */

Now all the exceptions gets redirected to my code. Hopefully this will help anyone in the same situation that I was in:)

like image 57
henfos Avatar answered Nov 09 '22 04:11

henfos