STM32F10x_StdPeriph_Examples/GPIO/JTAG_Remap/main.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    GPIO/JTAG_Remap/main.c 
00004   * @author  MCD Application Team
00005   * @version V3.4.0
00006   * @date    10/15/2010
00007   * @brief   Main program body
00008   ******************************************************************************
00009   * @copy
00010   *
00011   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
00012   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
00013   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
00014   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
00015   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
00016   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
00017   *
00018   * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>
00019   */ 
00020 
00021 /* Includes ------------------------------------------------------------------*/
00022 #include "stm32f10x.h"
00023 #include "stm32_eval.h"
00024 
00025 /** @addtogroup STM32F10x_StdPeriph_Examples
00026   * @{
00027   */
00028 
00029 /** @addtogroup GPIO_JTAG_Remap
00030   * @{
00031   */
00032 
00033 /* Private typedef -----------------------------------------------------------*/
00034 /* Private define ------------------------------------------------------------*/
00035 /* Private macro -------------------------------------------------------------*/
00036 /* Private variables ---------------------------------------------------------*/
00037 GPIO_InitTypeDef GPIO_InitStructure;
00038 
00039 /* Private function prototypes -----------------------------------------------*/
00040 void RCC_Configuration(void);
00041 void Delay(__IO uint32_t nCount);
00042 
00043 /* Private functions ---------------------------------------------------------*/
00044 
00045 /**
00046   * @brief  Main program.
00047   * @param  None
00048   * @retval None
00049   */
00050 int main(void)
00051 {
00052   /*!< At this stage the microcontroller clock setting is already configured, 
00053        this is done through SystemInit() function which is called from startup
00054        file (startup_stm32f10x_xx.s) before to branch to application main.
00055        To reconfigure the default setting of SystemInit() function, refer to
00056        system_stm32f10x.c file
00057      */     
00058        
00059   /* Configure the system clocks */
00060   RCC_Configuration();
00061     
00062   /* Initialize LEDs and Key Button mounted on STM3210X-EVAL board */       
00063   STM_EVAL_LEDInit(LED1);
00064   STM_EVAL_LEDInit(LED2);
00065        
00066   STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO);
00067 
00068   /* Test if Key Button GPIO Pin level is low (Key push-button on Eval Board pressed) */
00069   if (STM_EVAL_PBGetState(BUTTON_KEY) == 0x00)
00070   { /* Key is pressed */
00071 
00072      /* Turn on LED1 */
00073      STM_EVAL_LEDOn(LED1);
00074 
00075     /* Disable the Serial Wire Jtag Debug Port SWJ-DP */
00076     GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable, ENABLE);
00077 
00078     /* Configure PA.13 (JTMS/SWDAT), PA.14 (JTCK/SWCLK) and PA.15 (JTDI) as 
00079        output push-pull */
00080     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
00081     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
00082     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
00083     GPIO_Init(GPIOA, &GPIO_InitStructure);
00084 
00085     /* Configure PB.03 (JTDO) and PB.04 (JTRST) as output push-pull */
00086     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4;
00087     GPIO_Init(GPIOB, &GPIO_InitStructure);
00088 
00089     while (1)
00090     {
00091       /* Toggle JTMS/SWDAT pin */
00092       GPIO_WriteBit(GPIOA, GPIO_Pin_13, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOA, GPIO_Pin_13)));
00093       /* Insert delay */
00094       Delay(0x5FFFF);
00095 
00096       /* Toggle JTCK/SWCLK pin */
00097       GPIO_WriteBit(GPIOA, GPIO_Pin_14, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOA, GPIO_Pin_14)));
00098       /* Insert delay */
00099       Delay(0x5FFFF);
00100 
00101       /* Toggle JTDI pin */
00102       GPIO_WriteBit(GPIOA, GPIO_Pin_15, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOA, GPIO_Pin_15)));
00103       /* Insert delay */
00104       Delay(0x5FFFF);
00105 
00106       /* Toggle JTDO pin */
00107       GPIO_WriteBit(GPIOB, GPIO_Pin_3, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOB, GPIO_Pin_3)));
00108       /* Insert delay */
00109       Delay(0x5FFFF);
00110 
00111       /* Toggle JTRST pin */
00112       GPIO_WriteBit(GPIOB, GPIO_Pin_4, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOB, GPIO_Pin_4)));
00113       /* Insert delay */
00114       Delay(0x5FFFF);
00115     }
00116   }
00117   else
00118   {
00119     /* Turn on LED2 */
00120     STM_EVAL_LEDOn(LED2);
00121 
00122     while (1)
00123     {
00124     }
00125   }
00126 }
00127 
00128 /**
00129   * @brief  Configures the different system clocks.
00130   * @param  None
00131   * @retval None
00132   */
00133 void RCC_Configuration(void)
00134 {  
00135   /* Enable GPIOA, GPIOB, RCC_APB2Periph_GPIO_KEY_BUTTON and AFIO clocks */
00136   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
00137                          RCC_APB2Periph_AFIO, ENABLE);
00138 }
00139 
00140 /**
00141   * @brief  Inserts a delay time.
00142   * @param  nCount: specifies the delay time length.
00143   * @retval None
00144   */
00145 void Delay(__IO uint32_t nCount)
00146 {
00147   for(; nCount != 0; nCount--);
00148 }
00149 
00150 #ifdef  USE_FULL_ASSERT
00151 /**
00152   * @brief  Reports the name of the source file and the source line number
00153   *         where the assert_param error has occurred.
00154   * @param  file: pointer to the source file name
00155   * @param  line: assert_param error line source number
00156   * @retval None
00157   */
00158 void assert_failed(uint8_t* file, uint32_t line)
00159 { 
00160   /* User can add his own implementation to report the file name and line number,
00161      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00162 
00163   /* Infinite loop */
00164   while (1)
00165   {
00166   }
00167 }
00168 #endif
00169 
00170 /**
00171   * @}
00172   */
00173 
00174 /**
00175   * @}
00176   */
00177 
00178 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
STM32F10x Standard Peripherals Library: Footer

 

 

 

      For complete documentation on STM32(CORTEX M3) 32-bit Microcontrollers platform visit  www.st.com/STM32