Skip to content

Commit 169fa67

Browse files
kbumsikfpistm
authored andcommitted
[MP1] Add pseudo-EEPROM support for RETRAM
1 parent cd1cd50 commit 169fa67

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

cores/arduino/stm32/stm32_eeprom.c

+20
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ static inline uint32_t get_flash_end(void)
115115
defined(STM32WBxx)
116116
/* If FLASH_PAGE_NUMBER is defined by user, this is not really end of the flash */
117117
#define FLASH_END ((uint32_t)(FLASH_BASE + (((FLASH_PAGE_NUMBER +1) * FLASH_PAGE_SIZE))-1))
118+
#elif defined(EEPROM_RETRAM_MODE)
119+
#define FLASH_END ((uint32_t)(EEPROM_RETRAM_START_ADDRESS + EEPROM_RETRAM_MODE_SIZE -1))
118120
#endif
119121
#ifndef FLASH_END
120122
#error "FLASH_END could not be defined"
@@ -130,6 +132,8 @@ static inline uint32_t get_flash_end(void)
130132
*/
131133
#if defined(STM32L0xx)
132134
#define FLASH_BASE_ADDRESS ((uint32_t)(DATA_EEPROM_BASE))
135+
#elif defined(EEPROM_RETRAM_MODE)
136+
#define FLASH_BASE_ADDRESS EEPROM_RETRAM_START_ADDRESS
133137
#else
134138
#define FLASH_BASE_ADDRESS ((uint32_t)((FLASH_END + 1) - FLASH_PAGE_SIZE))
135139
#endif
@@ -194,6 +198,20 @@ void eeprom_buffer_fill(void)
194198
memcpy(eeprom_buffer, (uint8_t *)(FLASH_BASE_ADDRESS), E2END + 1);
195199
}
196200

201+
#if defined(EEPROM_RETRAM_MODE)
202+
203+
/**
204+
* @brief This function writes the buffer content into the flash
205+
* @param none
206+
* @retval none
207+
*/
208+
void eeprom_buffer_flush(void)
209+
{
210+
memcpy((uint8_t *)(FLASH_BASE_ADDRESS), eeprom_buffer, E2END + 1);
211+
}
212+
213+
#else /* defined(EEPROM_RETRAM_MODE) */
214+
197215
/**
198216
* @brief This function writes the buffer content into the flash
199217
* @param none
@@ -306,6 +324,8 @@ void eeprom_buffer_flush(void)
306324
#endif
307325
}
308326

327+
#endif /* defined(EEPROM_RETRAM_MODE) */
328+
309329
#ifdef __cplusplus
310330
}
311331
#endif

cores/arduino/stm32/stm32_eeprom.h

+26
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,31 @@ extern "C" {
4545

4646
/* Exported types ------------------------------------------------------------*/
4747
/* Exported constants --------------------------------------------------------*/
48+
#if defined(STM32MP1xx)
49+
/* Note for STM32MP1xx devices:
50+
* Those devices do not have non-volatile memory. The emulation is done
51+
* in RETRAM. Therefore data will be preserved *only* when VBAT is supplied
52+
* (e.g. A coin battery is connected to CN3 on STM32MP157A_DK1) and
53+
* the coprocessor is waken up from STANBY mode.
54+
* The data won't be preserved from cold boot, even if VBAT is connected.
55+
* See: https://community.st.com/s/question/0D50X0000B44pHUSQY/doesnt-the-mcu-coprocessor-have-nonvolatile-memory
56+
*/
57+
#define EEPROM_RETRAM_MODE
58+
/* 4kB is the same size as EEPROM size of ATMega2560. */
59+
#ifndef EEPROM_RETRAM_MODE_SIZE
60+
#define EEPROM_RETRAM_MODE_SIZE ((uint32_t)(4*1024))
61+
#endif
62+
/* RETRAM start address is 0x00000000 (retset entry) and end address is
63+
* 0x00020000 (64kB in total). The by default, ldscript.ld for STM32MP1xx
64+
* does not define address between 0x00000298 (end of ISR Vector) and 0x00020000.
65+
* So it is okay to use in this address range. Make sure ldscript.ld does not
66+
* overrap the following address range.
67+
*/
68+
#ifndef EEPROM_RETRAM_START_ADDRESS
69+
#define EEPROM_RETRAM_START_ADDRESS (0x00000400UL)
70+
#endif
71+
#define E2END (EEPROM_RETRAM_MODE_SIZE - 1)
72+
#else
4873
#ifndef FLASH_PAGE_SIZE
4974
/*
5075
* FLASH_PAGE_SIZE is not defined for STM32F2xx, STM32F4xx and STM32F7xx
@@ -56,6 +81,7 @@ extern "C" {
5681
#define FLASH_PAGE_SIZE ((uint32_t)(16*1024)) /* 16kB page */
5782
#endif
5883
#define E2END (FLASH_PAGE_SIZE - 1)
84+
#endif
5985

6086
/* Exported macro ------------------------------------------------------------*/
6187
/* Exported functions ------------------------------------------------------- */

0 commit comments

Comments
 (0)