STM32F0xx Standard Peripherals Firmware Library: main.c Source File

STM32F0xx Standard Peripherals Library

STM32F0xx_StdPeriph_Examples/GPIO/GPIO_IOToggle/main.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    GPIO/GPIO_IOToggle/main.c 
00004   * @author  MCD Application Team
00005   * @version V1.4.0
00006   * @date    24-July-2014
00007   * @brief   Main program body
00008   ******************************************************************************
00009   * @attention
00010   *
00011   * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
00012   *
00013   * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
00014   * You may not use this file except in compliance with the License.
00015   * You may obtain a copy of the License at:
00016   *
00017   *        http://www.st.com/software_license_agreement_liberty_v2
00018   *
00019   * Unless required by applicable law or agreed to in writing, software 
00020   * distributed under the License is distributed on an "AS IS" BASIS, 
00021   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00022   * See the License for the specific language governing permissions and
00023   * limitations under the License.
00024   *
00025   ******************************************************************************
00026   */
00027 
00028 /* Includes ------------------------------------------------------------------*/
00029 #include "main.h"
00030 
00031 /** @addtogroup STM32F0xx_StdPeriph_Examples
00032   * @{
00033   */
00034 
00035 /** @addtogroup GPIO_IOToggle
00036   * @{
00037   */
00038 
00039 /* Private typedef -----------------------------------------------------------*/
00040 /* Private define ------------------------------------------------------------*/
00041 #define BSRR_VAL 0x0C00
00042 
00043 /* Private macro -------------------------------------------------------------*/
00044 /* Private variables ---------------------------------------------------------*/
00045 GPIO_InitTypeDef        GPIO_InitStructure;
00046 
00047 /* Private function prototypes -----------------------------------------------*/
00048 /* Private functions ---------------------------------------------------------*/
00049 
00050 /**
00051   * @brief  Main program.
00052   * @param  None
00053   * @retval None
00054   */
00055 int main(void)
00056 {
00057   /*!< At this stage the microcontroller clock setting is already configured, 
00058        this is done through SystemInit() function which is called from startup
00059        file (startup_stm32f0xx.s) before to branch to application main.
00060        To reconfigure the default setting of SystemInit() function, refer to
00061        system_stm32f0xx.c file
00062      */
00063 
00064   /* GPIOC Periph clock enable */
00065   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);
00066 
00067   /* Configure PC10 and PC11 in output pushpull mode */
00068   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;
00069   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
00070   GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
00071   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
00072   GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
00073   GPIO_Init(GPIOC, &GPIO_InitStructure);
00074 
00075   /* To achieve GPIO toggling maximum frequency, the following  sequence is mandatory. 
00076      You can monitor PC10 and PC11 on the scope to measure the output signal. 
00077      If you need to fine tune this frequency, you can add more GPIO set/reset 
00078      cycles to minimize more the infinite loop timing.
00079      This code needs to be compiled with high speed optimization option.  */
00080   while (1)
00081   {
00082     /* Set PC10 and PC11 */
00083     GPIOC->BSRR = BSRR_VAL;
00084     /* Reset PC10 and PC11 */
00085     GPIOC->BRR = BSRR_VAL;
00086 
00087     /* Set PC10 and PC11 */
00088     GPIOC->BSRR = BSRR_VAL;
00089     /* Reset PC10 and PC11 */
00090     GPIOC->BRR = BSRR_VAL;
00091 
00092     /* Set PC10 and PC11 */
00093     GPIOC->BSRR = BSRR_VAL;
00094     /* Reset PC10 and PC11 */
00095     GPIOC->BRR = BSRR_VAL;
00096 
00097     /* Set PC10 and PC11 */
00098     GPIOC->BSRR = BSRR_VAL;
00099     /* Reset PC10 and PC11 */
00100     GPIOC->BRR = BSRR_VAL;
00101 
00102     /* Set PC10 and PC11 */
00103     GPIOC->BSRR = BSRR_VAL;
00104     /* Reset PC10 and PC11 */
00105     GPIOC->BRR = BSRR_VAL;
00106 
00107     /* Set PC10 and PC11 */
00108     GPIOC->BSRR = BSRR_VAL;
00109     /* Reset PC10 and PC11 */
00110     GPIOC->BRR = BSRR_VAL;
00111 
00112     /* Set PC10 and PC11 */
00113     GPIOC->BSRR = BSRR_VAL;
00114     /* Reset PC10 and PC11 */
00115     GPIOC->BRR = BSRR_VAL;
00116 
00117     /* Set PC10 and PC11 */
00118     GPIOC->BSRR = BSRR_VAL;
00119     /* Reset PC10 and PC11 */
00120     GPIOC->BRR = BSRR_VAL;
00121 
00122     /* Set PC10 and PC11 */
00123     GPIOC->BSRR = BSRR_VAL;
00124     /* Reset PC10 and PC11 */
00125     GPIOC->BRR = BSRR_VAL;
00126 
00127     /* Set PC10 and PC11 */
00128     GPIOC->BSRR = BSRR_VAL;
00129     /* Reset PC10 and PC11 */
00130     GPIOC->BRR = BSRR_VAL;
00131   }
00132 }
00133 
00134 #ifdef  USE_FULL_ASSERT
00135 
00136 /**
00137   * @brief  Reports the name of the source file and the source line number
00138   *         where the assert_param error has occurred.
00139   * @param  file: pointer to the source file name
00140   * @param  line: assert_param error line source number
00141   * @retval None
00142   */
00143 void assert_failed(uint8_t* file, uint32_t line)
00144 {
00145   /* User can add his own implementation to report the file name and line number,
00146      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00147 
00148   /* Infinite loop */
00149   while (1)
00150   {
00151   }
00152 }
00153 #endif
00154 
00155 /**
00156   * @}
00157   */
00158 
00159 /**
00160   * @}
00161   */
00162 
00163 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
STM32L1xx Standard Peripherals Library: Footer

 

 

 For complete documentation on STM32 Microcontrollers visit www.st.com/STM32