Skip to main content
Aimee
Visitor II
November 29, 2022
Solved

X-CUBE-EEPROM calculation of PAGES_NUMBER from NB_OF_VARIABLES is off by one

  • November 29, 2022
  • 1 reply
  • 993 views

In X-CUBE-EEPROM, the calculation of PAGES_NUMBER from NB_OF_VARIABLES is defined as:

#define PAGES_NUMBER (((((NB_OF_VARIABLES + NB_MAX_ELEMENTS_BY_PAGE) / NB_MAX_ELEMENTS_BY_PAGE) * 2U) * CYCLES_NUMBER) + GUARD_PAGES_NUMBER)

With a 2K flash page and a 32-byte header, 252 8-byte variables will fit in one page, as stated in AN4894. However, setting NB_OF_VARIABLES to 252 allocates an extra page.

To get the correct number of pages it should be:

#define PAGES_NUMBER (((((NB_OF_VARIABLES + NB_MAX_ELEMENTS_BY_PAGE - 1U) / NB_MAX_ELEMENTS_BY_PAGE) * 2U) * CYCLES_NUMBER) + GUARD_PAGES_NUMBER)

This topic has been closed for replies.
Best answer by Imen.D

Hello @Aimee​ ,

Welcome to the STM32 Community and thank you for having reported this issue.

I have submitted an internal ticket (ID 140029) for analysis and work with our development team.

(PS: ID 140029 is an internal tracking number and is not accessible outside of ST).

Thanks

Imen

1 reply

Imen.DBest answer
Technical Moderator
November 29, 2022

Hello @Aimee​ ,

Welcome to the STM32 Community and thank you for having reported this issue.

I have submitted an internal ticket (ID 140029) for analysis and work with our development team.

(PS: ID 140029 is an internal tracking number and is not accessible outside of ST).

Thanks

Imen

"When your question is answered, please close this topic by clicking ""Accept as Solution"".ThanksImen"