Saturday, August 24, 2013

bug in Vector Table Initialization

So after revisiting the program I realized that the errors were in a pattern that began with 0x2000 .... basically the address of RAM. It dawned on me that at the beginning the data in memory was fine ... so I single stepped to just after it got clobbered and that was in the stm32_nvic_init() function.

The problem was that I was initializing 256-2 vector table positions while only allocating space for 76. So I made the following changes

1) IE_stm32_ivt.S
.global stm32_ivt
.global stm32_ivt_end
.extern main
.equ    STM32_SRAM_BASE,0x20000000
.data
stm32_ivt:      .word   STM32_SRAM_BASE + (20 * 1024)
                .word   (main + 1)
                .skip   (14 * 4)
                .skip   (240 * 4)
stm32_ivt_end:
.text





2) IE_stm32.c
/*
 **********************************************************************
 *install handlers for all vector positions
 *skip positions 0 = thread stack and 1 = reset address
 *dont hardcode size of table - determine it with stm32_ivt and _end
 **********************************************************************
 */
ptrTemp = (volatile unsigned int *)STM32_NVIC_IVT_BASE;
wdTemp  = (&stm32_ivt_end - &stm32_ivt);
for(wdCount=2; wdCount<wdTemp; wdCount++)
        {
        if(wdCount <= 6)
                ptrTemp[wdCount] = ((unsigned int)(stm32_nvic_fault_isr)\
                | 0x1);
        else
                {
                if(wdCount == 15)
                        ptrTemp[wdCount] = ((unsigned int)(stm32_nvic_systick_isr)\
                        | 0x1);
                else
                        ptrTemp[wdCount] = ((unsigned int)(stm32_nvic_unknown_isr)\
                        | 0x1);
                }
        }





3) IE_stm32.ld
MEMORY  {
        STM32_RAM    : ORIGIN = 0x20000000,   LENGTH = (20480 - 1024)
        }


SECTIONS
        {
        .data :   
                {
                *(.data);
                } > STM32_RAM

        .text :   
                {
                *(.text);
                *(.rodata*);
                } > STM32_RAM

        .bss :
                {
                *(.bss);
                } > STM32_RAM
        }

No comments:

Post a Comment