Thursday, May 10, 2012

ARM STM32 Study Note_6/SysTick

1. Systick:
  Cortex System timer, 24bit decrementing counter.

 
  -FW functions:
  
2. Configuration

  -Need to setup the clock period

 -Enable the interrupt handler:
  -Set interrupt Vector table address:

@Let's talk about NVIC@:

-First, for the cortex M3 processor, we need to map the interrupt table to either RAM or flash.That's why we need to run the
  NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x00000);

-Next, how the table is constructed:
  1.pre-emption and subpriority:
   each interrupt must have a pre-emption value, smaller pre-emption value has more priority when the interrupt triggered(at same time), in addition, smaller pre-emption can interrupt the interrupt function that has large pre-emption value.
   if subpriority value exists, for same pre-emption value, smaller value subpriority runs first.


  2. how these two values defined:
let's look at some code first:
#define NVIC_PriorityGroup_0         ((uint32_t)0x700) /*!< 0 bits for pre-emption priority 4 bits for subpriority */
#define NVIC_PriorityGroup_1         ((uint32_t)0x600) /*!< 1 bits for pre-emption priority 3 bits for subpriority */
#define NVIC_PriorityGroup_2         ((uint32_t)0x500) /*!< 2 bits for pre-emption priority 2 bits for subpriority */
#define NVIC_PriorityGroup_3         ((uint32_t)0x400) /*!< 3 bits for pre-emption priority 1 bits for subpriority */
#define NVIC_PriorityGroup_4         ((uint32_t)0x300) /*!< 4 bits for pre-emption priority 0 bits for subpriority */

As you can see, we have four bits allocated for pre-emption and subpriotity values, for example, by choosing NVIC_PriorityGroup_2
We will have 2 bits for pre-emption and another two bits for subpriority. Which means, you can have 4 pre-emption (0-3) interrupt values, and for each pre-emption value you picked, you also have 4 subpriority values available to pick.
if we define NVIC_PriorityGroup_4, then we have total 16 pre-emption values and none subpriority value. 
Smaller pre-emption value can interrupt the lager one, in this case, max 16 cascaded interrupt could occur.

  3. Based on the pre-emption and subpriority value you defined, everything will be mapped to the location where the  
 NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x00000); 
is  located.

 



  
3. adding stuff to the interrupt handler function in side stm32f10x_it.c
 #use extern for any functions from other files

No comments:

Post a Comment