STM8S/A Standard Peripherals Firmware Library
|
STM8S_StdPeriph_Examples/FLASH/FLASH_WriteWordOperation/main.c
Go to the documentation of this file.
00001 /** 00002 ****************************************************************************** 00003 * @file FLASH_WriteWord\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 FLASH write word 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 00031 /** 00032 * @addtogroup FLASH_WriteWord 00033 * @{ 00034 */ 00035 00036 /* Private typedef -----------------------------------------------------------*/ 00037 typedef enum { FAILED = 0, PASSED = !FAILED} TestStatus; 00038 /* Private define ------------------------------------------------------------*/ 00039 /* Private macro -------------------------------------------------------------*/ 00040 /* Private variables ---------------------------------------------------------*/ 00041 __IO TestStatus OperationStatus = FAILED; 00042 /* Private function prototypes -----------------------------------------------*/ 00043 /* Private functions ---------------------------------------------------------*/ 00044 /* Public functions ----------------------------------------------------------*/ 00045 00046 /** 00047 * @brief How to Write a word & Erase Byte on Data EEPROM memory. 00048 * @par Examples description 00049 * - Program a word at address 0x4100 00050 * - Check program using Read byte 00051 * - Erase word using erase byte 00052 * - Check the 4 bytes (word) value is 0x00. 00053 * @param None 00054 * @retval None 00055 */ 00056 void main(void) 00057 { 00058 uint32_t start_add = 0x4100; 00059 uint32_t add = 0x00; 00060 uint32_t new_val = 0x01234567; 00061 uint8_t sub_test_count = 0x00, val = 0x00; 00062 00063 /*Define FLASH programming time*/ 00064 FLASH_SetProgrammingTime(FLASH_PROGRAMTIME_STANDARD); 00065 /* Unlock Data memory */ 00066 FLASH_Unlock(FLASH_MEMTYPE_DATA); 00067 00068 /* Program word at address 0x4100*/ 00069 FLASH_ProgramWord(start_add, new_val); 00070 00071 /* Check program word action */ 00072 val = FLASH_ReadByte(start_add); 00073 add = start_add; 00074 if (val != BYTE_3(new_val)) 00075 { 00076 /* Error */ 00077 OperationStatus = FAILED; 00078 /* OperationStatus = PASSED, if the data written/read to/from DATA EEPROM memory is correct */ 00079 /* OperationStatus = FAILED, if the data written/read to/from DATA EEPROM memory is corrupted */ 00080 while (1); 00081 } 00082 00083 add += 1; 00084 val = FLASH_ReadByte(add); 00085 if (val != BYTE_2(new_val)) 00086 { 00087 /* Error */ 00088 OperationStatus = FAILED; 00089 /* OperationStatus = PASSED, if the data written/read to/from DATA EEPROM memory is correct */ 00090 /* OperationStatus = FAILED, if the data written/read to/from DATA EEPROM memory is corrupted */ 00091 while (1); 00092 } 00093 00094 add += 1; 00095 val = FLASH_ReadByte(add); 00096 if (val != BYTE_1(new_val)) 00097 { 00098 /* Error */ 00099 OperationStatus = FAILED; 00100 /* OperationStatus = PASSED, if the data written/read to/from DATA EEPROM memory is correct */ 00101 /* OperationStatus = FAILED, if the data written/read to/from DATA EEPROM memory is corrupted */ 00102 while (1); 00103 } 00104 00105 add += 1; 00106 val = FLASH_ReadByte(add); 00107 if (val != BYTE_0(new_val)) 00108 { 00109 /* Error */ 00110 OperationStatus = FAILED; 00111 /* OperationStatus = PASSED, if the data written/read to/from DATA EEPROM memory is correct */ 00112 /* OperationStatus = FAILED, if the data written/read to/from DATA EEPROM memory is corrupted */ 00113 while (1); 00114 } 00115 00116 /* Erase word using Erase byte */ 00117 add = start_add; 00118 for (sub_test_count = 0; sub_test_count < 4; sub_test_count++) 00119 { 00120 FLASH_EraseByte(add); 00121 add += 1; 00122 } 00123 00124 /* Verify Erase action */ 00125 add = start_add; 00126 for (sub_test_count = 0; sub_test_count < 4; sub_test_count++) 00127 { 00128 val = FLASH_ReadByte(add); 00129 if (val != 0x00) 00130 { 00131 /* Error */ 00132 OperationStatus = FAILED; 00133 /* OperationStatus = PASSED, if the data written/read to/from DATA EEPROM memory is correct */ 00134 /* OperationStatus = FAILED, if the data written/read to/from DATA EEPROM memory is corrupted */ 00135 while (1); 00136 } 00137 add += 1; 00138 } 00139 00140 /* Pass */ 00141 OperationStatus = PASSED; 00142 /* OperationStatus = PASSED, if the data written/read to/from DATA EEPROM memory is correct */ 00143 /* OperationStatus = FAILED, if the data written/read to/from DATA EEPROM memory is corrupted */ 00144 while (1); 00145 00146 } 00147 00148 #ifdef USE_FULL_ASSERT 00149 00150 /** 00151 * @brief Reports the name of the source file and the source line number 00152 * where the assert_param error has occurred. 00153 * @param file: pointer to the source file name 00154 * @param line: assert_param error line source number 00155 * @retval None 00156 */ 00157 void assert_failed(uint8_t* file, uint32_t line) 00158 { 00159 /* User can add his own implementation to report the file name and line number, 00160 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 00161 00162 /* Infinite loop */ 00163 while (1) 00164 { 00165 } 00166 } 00167 #endif 00168 00169 /** 00170 * @} 00171 */ 00172 00173 00174 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/