diff options
author | lokher <lokher@gmail.com> | 2022-08-03 16:53:42 +0800 |
---|---|---|
committer | lokher <lokher@gmail.com> | 2022-08-05 14:45:45 +0800 |
commit | 968655c74cc13a1a63320ef795fe436449708429 (patch) | |
tree | b37716e10d16dcf760ba608dc66051cdb47eb31b /platforms/chibios/flash_stm32.c | |
parent | 068bfc49de127c1f1305ee7680f51425ca9cd1f1 (diff) |
Add K8 pro
Diffstat (limited to 'platforms/chibios/flash_stm32.c')
-rw-r--r-- | platforms/chibios/flash_stm32.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/platforms/chibios/flash_stm32.c b/platforms/chibios/flash_stm32.c index 72c41b8b78..59c77e0bc5 100644 --- a/platforms/chibios/flash_stm32.c +++ b/platforms/chibios/flash_stm32.c @@ -51,6 +51,15 @@ static uint8_t ADDR2PAGE(uint32_t Page_Address) { } #endif +#if defined(STM32L4XX) +# define FLASH_SR_PGERR (FLASH_SR_PROGERR | FLASH_SR_PGAERR | FLASH_SR_SIZERR | FLASH_SR_PGSERR) +# define FLASH_OBR_OPTERR FLASH_SR_OPERR +# define FLASH_KEY1 0x45670123U +# define FLASH_KEY2 0xCDEF89ABU + +static uint32_t ADDR2PAGE(uint32_t Page_Address) { return (Page_Address - FLASH_BASE) / 0x800; } +#endif + /* Delay definition */ #define EraseTimeout ((uint32_t)0x00000FFF) #define ProgramTimeout ((uint32_t)0x0000001F) @@ -128,6 +137,9 @@ FLASH_Status FLASH_ErasePage(uint32_t Page_Address) { #if defined(FLASH_CR_SNB) FLASH->CR &= ~FLASH_CR_SNB; FLASH->CR |= FLASH_CR_SER | (ADDR2PAGE(Page_Address) << FLASH_CR_SNB_Pos); +#elif defined(FLASH_CR_PNB) + FLASH->CR &= ~FLASH_CR_PNB; + FLASH->CR |= FLASH_CR_PER | (ADDR2PAGE(Page_Address) << FLASH_CR_PNB_Pos); #else FLASH->CR |= FLASH_CR_PER; FLASH->AR = Page_Address; @@ -140,6 +152,8 @@ FLASH_Status FLASH_ErasePage(uint32_t Page_Address) { /* if the erase operation is completed, disable the configured Bits */ #if defined(FLASH_CR_SNB) FLASH->CR &= ~(FLASH_CR_SER | FLASH_CR_SNB); +#elif defined(FLASH_CR_PNB) + FLASH->CR &= ~(FLASH_CR_PER | FLASH_CR_PNB); #else FLASH->CR &= ~FLASH_CR_PER; #endif @@ -150,6 +164,46 @@ FLASH_Status FLASH_ErasePage(uint32_t Page_Address) { return status; } +#if defined(STM32L4XX) +/** + * @brief Programs double words at a specified address. + * @param Address: specifies the address to be programmed. + * @param Data: specifies the data to be programmed. + * @retval FLASH Status: The returned value can be: FLASH_ERROR_PG, + * FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. + */ +FLASH_Status FLASH_ProgramDoubleWord(uint32_t Address, uint64_t Data) { + FLASH_Status status = FLASH_BAD_ADDRESS; + + if (IS_FLASH_ADDRESS(Address)) { + /* Wait for last operation to be completed */ + status = FLASH_WaitForLastOperation(ProgramTimeout); + if (status == FLASH_COMPLETE) { + /* if the previous operation is completed, proceed to program the new data */ + /* disable data cache first */ + FLASH->ACR &= ~FLASH_ACR_DCEN; + FLASH->CR |= FLASH_CR_PG; + *(__IO uint32_t*)Address = (uint32_t)Data; + __ISB(); + *(__IO uint32_t*)(Address + 4U) = (uint32_t)(Data >> 32); + /* Wait for last operation to be completed */ + status = FLASH_WaitForLastOperation(ProgramTimeout); + if (status != FLASH_TIMEOUT) { + /* if the program operation is completed, disable the PG Bit */ + FLASH->CR &= ~FLASH_CR_PG; + } + FLASH->SR = (FLASH_SR_EOP | FLASH_SR_PGERR | FLASH_SR_WRPERR); + /* reset data cache */ + FLASH->ACR |= FLASH_ACR_DCRST; + FLASH->ACR &= ~FLASH_ACR_DCRST; + /* enable data cache */ + FLASH->ACR |= FLASH_ACR_DCEN; + } + } + return status; +} + +#else /** * @brief Programs a half word at a specified address. * @param Address: specifies the address to be programmed. @@ -183,6 +237,7 @@ FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data) { } return status; } +#endif /** * @brief Unlocks the FLASH Program Erase Controller. |