STM8S/A Standard Peripherals Firmware Library
|
STM8S_StdPeriph_Examples/RST/RST_IllegalOpcode/main.c
Go to the documentation of this file.
00001 /** 00002 ****************************************************************************** 00003 * @file RST_IllegalOpcode\main.c 00004 * @author MCD Application Team 00005 * @version V2.2.0 00006 * @date 30-September-2014 00007 * @brief This file contains the main function for RST Illegal Opcode example. 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© 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 "stm8s.h" 00030 #include "stm8s_eval.h" 00031 00032 00033 /** 00034 * @addtogroup RST_IllegalOpcode 00035 * @{ 00036 */ 00037 00038 /* Private typedef -----------------------------------------------------------*/ 00039 00040 /* Private define ------------------------------------------------------------*/ 00041 /* Private macro -------------------------------------------------------------*/ 00042 /* Private variables ---------------------------------------------------------*/ 00043 /* Private function prototypes -----------------------------------------------*/ 00044 static void GPIO_Config(void); 00045 void Delay (uint16_t nCount); 00046 /* Private functions ---------------------------------------------------------*/ 00047 /* Public functions ----------------------------------------------------------*/ 00048 00049 /** 00050 * @brief Main program. 00051 * @param None 00052 * @retval None 00053 */ 00054 void main(void) 00055 { 00056 uint8_t i =0; 00057 FlagStatus IllOpFlag = RESET; 00058 00059 enableInterrupts(); 00060 00061 /* GPIO Configuration ------------------------------------------*/ 00062 GPIO_Config(); 00063 00064 /* Unlock Flash */ 00065 FLASH_Unlock(FLASH_MEMTYPE_PROG); 00066 00067 /* Get Illegal Opcode flag status */ 00068 IllOpFlag = RST_GetFlagStatus(RST_FLAG_ILLOPF); 00069 00070 /* Test if a ILLOP Reset has occurred */ 00071 if (IllOpFlag) 00072 { 00073 for (i=0;i<50;i++) 00074 { 00075 /* An ILLOP Reset has occurred, Toggles LD1, LD2, LD3 and LD4 */ 00076 STM_EVAL_LEDToggle(LED1); 00077 STM_EVAL_LEDToggle(LED2); 00078 STM_EVAL_LEDToggle(LED3); 00079 STM_EVAL_LEDToggle(LED4); 00080 /* delay */ 00081 Delay(0x7FFF); 00082 } 00083 /* Clear ILLOP Flag */ 00084 RST_ClearFlag(RST_FLAG_ILLOPF); 00085 } 00086 00087 /* Write an illegal opcode */ 00088 FLASH_ProgramByte(0x9FFF, 0x75); 00089 00090 while (1) 00091 { 00092 /* Toggle Leds */ 00093 STM_EVAL_LEDToggle(LED1); 00094 STM_EVAL_LEDToggle(LED2); 00095 STM_EVAL_LEDToggle(LED3); 00096 STM_EVAL_LEDToggle(LED4); 00097 Delay(0xFFFF); 00098 } 00099 00100 } 00101 00102 /** 00103 * @brief Configure GPIO for LEDs and buttons available on the evaluation board 00104 * @param None 00105 * @retval None 00106 */ 00107 static void GPIO_Config(void) 00108 { 00109 /* Initialize LEDs mounted on STM8-128 EVAL board */ 00110 STM_EVAL_LEDInit(LED1); 00111 STM_EVAL_LEDInit(LED2); 00112 STM_EVAL_LEDInit(LED3); 00113 STM_EVAL_LEDInit(LED4); 00114 00115 /* Initialize KEY pushbutton mounted on STM8-128 EVAL board */ 00116 STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI); 00117 00118 /* Switch LEDs Off */ 00119 STM_EVAL_LEDOff(LED1); 00120 STM_EVAL_LEDOff(LED2); 00121 STM_EVAL_LEDOff(LED3); 00122 STM_EVAL_LEDOff(LED4); 00123 } 00124 00125 /** 00126 * @brief Delay. 00127 * @param nCount 00128 * @retval None 00129 */ 00130 void Delay(uint16_t nCount) 00131 { 00132 /* Decrement nCount value */ 00133 while (nCount != 0) 00134 { 00135 nCount--; 00136 } 00137 } 00138 00139 #ifdef USE_FULL_ASSERT 00140 00141 /** 00142 * @brief Reports the name of the source file and the source line number 00143 * where the assert_param error has occurred. 00144 * @param file: pointer to the source file name 00145 * @param line: assert_param error line source number 00146 * @retval None 00147 */ 00148 void assert_failed(uint8_t* file, uint32_t line) 00149 { 00150 /* User can add his own implementation to report the file name and line number, 00151 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 00152 00153 /* Infinite loop */ 00154 while (1) 00155 { 00156 } 00157 } 00158 #endif 00159 00160 /** 00161 * @} 00162 */ 00163 00164 00165 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/