STM8S/A Standard Peripherals Firmware Library
|
STM8S_StdPeriph_Examples/FLASH/FLASH_ByteReadWriteOperation/main.c
Go to the documentation of this file.
00001 /** 00002 ****************************************************************************** 00003 * @file FLASH_ByteReadWriteOperation\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 byte read write operation 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_ByteReadWriteOperation 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; 00042 /* Private function prototypes -----------------------------------------------*/ 00043 /* Private functions ---------------------------------------------------------*/ 00044 /* Public functions ----------------------------------------------------------*/ 00045 00046 /** 00047 * @brief How to Read / Write / Erase one Byte on FLASH memory. 00048 * @par Examples description 00049 * - Read one byte at address 0x40A5 00050 * - Write its complement value at adress + 1 00051 * - Check programed value 00052 * - Erase 2 byte (address 40A5 & 40A6) 00053 * - Check the 2 bytes value is 0x00. 00054 * @param None 00055 * @retval None 00056 */ 00057 void main(void) 00058 { 00059 00060 uint8_t val = 0x00, val_comp = 0x00; 00061 uint32_t add = 0x00; 00062 00063 /* Define FLASH programming time */ 00064 FLASH_SetProgrammingTime(FLASH_PROGRAMTIME_STANDARD); 00065 00066 /* Unlock Data memory */ 00067 FLASH_Unlock(FLASH_MEMTYPE_DATA); 00068 00069 /* Read a byte at a specified address */ 00070 add = 0x40A5; 00071 val = FLASH_ReadByte(add); 00072 00073 /* Program complement value (of previous read byte) at previous address + 1 */ 00074 val_comp = (uint8_t)(~val); 00075 FLASH_ProgramByte((add + 1), val_comp); 00076 00077 /* Check program action */ 00078 val = FLASH_ReadByte((add + 1)); 00079 if (val != val_comp) 00080 { 00081 /* Error */ 00082 OperationStatus = FAILED; 00083 /* OperationStatus = PASSED, if the data written/read to/from DATA EEPROM memory is correct */ 00084 /* OperationStatus = FAILED, if the data written/read to/from DATA EEPROM memory is corrupted */ 00085 while (1) 00086 { 00087 } 00088 } 00089 00090 /* Erase byte at a specified address & address + 1 */ 00091 FLASH_EraseByte(add); 00092 FLASH_EraseByte((add + 1)); 00093 /* Erase action */ 00094 val = FLASH_ReadByte(add); 00095 val_comp = FLASH_ReadByte((add + 1)); 00096 if ((val != 0x00) & (val_comp != 0x00)) 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 } 00106 00107 /* Pass */ 00108 OperationStatus = PASSED; 00109 /* OperationStatus = PASSED, if the data written/read to/from DATA EEPROM memory is correct */ 00110 /* OperationStatus = FAILED, if the data written/read to/from DATA EEPROM memory is corrupted */ 00111 while (1) 00112 { 00113 } 00114 } 00115 00116 #ifdef USE_FULL_ASSERT 00117 00118 /** 00119 * @brief Reports the name of the source file and the source line number 00120 * where the assert_param error has occurred. 00121 * @param file: pointer to the source file name 00122 * @param line: assert_param error line source number 00123 * @retval None 00124 */ 00125 void assert_failed(uint8_t* file, uint32_t line) 00126 { 00127 /* User can add his own implementation to report the file name and line number, 00128 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 00129 00130 /* Infinite loop */ 00131 while (1) 00132 { 00133 } 00134 } 00135 #endif 00136 00137 /** 00138 * @} 00139 */ 00140 00141 00142 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/