summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHierophect <hierophect@gmail.com>2019-08-10 18:00:09 -0400
committerHierophect <hierophect@gmail.com>2019-08-10 18:00:09 -0400
commit300dc68955141ede186521e9fb1678d693c02fdf (patch)
treeec2873692199e6d0cd49e0fe23222b53df949893
parent294d6dc8673d3c288033ac226ff1d695b8df1073 (diff)
Further non-functional flash changes
-rw-r--r--ports/stm32f4/boards/STM32F411VETx_FLASH.ld2
-rw-r--r--ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.h4
-rw-r--r--ports/stm32f4/peripherals/stm32f4/stm32f411xe/clocks.c2
-rw-r--r--ports/stm32f4/supervisor/internal_flash.c13
-rw-r--r--ports/stm32f4/supervisor/internal_flash.h4
5 files changed, 19 insertions, 6 deletions
diff --git a/ports/stm32f4/boards/STM32F411VETx_FLASH.ld b/ports/stm32f4/boards/STM32F411VETx_FLASH.ld
index a3c3594a9..763e7bcea 100644
--- a/ports/stm32f4/boards/STM32F411VETx_FLASH.ld
+++ b/ports/stm32f4/boards/STM32F411VETx_FLASH.ld
@@ -62,7 +62,7 @@ _Min_Stack_Size = 0x400; /* required amount of stack */
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
-FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K
+FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K - 256 - 100K
}
/* Define output sections */
diff --git a/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.h b/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.h
index 1bb5849af..81e0f8790 100644
--- a/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.h
+++ b/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.h
@@ -30,8 +30,8 @@
#define MICROPY_HW_BOARD_NAME "STM32F411E_DISCO"
#define MICROPY_HW_MCU_NAME "STM32F411xE"
-// #define FLASH_SIZE (0x7D000)
-// #define FLASH_PAGE_SIZE (0x4000)
+#define FLASH_SIZE (0x80000) //512K
+#define FLASH_PAGE_SIZE (0x4000) //16K
#define CIRCUITPY_AUTORELOAD_DELAY_MS 500
diff --git a/ports/stm32f4/peripherals/stm32f4/stm32f411xe/clocks.c b/ports/stm32f4/peripherals/stm32f4/stm32f411xe/clocks.c
index f1ce6fef9..6d2a6fac9 100644
--- a/ports/stm32f4/peripherals/stm32f4/stm32f411xe/clocks.c
+++ b/ports/stm32f4/peripherals/stm32f4/stm32f411xe/clocks.c
@@ -57,5 +57,5 @@ void stm32f4_peripherals_clocks_init(void) {
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
- HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);
+ HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3);
}
diff --git a/ports/stm32f4/supervisor/internal_flash.c b/ports/stm32f4/supervisor/internal_flash.c
index fab067818..70d9277e0 100644
--- a/ports/stm32f4/supervisor/internal_flash.c
+++ b/ports/stm32f4/supervisor/internal_flash.c
@@ -61,6 +61,7 @@ static const flash_layout_t flash_layout[] = {
#endif
};
+//Return the sector of a given flash address.
uint32_t flash_get_sector_info(uint32_t addr, uint32_t *start_addr, uint32_t *size) {
if (addr >= flash_layout[0].base_address) {
uint32_t sector_index = 0;
@@ -122,6 +123,7 @@ bool supervisor_flash_write_block(const uint8_t *src, uint32_t block) {
int32_t dest = convert_block_to_flash_addr(block);
if (dest == -1) {
// bad block number
+ mp_printf(&mp_plat_print, "BAD FLASH BLOCK ERROR");
return false;
}
@@ -142,14 +144,25 @@ bool supervisor_flash_write_block(const uint8_t *src, uint32_t block) {
if (HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError) != HAL_OK) {
// error occurred during sector erase
HAL_FLASH_Lock(); // lock the flash
+ mp_printf(&mp_plat_print, "FLASH SECTOR ERASE ERROR");
return false;
}
+ __HAL_FLASH_DATA_CACHE_DISABLE();
+ __HAL_FLASH_INSTRUCTION_CACHE_DISABLE();
+
+ __HAL_FLASH_DATA_CACHE_RESET();
+ __HAL_FLASH_INSTRUCTION_CACHE_RESET();
+
+ __HAL_FLASH_INSTRUCTION_CACHE_ENABLE();
+ __HAL_FLASH_DATA_CACHE_ENABLE();
+
// program the flash word by word
for (int i = 0; i < (FILESYSTEM_BLOCK_SIZE / 4); i++) {
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, dest, *src) != HAL_OK) {
// error occurred during flash write
HAL_FLASH_Lock(); // lock the flash
+ mp_printf(&mp_plat_print, "FLASH WRITE ERROR");
return false;
}
dest += 4;
diff --git a/ports/stm32f4/supervisor/internal_flash.h b/ports/stm32f4/supervisor/internal_flash.h
index 4d720913f..434281ed5 100644
--- a/ports/stm32f4/supervisor/internal_flash.h
+++ b/ports/stm32f4/supervisor/internal_flash.h
@@ -46,7 +46,7 @@
#define INTERNAL_FLASH_FILESYSTEM_START_ADDR ((STM32_FLASH_SIZE + STM32_FLASH_OFFSET) - INTERNAL_FLASH_FILESYSTEM_SIZE - CIRCUITPY_INTERNAL_NVM_SIZE)
#define INTERNAL_FLASH_FILESYSTEM_NUM_BLOCKS (INTERNAL_FLASH_FILESYSTEM_SIZE / FILESYSTEM_BLOCK_SIZE)
-// #define INTERNAL_FLASH_SYSTICK_MASK (0x1ff) // 512ms
-// #define INTERNAL_FLASH_IDLE_TICK(tick) (((tick) & INTERNAL_FLASH_SYSTICK_MASK) == 2)
+#define INTERNAL_FLASH_SYSTICK_MASK (0x1ff) // 512ms
+#define INTERNAL_FLASH_IDLE_TICK(tick) (((tick) & INTERNAL_FLASH_SYSTICK_MASK) == 2)
#endif // MICROPY_INCLUDED_STM32F4_INTERNAL_FLASH_H