Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions cpu/stm32_common/periph/flashpage.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#define CNTRL_REG (FLASH->PECR)
#define CNTRL_REG_LOCK (FLASH_PECR_PELOCK)
#define FLASH_CR_PER (FLASH_PECR_ERASE | FLASH_PECR_PROG)
#define FLASH_CR_PG (FLASH_PECR_FPRG | FLASH_PECR_PROG)
#define FLASHPAGE_DIV (4U) /* write 4 bytes in one go */
#else
#if defined(CPU_FAM_STM32L4)
Expand Down Expand Up @@ -77,7 +76,8 @@ static void _erase_page(void *page_addr)
uint32_t *dst = page_addr;
#else
uint16_t *dst = page_addr;

#endif
#if defined(CPU_FAM_STM32F0) || defined(CPU_FAM_STM32F1)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This change should be in it's own commit and not in b72a6ed where it's unrelated.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Why? Only STM32F0 STM32F1 need to initialize HSI clock (at least for the implemented boards). My goal was to separate it from the default case which only said /* Default is to support half-word sizes */, But I guess you are right, the commit message is not explicit enough. Would you be Ok with just re-wording?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No, this changes the initial behaviour as you say, so it needs to be in its own commit.

uint32_t hsi_state = (RCC->CR & RCC_CR_HSION);
/* the internal RC oscillator (HSI) must be enabled */
stmclk_enable_hsi();
Expand All @@ -98,7 +98,6 @@ static void _erase_page(void *page_addr)
*dst = (uint32_t)0;
#elif defined(CPU_FAM_STM32L4)
DEBUG("[flashpage] erase: setting the page address\n");
CNTRL_REG |= FLASH_CR_PER;
uint8_t pn;
#if FLASHPAGE_NUMOF <= 256
pn = (uint8_t)flashpage_page(dst);
Expand Down Expand Up @@ -131,8 +130,7 @@ static void _erase_page(void *page_addr)
/* lock the flash module again */
_lock();

#if !(defined(CPU_FAM_STM32L0) || defined(CPU_FAM_STM32L1) || \
defined(CPU_FAM_STM32L4))
#if defined(CPU_FAM_STM32F0) || defined(CPU_FAM_STM32F1)
/* restore the HSI state */
if (!hsi_state) {
stmclk_disable_hsi();
Expand Down Expand Up @@ -163,7 +161,9 @@ void flashpage_write_raw(void *target_addr, const void *data, size_t len)
#else
uint16_t *dst = (uint16_t *)target_addr;
const uint16_t *data_addr = data;
#endif

#if defined(CPU_FAM_STM32F0) || defined(CPU_FAM_STM32F1)
uint32_t hsi_state = (RCC->CR & RCC_CR_HSION);
/* the internal RC oscillator (HSI) must be enabled */
stmclk_enable_hsi();
Expand All @@ -173,7 +173,8 @@ void flashpage_write_raw(void *target_addr, const void *data, size_t len)
_unlock_flash();

DEBUG("[flashpage_raw] write: now writing the data\n");
#if !(defined(CPU_FAM_STM32L0) || defined(CPU_FAM_STM32L1))
#if defined(CPU_FAM_STM32F0) || defined(CPU_FAM_STM32F1) || \
defined(CPU_FAM_STM32L4)
/* set PG bit and program page to flash */
CNTRL_REG |= FLASH_CR_PG;
#endif
Expand All @@ -185,14 +186,16 @@ void flashpage_write_raw(void *target_addr, const void *data, size_t len)
}

/* clear program bit again */
#if defined(CPU_FAM_STM32F0) || defined(CPU_FAM_STM32F1) || \
defined(CPU_FAM_STM32L4)
CNTRL_REG &= ~(FLASH_CR_PG);
#endif

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The DEBUG message above is now only displayed with F0/F1/L4 but not for L0/L1. It should be put after.
I would also not put this change in 5e0c867 because it seems unrelated.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You are right about the DEBUG message. But it is related since I'm removing the definition of FLASH_CR_PG Therefore I need to excluded it from compilation and that is the reason for the #ifdefined. Should I split guarding and removing FLASH_CR_PG into two commits?

@aabadie aabadie Jun 20, 2019

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see, let's keep the changes in the same commit then. You still have to fix the commit message: it's full of typos :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The DEBUG line must still move out of the define (preferably after).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

damn, I was concentrating on the typos sorry

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok I think now it should be ok .. sorry for missing this.

DEBUG("[flashpage_raw] write: done writing data\n");

/* lock the flash module again */
_lock();

#if !(defined(CPU_FAM_STM32L0) || defined(CPU_FAM_STM32L1) || \
defined(CPU_FAM_STM32L4))
#if defined(CPU_FAM_STM32F0) || defined(CPU_FAM_STM32F1)
/* restore the HSI state */
if (!hsi_state) {
stmclk_disable_hsi();
Expand Down