Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 136cf8f

Browse filesBrowse files
committed
[EEPROM] Add pseudo-EEPROM support for MP1 RETRAM
1 parent 442ca6c commit 136cf8f
Copy full SHA for 136cf8f

File tree

2 files changed

+64
-5
lines changed
Filter options

2 files changed

+64
-5
lines changed

‎cores/arduino/stm32/stm32_eeprom.c

Copy file name to clipboardExpand all lines: cores/arduino/stm32/stm32_eeprom.c
+38Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@
3939
extern "C" {
4040
#endif
4141

42+
#ifndef EEPROM_RETRAM_MODE /* Buffering not needed in RETRAM mode */
43+
44+
static void eeprom_buffer_fill();
45+
static void eeprom_buffer_flush();
46+
static uint8_t eeprom_buffered_read_byte(const uint32_t pos);
47+
static void eeprom_buffered_write_byte(uint32_t pos, uint8_t value);
48+
4249
/* Be able to change FLASH_BANK_NUMBER to use if relevant */
4350
#if !defined(FLASH_BANK_NUMBER) &&\
4451
(defined(STM32F0xx) || defined(STM32F1xx) || defined(STM32G4xx) ||\
@@ -306,6 +313,37 @@ void eeprom_buffer_flush(void)
306313
#endif
307314
}
308315

316+
#else /* EEPROM_RETRAM_MODE */
317+
/**
318+
* @brief Function reads a byte from emulated eeprom (flash)
319+
* @param pos : address to read
320+
* @retval byte : data read from eeprom
321+
*/
322+
uint8_t eeprom_read_byte(const uint32_t pos)
323+
{
324+
uint8_t tmp;
325+
if (pos > E2END) {
326+
return 0;
327+
}
328+
memcpy(&tmp, (uint8_t *)(EEPROM_RETRAM_START_ADDRESS + pos), sizeof(uint8_t));
329+
return tmp;
330+
}
331+
332+
/**
333+
* @brief Function writes a byte to emulated eeprom (flash)
334+
* @param pos : address to write
335+
* @param value : value to write
336+
* @retval none
337+
*/
338+
void eeprom_write_byte(uint32_t pos, uint8_t value)
339+
{
340+
if (pos > E2END) {
341+
return;
342+
}
343+
memcpy((uint8_t *)(EEPROM_RETRAM_START_ADDRESS + pos), &value, sizeof(uint8_t));
344+
}
345+
#endif /* EEPROM_RETRAM_MODE */
346+
309347
#ifdef __cplusplus
310348
}
311349
#endif

‎cores/arduino/stm32/stm32_eeprom.h

Copy file name to clipboardExpand all lines: cores/arduino/stm32/stm32_eeprom.h
+26-5Lines changed: 26 additions & 5 deletions
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,18 +81,14 @@ 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 ------------------------------------------------------- */
6288

6389
uint8_t eeprom_read_byte(const uint32_t pos);
6490
void eeprom_write_byte(uint32_t pos, uint8_t value);
6591

66-
void eeprom_buffer_fill();
67-
void eeprom_buffer_flush();
68-
uint8_t eeprom_buffered_read_byte(const uint32_t pos);
69-
void eeprom_buffered_write_byte(uint32_t pos, uint8_t value);
70-
7192
#ifdef __cplusplus
7293
}
7394
#endif

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.