Skip to main content
sima2
Associate III
February 10, 2011
Question

Trouble, need urgent help.

  • February 10, 2011
  • 10 replies
  • 1385 views
Posted on February 10, 2011 at 16:10

Trouble, need urgent help.

    This topic has been closed for replies.

    10 replies

    ColdWeather
    Senior
    May 17, 2011
    Posted on May 17, 2011 at 14:24

    1. Have you enabled a clock to the timer anywhere like

    RCC_APB1PeriphClockCmd (RCC_APB1Periph_TIM6, ENABLE);

    2. Have you named an IRQ handler right?

    void TIM6_IRQHandler(void)

     

    {

     

    ...

     

    }

    3. Have you added the correct startup file to the project?

    For instance, ''startup_stm32f10x_hd.s''. Look inside your startup file: can you find a line ''TIM6_IRQHandler'' there?

    sima2
    sima2Author
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 14:24

    Yes, I have checked all your points.

    And the application works fine when located at 0x0800 0000.

    And I have also move the interrupt vector table using:

    NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x8100);

    It's so stange.

    No I have also found when the MCU receives a byte on UART5 I get a Bus Fault exception (a jump to BusFault_Handler().

    I have looked at the memory addresses for these interrupt vectors  and they are correct.

    I use a STM32F103ZET6 device. Is there any chip errata on this?

    Tesla DeLorean
    Guru
    May 17, 2011
    Posted on May 17, 2011 at 14:24

    Attach the application's HEX file.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Nickname12657_O
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 14:24

    Dear SirM,

    Your trouble are due to the fact that your application start boundary is not multiple of 0x200 : ''0x08008100''. Please move it to be at

    ''0x08008200''.

    Have a look on our

    http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/PROGRAMMING_MANUAL/CD00228pdf

    : Page 133 :

    ''you must align the offset to the number of exception entries in the vector table.

    The minimum alignment is 128 words'' , word is 32-bits that means 128 x 4 = 512 Bytes .

    This is mainly due to the Vector table size of our High-density devices

    0690X0000060MlZQAU.gif

    Cheers,

    STOne- Your STM32 Moderator.

    sima2
    sima2Author
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 14:24

    Here is the application hex file that I'm experimenting right now to find the problem.

    It is located from 0x08008100.

    I have scaled away all other code. It only does the following:

    int main(void)

    {

        TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;

        NVIC_InitTypeDef NVIC_InitStructure;

        NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x8100);

        // System clocks configuration

        SystemInit();

       

        // Enable clocks

        //RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);

        //RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE);

        RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR |

                               RCC_APB1Periph_BKP |

                               //RCC_APB1Periph_SPI2 |

                               //RCC_APB1Periph_SPI3 |

                               //RCC_APB1Periph_CAN1 |

                               //RCC_APB1Periph_USART2 |

                               //RCC_APB1Periph_USART3 |

                               //RCC_APB1Periph_UART4 |

                               //RCC_APB1Periph_UART5 |

                               //RCC_APB1Periph_TIM2 |   

                               //RCC_APB1Periph_TIM3 |   

                               //RCC_APB1Periph_TIM4 |   

                               //RCC_APB1Periph_TIM5 |   

                               RCC_APB1Periph_TIM6    

                               //RCC_APB1Periph_TIM7 |   

                               //RCC_APB1Periph_I2C1   

                               , ENABLE);

        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |

                               RCC_APB2Periph_GPIOB |

                               RCC_APB2Periph_GPIOC |

                               RCC_APB2Periph_GPIOD |

                               RCC_APB2Periph_GPIOE |

                               RCC_APB2Periph_GPIOF |

                               RCC_APB2Periph_GPIOG |

                               //RCC_APB2Periph_USART1 |

                               //RCC_APB2Periph_ADC1 |

                               //RCC_APB2Periph_ADC2 |

                               //RCC_APB2Periph_ADC3 |

                               RCC_APB2Periph_AFIO, ENABLE);

       

        // Enable CAN RX0 interrupt IRQ channel

        NVIC_InitStructure.NVIC_IRQChannel = TIM6_IRQn;

        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

        NVIC_Init(&NVIC_InitStructure);

        // ========================================================================

        // Configure TIM6

        //

        // Generate a timer interrupt 6 times per period

        // Time base configuration

        TIM_TimeBaseStructure.TIM_Period = 59999; // Period 60000 = 3.3333 ms

        TIM_TimeBaseStructure.TIM_Prescaler = 3;    // Divide 72MHz with 4 = 18MHz

        TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1 ;

        TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

        TIM_TimeBaseInit(TIM6, &TIM_TimeBaseStructure);

     

        // Clear interrupt flags

        TIM6->SR = 0x0000;

       

        // TIM IT enable

        TIM_ITConfig(TIM6, TIM_IT_Update, ENABLE);

       

        // Enable timer

        TIM6->CR1 |= TIM_CR1_CEN;

    }

    If i disable the last row (not enabling timer 6) it doesn't fail. But as soon as I activate the timer 6 a Usage Fault exception occurs.

    sima2
    sima2Author
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 14:24

    Thank you very much. I will try that tomorrow.

    I have not used high density STM32's until now so I was unaware of that.

    Learning all the time.

    Tesla DeLorean
    Guru
    May 17, 2011
    Posted on May 17, 2011 at 14:24

    Your TIM6 interrupt doesn't seem to do much, just increment a RAM variable and leave. It does not appear to actually clear any interrupt, so it will get stuck there endlessly as it repeatedly tail-chains.

    Be aware also that SystemInit() is already called before it executes main()

    08008354    SUB16    TIM6_IRQHandler:

    08008354 B480            push    {r7}

    08008356 AF00            add    r7, sp, #0

    08008358 F240 0300        movw    r3, #0    ; $0

    0800835C F2C2 0300        movt    r3, #8192    ; $2000

    08008360 681B            ldr    r3, [r3, #0]

    08008362 F103 0201        add.w    r2, r3, #1    ; $1

    08008366 F240 0300        movw    r3, #0    ; $0

    0800836A F2C2 0300        movt    r3, #8192    ; $2000

    0800836E 601A            str    r2, [r3, #0]

    08008370 46BD            mov    sp, r7

    08008372 BC80            pop    {r7}

    08008374 4770            bx    lr

    Translates roughly to :

    int foo;

    void TIM6_IRQHandler(void)

    {

        foo++;

    }

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    sima2
    sima2Author
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 14:24

    In the real application I do in fact have a:

    TIM6->SR = 0x0000;

    , at the entry of the interrupt handler.

    I managed to scale away too much when I posted my test code. ;)

    And the counter was just to see if the interrupt handler had activated.

    Nickname12657_O
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 14:24

    Hi SirM,

    Thank you so much for your posting, we will fix that typo in our Library version 3.5.0.

    Cheers,

    STOne-32.

    sima2
    sima2Author
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 14:24

    When I look at the function header for the NVIC_SetVectorTable() function in misc.c in ST Libraries it says:

    @param  Offset: Vector Table base offset field. This value must be a multiple of

    0x100

    .

    There should be some note about this pitfall here?