AnsweredAssumed Answered

lease help me something about delay function in stm32f303 discovery

Question asked by chau_vo.huong on May 8, 2015
Latest reply on May 8, 2015 by AvaTar
hi! 
 i have learned about  how to use systick timer according to  example systick_example  that st provide 
this is source code 
001./**
002.  ******************************************************************************
003.  * @file    SysTick_Example/main.c
004.  * @author  MCD Application Team
005.  * @version V1.1.0
006.  * @date    20-September-2012
007.  * @brief   Main program body
008.  ******************************************************************************
009.  * @attention
010.  *
011.  * <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2>
012.  *
013.  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
014.  * You may not use this file except in compliance with the License.
015.  * You may obtain a copy of the License at:
016.  *
018.  *
019.  * Unless required by applicable law or agreed to in writing, software
020.  * distributed under the License is distributed on an "AS IS" BASIS,
021.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
022.  * See the License for the specific language governing permissions and
023.  * limitations under the License.
024.  *
025.  ******************************************************************************
026.  */
027. 
028./* Includes ------------------------------------------------------------------*/
029.#include "main.h"
030. 
031./** @addtogroup STM32F3_Discovery_Peripheral_Examples
032.  * @{
033.  */
034. 
035./** @addtogroup SysTick_Example
036.  * @{
037.  */
038. 
039./* Private typedef -----------------------------------------------------------*/
040./* Private define ------------------------------------------------------------*/
041./* Private macro -------------------------------------------------------------*/
042./* Private variables ---------------------------------------------------------*/
043.GPIO_InitTypeDef GPIO_InitStructure;
044.static __IO uint32_t TimingDelay;
045. 
046./* Private function prototypes -----------------------------------------------*/
047.void Delay(__IO uint32_t nTime);
048. 
049./* Private functions ---------------------------------------------------------*/
050. 
051./**
052.  * @brief   Main program
053.  * @param  None
054.  * @retval None
055.  */
056.int main(void)
057.{
058.  /*!< At this stage the microcontroller clock setting is already configured,
059.       this is done through SystemInit() function which is called from startup
060.       file (startup_stm32f30x.s) before to branch to application main.
061.       To reconfigure the default setting of SystemInit() function, refer to
062.       system_stm32f30x.c file
063.     */    
064.   
065.  /* Initialize Leds mounted on STM32F3-discovery */
066.  STM_EVAL_LEDInit(LED3);
067.  STM_EVAL_LEDInit(LED4);
068.  STM_EVAL_LEDInit(LED5);
069.  STM_EVAL_LEDInit(LED6);
070.  STM_EVAL_LEDInit(LED7);
071.  STM_EVAL_LEDInit(LED8);
072.  STM_EVAL_LEDInit(LED9);
073.  STM_EVAL_LEDInit(LED10);
074.   
075.  /* Turn On LED3 */
076.  STM_EVAL_LEDOn(LED3);
077.  /* Turn On LED7 */
078.  STM_EVAL_LEDOn(LED7);
079.  /* Turn On LED6 */
080.  STM_EVAL_LEDOn(LED6);
081.  /* Turn On LED10 */
082.  STM_EVAL_LEDOn(LED10);
083.   
084.  /* Setup SysTick Timer for 1 msec interrupts.
085.     ------------------------------------------
086.    1. The SysTick_Config() function is a CMSIS function which configure:
087.       - The SysTick Reload register with value passed as function parameter.
088.       - Configure the SysTick IRQ priority to the lowest value (0x0F).
089.       - Reset the SysTick Counter register.
090.       - Configure the SysTick Counter clock source to be Core Clock Source (HCLK).
091.       - Enable the SysTick Interrupt.
092.       - Start the SysTick Counter.
093.     
094.    2. You can change the SysTick Clock source to be HCLK_Div8 by calling the
095.       SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8) just after the
096.       SysTick_Config() function call. The SysTick_CLKSourceConfig() is defined
097.       inside the stm32f30x_misc.c file.
098. 
099.    3. You can change the SysTick IRQ priority by calling the
100.       NVIC_SetPriority(SysTick_IRQn,...) just after the SysTick_Config() function
101.       call. The NVIC_SetPriority() is defined inside the core_cm0.h file.
102. 
103.    4. To adjust the SysTick time base, use the following formula:
104.                             
105.         Reload Value = SysTick Counter Clock (Hz) x  Desired Time base (s)
106.     
107.       - Reload Value is the parameter to be passed for SysTick_Config() function
108.       - Reload Value should not exceed 0xFFFFFF
109.   */
110.  if (SysTick_Config(SystemCoreClock / 1000))
111.  {
112.    /* Capture error */
113.    while (1);
114.  }
115. 
116.  while (1)
117.  {
118.    /* Toggle LED3 */
119.    STM_EVAL_LEDToggle(LED3);
120.    /* Toggle LED7 */
121.    STM_EVAL_LEDToggle(LED7);
122.    /* Toggle LED6 */
123.    STM_EVAL_LEDToggle(LED6);
124.    /* Toggle LED10 */
125.    STM_EVAL_LEDToggle(LED10);
126.     
127.    /* Insert 100 ms delay */
128.    Delay(100);
129.     
130.    /* Toggle LED4 */
131.    STM_EVAL_LEDToggle(LED4);
132.    /* Toggle LED5 */
133.    STM_EVAL_LEDToggle(LED5);
134.    /* Toggle LED9 */
135.    STM_EVAL_LEDToggle(LED9);
136.    /* Toggle LED8 */
137.    STM_EVAL_LEDToggle(LED8);
138.     
139.    /* Insert 150 ms delay */
140.    Delay(150);
141.  }
142.}
143. 
144./**
145.  * @brief  Inserts a delay time.
146.  * @param  nTime: specifies the delay time length, in milliseconds.
147.  * @retval None
148.  */
149.void Delay(__IO uint32_t nTime)
150.{
151.  TimingDelay = nTime;
152. 
153.  while(TimingDelay != 0);
154.}
155. 
156./**
157.  * @brief  Decrements the TimingDelay variable.
158.  * @param  None
159.  * @retval None
160.  */
161.void TimingDelay_Decrement(void)
162.{
163.  if (TimingDelay != 0x00)
164.  {
165.    TimingDelay--;
166.  }
167.}
168. 
169.#ifdef  USE_FULL_ASSERT
170. 
171./**
172.  * @brief  Reports the name of the source file and the source line number
173.  *         where the assert_param error has occurred.
174.  * @param  file: pointer to the source file name
175.  * @param  line: assert_param error line source number
176.  * @retval None
177.  */
178.void assert_failed(uint8_t* file, uint32_t line)
179.{
180.  /* User can add his own implementation to report the file name and line number,
181.     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
182. 
183.  /* Infinite loop */
184.  while (1)
185.  {
186.  }
187.}
188.#endif
189. 
190./**
191.  * @}
192.  */
193. 
194./**
195.  * @}
196.  */
197. 
198./************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
 that i can't know is how the   Delay() , and TimingDelay_Decrement() function relate . 
ex : if i call delay(150) that meaning to according to declare delay() function 
void Delay(__IO uint32_t nTime)

  TimingDelay = nTime;


  while(TimingDelay != 0);

 i will have timemingDelay= 150 
and i can't to imagine for steps after that the program work 

thank for yours help !!!! 

Outcomes