Information Center for ARM

Example description

  
NVIC_DMA_WFIMode NVIC DMA in WFI mode example
  
Example Description 

This example shows how to enter the system to WFI mode with DMA transfer enabled
and wake-up from this mode by the DMA End of Transfer interrupt.

In the associated software, the system clock is set to 120 MHz, the DMA1 Stream1
channel4 is configured to transfer 10 data from the EVAL_COM1 (USART3) data register 
to a predefined buffer, DST_Buffer, and to generate an interrupt at the end of
the transfer. The EVAL_COM1 (USART3) receives data from Hyperterminal.
LED1 is toggled with a frequency depending on the system clock, this is used 
to indicate whether the MCU is in WFI or RUN mode. 

Pressing key push button (generates rising edge on EXTI Line15) will put the core
in the WFI mode, causing the LED1 to stop toggling.
To wake-up from WFI mode you have to send the sequence (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
from the Hyperterminal to the EVAL_COM1 (USART3). These bytes will be transferred 
by the DMA from the EVAL_COM1 (USART3) receive data register to the predefined buffer, 
then generates an interrupt which exits the system from WFI mode. 
The LED1 restarts toggling and a LED2 will toggle if the buffer is correctly 
received else a LED3 is toggled.

Directory contents 

  - NVIC/DMA_WFIMode/stm32f2xx_conf.h    Library Configuration file
  - NVIC/DMA_WFIMode/stm32f2xx_it.c       Interrupt handlers
  - NVIC/DMA_WFIMode/stm32f2xx_it.h      Interrupt handlers header file
  - NVIC/DMA_WFIMode/main.c              Main program
  - NVIC/DMA_WFIMode/system_stm32f2xx.c  STM32F2xx system source file
  
	  The "system_stm32f2xx.c" is generated by an automatic clock configuration 
      tool and can be easily customized to your own configuration. 
      To select different clock setup, use the "STM32F2xx_Clock_Configuration_V1.0.0.xls" tool.

Hardware and Software environment

  - This example runs on STM32F2xx Devices.
  
  - This example has been tested with STM322xG-EVAL RevB and can be easily 
    tailored to any other development board.

  - STM322xG-EVAL Set-up
    - Use the Key push-button connected to pin PG15 (EXTI Line15)
    - Use LED1, LED2 and LED3 connected respectively to PG.06, PG.08 and PC.07 pins    
    - Connect a null-modem female/female RS232 cable between the DB9 connector 
      CN16 (USART3) and PC serial port if you want to display data on the HyperTerminal.
      @note Make sure that jumper JP22 is in position 1-2

  - Hyperterminal configuration:
    - Word Length = 8 Bits
    - One Stop Bit
    - No parity
    - BaudRate = 115200 baud
    - flow control: None   
 
===============================================================================

NVIC_IRQ_Mask NVIC IRQ Channels Mask example
  
Example Description 

This example demontrates the use of the Nested Vectored Interrupt Controller (NVIC)
IRQ Channels configuration and how to mask/activate different IRQs: 

- Configuration of 3 TIM (TIM2..TIM4) timers to generate an interrupt on each 
  counter update event.

- The three timers are linked to their correspondant Update IRQ channel.

- Assignment of a ascendant IRQ priority for each IRQ channel :
     - TIM2 has a preemption priority of 0
     - TIM3 has a preemption priority of 1
     - TIM4 has a preemption priority of 2
- In each interrupt routine: 
   - TIM2 toggles a LED1 each 1s 
   - TIM3 toggles a LED2 each 2s 
   - TIM4 toggles a LED3 each 3s 

- The KEY and SEL buttons are used to boost the execution priority as follows:

  - The KEY button is used in GPIO mode and at each KEY button press, the execution 
    priority is raised to 0 and turn LED4 ON. This prevents all exceptions with 
    configurable priority from activating, other than through the HardFault fault 
    escalation mechanism. As consequence, all LEDs stop toggling as TIM2, TIM3 
    and TIM4 IRQs are prevented from activation. 
    
    Pressing again the KEY button will release the priority boosting, turn LED4 
    OFF and will allow all exceptions with configurable priority to be activated 
    and TIM2, TIM3 and TIM4 can be generated again and the LEDs restart toggling.
    
    This execution priority is made using the CMSIS functions "__disable_irq()" 
    and "__enable_irq()". 
    These two functions are managing the Cortex-M3 PRIMASK special register.

  - The TAMPER button is used in EXTI mode and at each TAMPER button press, the
    execution priority is masked to 0x40 using the BASEPRI register. 
    A non-zero value will act as a priority mask, affecting the execution priority 
    when the priority defined by BASEPRI is the same or higher than the current 
    executing priority. 
    As consequence, LED2 and LED3 stop toggling as TIM3 and TIM4 IRQs are 
    prevented from activation. 
    Pressing again the TAMPER button will configure the BASEPRI register to 0, 
    thus it has no effect on the current priority and TIM3 and TIM4 can be 
    generated again and LED2 and LED3 restart toggling.
    
    This execution priority is made using the CMSIS functions "__set_BASEPRI()". 
    This function is managing the Cortex-M3 BASEPRI special register.
    Setting the BASEPRI register has no effect when the execution priority is
    raised to 0 using the "__disable_irq()" function.

	  These mechanisms only affect the group priority. They have no effect on 
      the sub-priority. The sub-priority is only used to sort pending exception 
      priorities, and does not affect active exceptions.

Directory contents 

  - NVIC/IRQ_Mask/stm32f2xx_conf.h    Library Configuration file
  - NVIC/IRQ_Mask/stm32f2xx_it.c       Interrupt handlers
  - NVIC/IRQ_Mask/stm32f2xx_it.h      Interrupt handlers header file
  - NVIC/IRQ_Mask/main.c              Main program
  - NVIC/IRQ_Mask/system_stm32f2xx.c  STM32F2xx system source file
  
	  The "system_stm32f2xx.c" is generated by an automatic clock configuration 
      tool and can be easily customized to your own configuration. 
      To select different clock setup, use the "STM32F2xx_Clock_Configuration_V1.0.0.xls" tool.

Hardware and Software environment

  - This example runs on STM32F2xx Devices.
  
  - This example has been tested with STM322xG-EVAL RevB and can be easily 
    tailored to any other development board.

  - STM322xG-EVAL Set-up
    - Use LED1, LED2, LED3 and LED4 connected respectively to PG.06, PG.08, PI.09
      and PC.07 pins
    - Use the KEY push-button connected to pin PG15 (EXTI Line15)
    - Use the TAMPER push-button connected to pin PC13 (EXTI Line13)

===============================================================================

NVIC_IRQ_Priority NVIC IRQ Priority example
  
Example Description 

This example demonstrates the use of the Nested Vectored Interrupt Controller (NVIC): 

- Configuration of 2 EXTI Lines (WAKEUP button EXTI Line & KEY button EXTI Line)
  to generate an interrupt on each falling edge and use the SysTick interrupt.
- These interrupts are configured with the following parameters:
    - WAKEUP button EXTI Line:  
        - PreemptionPriority = PreemptionPriorityValue
        - SubPriority = 0
    - KEY button EXTI Line:    
        - PreemptionPriority = 0
        - SubPriority = 1           
    - SysTick Handler:  
        - PreemptionPriority = !PreemptionPriorityValue
        - SubPriority = 0             
First, the PreemptionPriorityValue is equal to 0, the WAKEUP button EXTI Line 
has higher preemption priority than the SysTick handler. 

In the KEY button EXTI Line interrupt routine the WAKEUP button EXTI Line and 
SysTick preemption priorities are inverted. 
In the WAKEUP button EXTI Line interrupt routine the pending bit of the SysTick 
interrupt is set this will cause SysTick ISR to preempt the WAKEUP button EXTI 
Line ISR only if it has higher preemption priority.

The system behaves as following:
 
1) The first time KEY button EXTI Line interrupt occurs the SysTick preemption 
become higher than WAKEUP button EXTI Line one. So when the WAKEUP button EXTI 
Line interrupt occurs, the SysTick ISR is executed and the PreemptionOccured 
variable become TRUE and the four leds (LED1, LED2, LED3, LED4) start toggling.

2) When the next KEY button EXTI Line interrupt occurs the SysTick preemption
become lower than WAKEUP button EXTI Line one. So when the WAKEUP button EXTI Line
interrupt occurs, the PreemptionOccured variable became FALSE and the four leds
(LED1, LED2, LED3, LED4) stop toggling.

Then this behavior is repeated from point 1) in an infinite loop.

Directory contents 

  - NVIC/IRQ_Priority/stm32f2xx_conf.h    Library Configuration file
  - NVIC/IRQ_Priority/stm32f2xx_it.c       Interrupt handlers
  - NVIC/IRQ_Priority/stm32f2xx_it.h      Interrupt handlers header file
  - NVIC/IRQ_Priority/main.c              Main program
  - NVIC/IRQ_Priority/system_stm32f2xx.c  STM32F2xx system source file
  
	  The "system_stm32f2xx.c" is generated by an automatic clock configuration 
      tool and can be easily customized to your own configuration. 
      To select different clock setup, use the "STM32F2xx_Clock_Configuration_V1.0.0.xls" tool.

Hardware and Software environment

  - This example runs on STM32F2xx Devices.
  
  - This example has been tested with STM322xG-EVAL RevB and can be easily 
    tailored to any other development board.

  - STM322xG-EVAL Set-up
    - Use LED1, LED2, LED3 and LED4 connected respectively to PG.06, PG.08, PI.09
      and PC.07 pins
    - Use the WAKEUP push-button connected to pin PA.00 (EXTI Line0).
    - Use the KEY push-button connected to pin PG15 (EXTI Line15)

===============================================================================

NVIC_VectorTable_Relocation NVIC Vector Table Relocation example
  
Example Description 

This example describes how to relocate the CortexM3 vector table in a specific 
address other than the default Flash memory base address.
This can be used to build program which will be loaded into Flash memory by an
application previously programmed from the Flash memory base address. 
Such application can be In-Application Programming (IAP) through USART, Ethernet
or USB (Device Firmware Upgrade, DFU).
These applications are available for download from the ST microcontrollers 
website: ST Microcontrollers

To build such application, some special configuration has to be performed:
1. Set the application load address, using your toolchain linker file
2. In the application code, relocate the vector table at the application load 
   address using the "NVIC_SetVectorTable" function from the misc.h/.c driver or
   by modifying the value of the constant "VECT_TAB_OFFSET" defined
   in system_stm32f2xx.c file. 
For example, when building an application to be loaded with the IAP through USART
the application load address and vector table address must be set to 0x08004000.

In this example, the associated program implements a "Delay" function based on
SysTick end of count interrupt, and toggles four leds with timing defined by the
"Delay" function.

Directory contents 

  - NVIC/VectorTable_Relocation/stm32f2xx_conf.h    Library Configuration file
  - NVIC/VectorTable_Relocation/stm32f2xx_it.c       Interrupt handlers
  - NVIC/VectorTable_Relocation/stm32f2xx_it.h      Interrupt handlers header file
  - NVIC/VectorTable_Relocation/main.c              Main program
  - NVIC/VectorTable_Relocation/system_stm32f2xx.c  STM32F2xx system source file

	  The "system_stm32f2xx.c" is generated by an automatic clock configuration 
      tool and can be easily customized to your own configuration. 
      To select different clock setup, use the "STM32F2xx_Clock_Configuration_V1.0.0.xls" tool.

Hardware and Software environment

  - This example runs on STM32F2xx Devices.
  
  - This example has been tested with STM322xG-EVAL RevB and can be easily 
    tailored to any other development board.

  - STM322xG-EVAL Set-up
    - Use LED1, LED2, LED3 and LED4 connected respectively to PG.06, PG.08, PI.09
      and PC.07 pins