forked from apache/mynewt-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hw/mcu/stm32h7: Use linear sector flash driver
STM32H7 actually has liner flash with sectors of 128kB. There is no need for stm32_flash_sectors table in BSP. Additionally non-linear version that was used so far would not compile for some H7 chips that have different FLASH CR register and where FLASH_VOLATEG_RANGE_3 is not defined. Liner sector variant was chosen when FLASH_PAGE_SIZE was defined. While H7 and H5 don't have this definition they do have FLASH_SECTOR_SIZE and when this definition is present FLASH_IS_LINEAR is also set to 1 For U5 where minimal write size is 16 bytes function stm32_flash_write_linear() was using to small buffer possibly clobbering some stack values. Now val variable is an array to accommodate 16 and 32 accesses needed for U5 and H7 Signed-off-by: Jerzy Kasenberg <jerzy.kasenberg@codecoup.pl>
- Loading branch information
Showing
3 changed files
with
68 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
#include <syscfg/syscfg.h> | ||
#include <mcu/stm32_hal.h> | ||
#include "hal/hal_flash_int.h" | ||
|
||
#define STM32_FLASH_SIZE (MYNEWT_VAL(STM32_FLASH_SIZE_KB) * 1024) | ||
|
||
int | ||
stm32_mcu_flash_erase_sector(const struct hal_flash *dev, uint32_t sector_address) | ||
{ | ||
FLASH_EraseInitTypeDef eraseinit; | ||
uint32_t PageError; | ||
HAL_StatusTypeDef rc; | ||
|
||
(void)PageError; | ||
|
||
if (!(sector_address & (FLASH_SECTOR_SIZE - 1))) { | ||
eraseinit.TypeErase = FLASH_TYPEERASE_SECTORS; | ||
#ifdef FLASH_BANK_2 | ||
if ((sector_address - dev->hf_base_addr) < (STM32_FLASH_SIZE / 2)) { | ||
eraseinit.Banks = FLASH_BANK_1; | ||
} else { | ||
eraseinit.Banks = FLASH_BANK_2; | ||
} | ||
#else | ||
eraseinit.Banks = FLASH_BANK_1; | ||
#endif | ||
eraseinit.Sector = (sector_address - dev->hf_base_addr) / FLASH_SECTOR_SIZE; | ||
eraseinit.NbSectors = 1; | ||
#if defined(FLASH_CR_PSIZE) | ||
eraseinit.VoltageRange = FLASH_VOLTAGE_RANGE_3; | ||
#endif | ||
rc = HAL_FLASHEx_Erase(&eraseinit, &PageError); | ||
if (rc == HAL_OK) { | ||
return 0; | ||
} | ||
} | ||
|
||
return -1; | ||
} |