Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpu/stm32f7/4/2: add flashpage and flashpage_raw #11681

Closed
wants to merge 12 commits into from

Conversation

fjmolinas
Copy link
Contributor

@fjmolinas fjmolinas commented Jun 12, 2019

Contribution description

This PR adds flashpage and flashpage_raw for stm32f2/4/7stm32f2 and stm32f4. They both use sectors as the way of dividing flash, instead of the usual page. These sector do not have the same size, and they can vary according to the specific CPU.

This PR implements flashpage and flashpage_raw as a wrapper over sectors. To still keep the page notion, an arbitrary page of length 1kB has been defined. When an erase is requested the sector where this page is located is only erased if the page was in not in a erase state anymore, i.e. '0xFF'.

NOTE1: this "wrapper" concept is only for erasing, when it comes to writing it's pretty much the same than for other STM32.

NOTE2: there is an api change since a flashpage_init() is introduced. Not sure if that is the best option.

NOTE3: I tried to make it work for stm32f7 but I have problems with unexpected latency when performing flash operations, so delaying it out; but the general approach works as well for stm32f7.

Testing procedure

Tested on nucleo-f207zg, nucleo-f446re, nucleo-f767zi & stm32f429i-disc1. On these or other stm32f2 and stm32f4 run:

make clean -C tests/periph_flashpage/ BOARD=nucleo-f207zg flash test
everything should pass.

Issues/PRs references

@fjmolinas fjmolinas added Platform: ARM Platform: This PR/issue effects ARM-based platforms Type: new feature The issue requests / The PR implemements a new feature for RIOT Area: OTA Area: Over-the-air updates labels Jun 12, 2019
@fjmolinas fjmolinas requested a review from aabadie June 12, 2019 14:55
@fjmolinas fjmolinas changed the title stm32f4/2: add flashpage and flashpage_raw cpu/stm32f4/2: add flashpage and flashpage_raw Jun 12, 2019
@aabadie aabadie added Area: cpu Area: CPU/MCU ports and removed Area: OTA Area: Over-the-air updates labels Jun 12, 2019
Copy link
Contributor

@aabadie aabadie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good at first sight. This is a nice work, very useful.

I have a comment regarding flashpage_init, because I think it could be called from the cpu_init of the stm32.

The new code in flashpage.c should be uncrustified.

Copy link
Contributor

@aabadie aabadie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please uncrustify ;)

#if defined(CPU_FAM_STM32F2) || defined(CPU_FAM_STM32F4)
static inline int flashbank_sector(void *addr) {
uint8_t sn = (uint8_t)(((uint32_t)addr - CPU_FLASH_BASE) / FLASHSECTOR_SIZE_MIN);
if(sn > 3 && sn < 8) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like magic number. Can you add a comment and a reference ? Maybe there's a macro available from the CMSIS ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is not Macro available in CMSIS, tell me if the comment is enough or if I should define Macros for this :)

}
#endif

#if !(defined(CPU_FAM_STM32F2) || defined(CPU_FAM_STM32F4))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#if !(defined(CPU_FAM_STM32F2) || defined(CPU_FAM_STM32F4))
#if defined(CPU_FAM_STM32F0) || defined(CPU_FAM_STM32F1) \
defined(CPU_FAM_STM32L0) || defined(CPU_FAM_STM32L1) \
defined(CPU_FAM_STM32L4)

Better be explicit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be done for the other cases not related to this PR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say yes but not in this PR.

@fjmolinas
Copy link
Contributor Author

@aabadie I rebased and added support for STM32F7

@fjmolinas fjmolinas changed the title cpu/stm32f4/2: add flashpage and flashpage_raw cpu/stm32f7/4/2: add flashpage and flashpage_raw Jul 17, 2019
@fjmolinas fjmolinas force-pushed the pr_flashpage_stm32f4 branch from 32ce3fe to caba796 Compare July 24, 2019 08:30
@fjmolinas fjmolinas added the State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet label Oct 24, 2019
@stale
Copy link

stale bot commented Jan 25, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions.

@stale stale bot added the State: stale State: The issue / PR has no activity for >185 days label Jan 25, 2020
@stale stale bot closed this Feb 25, 2020
@fjmolinas fjmolinas deleted the pr_flashpage_stm32f4 branch July 30, 2021 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: cpu Area: CPU/MCU ports Platform: ARM Platform: This PR/issue effects ARM-based platforms State: stale State: The issue / PR has no activity for >185 days State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants