Prusa MINI Firmware overview
eeprom_emul.h
Go to the documentation of this file.
1 /******************************************************************************
2  * @file eeprom_emul.h
3  * @author MCD Application Team
4  * @version V1.2.6
5  * @date 04-November-2016
6  * @brief This file contains all the functions prototypes for the EEPROM
7  * emulation firmware library.
8  ******************************************************************************
9  * @attention
10  *
11  * Copyright © 2016 STMicroelectronics International N.V.
12  * All rights reserved.</center></h2>
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted, provided that the following conditions are met:
16  *
17  * 1. Redistribution of source code must retain the above copyright notice,
18  * this list of conditions and the following disclaimer.
19  * 2. Redistributions in binary form must reproduce the above copyright notice,
20  * this list of conditions and the following disclaimer in the documentation
21  * and/or other materials provided with the distribution.
22  * 3. Neither the name of STMicroelectronics nor the names of other
23  * contributors to this software may be used to endorse or promote products
24  * derived from this software without specific written permission.
25  * 4. This software, including modifications and/or derivative works of this
26  * software, must execute solely and exclusively on microcontroller or
27  * microprocessor devices manufactured by or for STMicroelectronics.
28  * 5. Redistribution and use of this software other than as permitted under
29  * this license is void and will automatically terminate your rights under
30  * this license.
31  *
32  * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
33  * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
34  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
35  * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
36  * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
37  * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
38  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
39  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
40  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
41  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
42  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
43  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44  *
45  ******************************************************************************/
46 #pragma once
47 
48 // ------------------------
49 // Includes
50 // ------------------------
51 
52 #include "../../inc/MarlinConfig.h"
53 #include "HAL.h"
54 
55 /* Exported constants --------------------------------------------------------*/
56 /* EEPROM emulation firmware error codes */
57 #define EE_OK uint32_t(HAL_OK)
58 #define EE_ERROR uint32_t(HAL_ERROR)
59 #define EE_BUSY uint32_t(HAL_BUSY)
60 #define EE_TIMEOUT uint32_t(HAL_TIMEOUT)
61 
62 /* Define the size of the sectors to be used */
63 #define PAGE_SIZE uint32_t(0x4000) /* Page size = 16KByte */
64 
65 /* Device voltage range supposed to be [2.7V to 3.6V], the operation will
66  be done by word */
67 #define VOLTAGE_RANGE uint8_t(VOLTAGE_RANGE_3)
68 
69 /* EEPROM start address in Flash */
70 #ifdef STM32F7
71  #define EEPROM_START_ADDRESS uint32_t(0x08100000) /* EEPROM emulation start address:
72  from sector2 : after 16KByte of used
73  Flash memory */
74 #else
75  #define EEPROM_START_ADDRESS uint32_t(0x08078000) /* EEPROM emulation start address:
76  after 480KByte of used Flash memory */
77 #endif
78 
79 /* Pages 0 and 1 base and end addresses */
80 #define PAGE0_BASE_ADDRESS uint32_t(EEPROM_START_ADDRESS + 0x0000)
81 #define PAGE0_END_ADDRESS uint32_t(EEPROM_START_ADDRESS + PAGE_SIZE - 1)
82 #define PAGE0_ID FLASH_SECTOR_1
83 
84 #define PAGE1_BASE_ADDRESS uint32_t(EEPROM_START_ADDRESS + 0x4000)
85 #define PAGE1_END_ADDRESS uint32_t(EEPROM_START_ADDRESS + 2 * (PAGE_SIZE) - 1)
86 #define PAGE1_ID FLASH_SECTOR_2
87 
88 /* Used Flash pages for EEPROM emulation */
89 #define PAGE0 uint16_t(0x0000)
90 #define PAGE1 uint16_t(0x0001) /* Page nb between PAGE0_BASE_ADDRESS & PAGE1_BASE_ADDRESS*/
91 
92 /* No valid page define */
93 #define NO_VALID_PAGE uint16_t(0x00AB)
94 
95 /* Page status definitions */
96 #define ERASED uint16_t(0xFFFF) /* Page is empty */
97 #define RECEIVE_DATA uint16_t(0xEEEE) /* Page is marked to receive data */
98 #define VALID_PAGE uint16_t(0x0000) /* Page containing valid data */
99 
100 /* Valid pages in read and write defines */
101 #define READ_FROM_VALID_PAGE uint8_t(0x00)
102 #define WRITE_IN_VALID_PAGE uint8_t(0x01)
103 
104 /* Page full define */
105 #define PAGE_FULL uint8_t(0x80)
106 
107 /* Variables' number */
108 #define NB_OF_VAR uint16_t(4096)
109 
110 /* Exported functions ------------------------------------------------------- */
111 uint16_t EE_Initialize();
112 uint16_t EE_ReadVariable(uint16_t VirtAddress, uint16_t* Data);
113 uint16_t EE_WriteVariable(uint16_t VirtAddress, uint16_t Data);
114 
115 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
FLASH_TYPEERASE_SECTORS
#define FLASH_TYPEERASE_SECTORS
Definition: stm32f4xx_hal_flash_ex.h:162
WRITE_IN_VALID_PAGE
#define WRITE_IN_VALID_PAGE
Definition: eeprom_emul.h:102
EE_ReadVariable
uint16_t EE_ReadVariable(uint16_t VirtAddress, uint16_t *Data)
FLASH_EraseInitTypeDef::NbSectors
uint32_t NbSectors
Definition: stm32f4xx_hal_flash_ex.h:74
HAL_OK
Definition: stm32f4xx_hal_def.h:57
ERASED
#define ERASED
Definition: eeprom_emul.h:96
TYPEERASE_SECTORS
#define TYPEERASE_SECTORS
Definition: stm32_hal_legacy.h:291
HAL_FLASHEx_Erase
HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *SectorError)
PAGE1
#define PAGE1
Definition: eeprom_emul.h:90
NO_VALID_PAGE
#define NO_VALID_PAGE
Definition: eeprom_emul.h:93
eeprom_emul.h
FLASH_EraseInitTypeDef::Sector
uint32_t Sector
Definition: stm32f4xx_hal_flash_ex.h:71
EE_Initialize
uint16_t EE_Initialize()
EE_WriteVariable
uint16_t EE_WriteVariable(uint16_t VirtAddress, uint16_t Data)
RECEIVE_DATA
#define RECEIVE_DATA
Definition: eeprom_emul.h:97
NB_OF_VAR
#define NB_OF_VAR
Definition: eeprom_emul.h:108
HAL_StatusTypeDef
HAL_StatusTypeDef
HAL Status structures definition.
Definition: stm32f4xx_hal_def.h:55
PAGE_SIZE
#define PAGE_SIZE
Definition: eeprom_emul.h:63
PAGE0_END_ADDRESS
#define PAGE0_END_ADDRESS
Definition: eeprom_emul.h:81
PAGE1_ID
#define PAGE1_ID
Definition: eeprom_emul.h:86
FLASH_EraseInitTypeDef::TypeErase
uint32_t TypeErase
Definition: stm32f4xx_hal_flash_ex.h:65
PAGE_FULL
#define PAGE_FULL
Definition: eeprom_emul.h:105
FLASH_EraseInitTypeDef::VoltageRange
uint32_t VoltageRange
Definition: stm32f4xx_hal_flash_ex.h:77
HAL_FLASH_Program
HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data)
PAGE0_BASE_ADDRESS
#define PAGE0_BASE_ADDRESS
Definition: eeprom_emul.h:80
uint8_t
const uint8_t[]
Definition: 404_html.c:3
READ_FROM_VALID_PAGE
#define READ_FROM_VALID_PAGE
Definition: eeprom_emul.h:101
HAL.h
PAGE0
#define PAGE0
Definition: eeprom_emul.h:89
EEPROM_START_ADDRESS
#define EEPROM_START_ADDRESS
Definition: eeprom_emul.h:75
TYPEPROGRAM_HALFWORD
#define TYPEPROGRAM_HALFWORD
Definition: stm32_hal_legacy.h:288
PAGE0_ID
#define PAGE0_ID
Definition: eeprom_emul.h:82
VOLTAGE_RANGE
#define VOLTAGE_RANGE
Definition: eeprom_emul.h:67
PAGE1_BASE_ADDRESS
#define PAGE1_BASE_ADDRESS
Definition: eeprom_emul.h:84
VALID_PAGE
#define VALID_PAGE
Definition: eeprom_emul.h:98
FLASH_EraseInitTypeDef
FLASH Erase structure definition.
Definition: stm32f4xx_hal_flash_ex.h:63