registering a new interrupt handler at runtime

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

hazelnusse
Posts: 77
Joined: Thu May 24, 2012 8:01 am

Re: registering a new interrupt handler at runtime

Post by hazelnusse »

Ok, I think I found a solution I am happy with. In my linker script, I have:

Code: Select all

    
    ram_startup : ALIGN(16) SUBALIGN(16)
    {
        __ram_vector_table_start__ = .;
        KEEP(*(ram_vectors))
    } > ram AT > flash

Note that you must have "> ram AT > flash" NOT "> ram" as I had in my previous post.
Then, in my chconf.h, I have:

Code: Select all

extern uint32_t __ram_vector_table_start__;
#define CORTEX_VTOR_INIT __ram_vector_table_start__

Then all seems to work correctly. If I look at my map file, I can see:

Code: Select all

                0x0000000020000800                __ram_vector_table_start__ = .
 *(ram_vectors)
 ram_vectors    0x0000000020000800      0x200 build/obj/VectorTable.o
__ram_vector_table_start__                        build/obj/chcore_v7m.o

The nice thing about this approach is that if I change the stack sizes in the linker script, SCB_VTOR still gets correctly initialized with the right value.

I'm going to test it to make sure, but I think this looks pretty good. Any thoughts?

Thanks,
Luke
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: registering a new interrupt handler at runtime

Post by Giovanni »

Probably it should be:

Code: Select all

#define CORTEX_VTOR_INIT &__ram_vector_table_start__


You have to refer the address of the variable.

Giovanni
hazelnusse
Posts: 77
Joined: Thu May 24, 2012 8:01 am

Re: registering a new interrupt handler at runtime

Post by hazelnusse »

One thing I am a bit confused about still is the alignment of the vector table. For the STM32F4, there are 16 + 82 interrupt vectors. My understanding of the vector table is that it must be aligned to the vector table size, extended to the next larger power of 2. So that would be 4*(16+82) = 392, extended to the next larger power of 2 would be 512. In the linker script there are alignment statements like

Code: Select all

    ram_startup : ALIGN(16) SUBALIGN(16)

but in the place where I declare the vector table, I have this:

Code: Select all

static vectors_t vtable_ __attribute__((aligned(512)));

So I'm a bit confused as to which one does what. The map indicates that the vector table is on a 512 byte boundary, so I guess I'm ok, but I tried experimenting with changing the values in ALIGN(), SUBALIGN(), and __attribute__((aligned())) and couldn't really see which one has control over where the vector table gets placed. Also, if I make the stack sizes such that they are just past a 512 byte boundary, and only specify 16 byte alignment (in all three places), I still get 512 byte alignment for some reason..... Very confusing. I must be missing something here.

I changed to be &__ram_vector_table_start__. In the context of the linker script, this variable is the location counter at the beginning of the ram_startup section, so I'm a bit confused as to why we need the address of this variable and not the value. Must be another subtlety of linker scripts that I'm not clear on.

Luke


Luke
Post Reply