Hi,
I’m trying to get a ‘trivial’ SysTick demo example running based on the example code provided with the Std Periph library V3.2.0.
AFAICT, with CMSIS and V3 of Std Periph, the only code that should be required is :
/* Setup SysTick Timer for 1 msec interrupts.
*/
if (SysTick_Config(SystemCoreClock / 1000))
{
while (1); /* Capture error */
}
and
void SysTick_Handler(void)
{
/* ISR handler. */
}
…however this isn’t working for me. SysTick_Handler() is never called.
Could anyone show me how to hook this up please?
The full code is below. I’m using the Olimex STM32-H103 board. I turn the onboard LED on (output low) at start and then off (output high) in the ISR, but the LED stays on.
Using the same template I have made working code to handle UART interrupts, so I have some confidence the vector table is being set up although clearly something is not right.
main.c:
#include "stm32f10x.h"
#include "main.h"
void GPIO_Configuration(void);
void NVIC_Configuration(void);
int main(void)
{
/*!< At this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup
file (startup_stm32f10x_xx.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32f10x.c file
*/
NVIC_Configuration(); /* <--- Tried with and without this call. */
GPIO_Configuration();
/* Setup SysTick Timer for 1 msec interrupts.
*/
if (SysTick_Config(SystemCoreClock / 1000))
{
while (1); /* Capture error */
}
GPIO_ResetBits(LED_PORT, LED1_PIN); /* LED on. */
while (1)
{
}
}
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(LED_RCC_APB2Periph_GPIO | RCC_APB2Periph_AFIO, ENABLE);
GPIO_InitStructure.GPIO_Pin = LEDS_ALL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(LED_PORT, &GPIO_InitStructure);
}
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = SysTick_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
main.h:
#ifndef __MAIN_H
#define __MAIN_H
/* STM3210C-EVAL
*/
/* #define LED_RCC_APB2Periph_GPIO RCC_APB2Periph_GPIOD */
/* #define LED_PORT GPIOD */
/* #define LED1_PIN GPIO_Pin_7 */
/* #define LED2_PIN GPIO_Pin_13 */
/* #define LED3_PIN GPIO_Pin_3 */
/* #define LED4_PIN GPIO_Pin_4 */
/* #define LEDS_ALL (LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN) */
/* Olimex STM32-H103.
*/
#define LED_RCC_APB2Periph_GPIO RCC_APB2Periph_GPIOC
#define LED_PORT GPIOC
#define LED1_PIN GPIO_Pin_12
#define LEDS_ALL LED1_PIN
#endif /* __MAIN_H */
stm32f10x_it.c:
#include "stm32f10x.h"
#include "stm32f10x_it.h"
#include "main.h"
/**
* @brief This function handles NMI exception.
* @param None
* @retval None
*/
void NMI_Handler(void)
{
}
/**
* @brief This function handles Hard Fault exception.
* @param None
* @retval None
*/
void HardFault_Handler(void)
{
/* Go to infinite loop when Hard Fault exception occurs */
while (1)
{
}
}
/**
* @brief This function handles Memory Manage exception.
* @param None
* @retval None
*/
void MemManage_Handler(void)
{
/* Go to infinite loop when Memory Manage exception occurs */
while (1)
{
}
}
/**
* @brief This function handles Bus Fault exception.
* @param None
* @retval None
*/
void BusFault_Handler(void)
{
/* Go to infinite loop when Bus Fault exception occurs */
while (1)
{
}
}
/**
* @brief This function handles Usage Fault exception.
* @param None
* @retval None
*/
void UsageFault_Handler(void)
{
/* Go to infinite loop when Usage Fault exception occurs */
while (1)
{
}
}
/**
* @brief This function handles SVCall exception.
* @param None
* @retval None
*/
void SVC_Handler(void)
{
}
/**
* @brief This function handles Debug Monitor exception.
* @param None
* @retval None
*/
void DebugMon_Handler(void)
{
}
/**
* @brief This function handles PendSV_Handler exception.
* @param None
* @retval None
*/
void PendSV_Handler(void)
{
}
/**
* @brief This function handles SysTick Handler.
* @param None
* @retval None
*/
void SysTick_Handler(void)
{
GPIO_SetBits(LED_PORT, LED1_PIN); /* LED off. */
}
stm32f10x_it.h:
#ifndef __STM32F10x_IT_H
#define __STM32F10x_IT_H
void NMI_Handler(void);
void HardFault_Handler(void);
void MemManage_Handler(void);
void BusFault_Handler(void);
void UsageFault_Handler(void);
void SVC_Handler(void);
void DebugMon_Handler(void);
void PendSV_Handler(void);
void SysTick_Handler(void);
#endif /* __STM32F10x_IT_H */