From 6d983539bcff2a540dd136a7e84e1db2b334528f Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 16 Apr 2014 23:08:36 +0100 Subject: stmhal: Improve flash storage cache management. Internal flash used for the filesystem is now written (from the cache) only after a 5s delay, or when a file is closed, or when the drive is unmounted from the host. This delay means that multiple writes can accumulate in the cache, and leads to less writes to the flash, making it last longer. It's implemented by a high-priority interrupt that takes care of flash erase and write, and flushing the cache. This is still only an interim solution for the flash filesystem. It eventually needs to be replaced with something that uses less RAM for the cache, something that can use more of the flash, and something that does proper wear levelling. --- stmhal/stm32f4xx_it.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'stmhal/stm32f4xx_it.c') diff --git a/stmhal/stm32f4xx_it.c b/stmhal/stm32f4xx_it.c index aee689d7e2..06428a4c4f 100644 --- a/stmhal/stm32f4xx_it.c +++ b/stmhal/stm32f4xx_it.c @@ -49,6 +49,7 @@ #include "obj.h" #include "exti.h" #include "timer.h" +#include "storage.h" /** @addtogroup STM32F4xx_HAL_Examples * @{ @@ -263,6 +264,19 @@ void OTG_XX_WKUP_IRQHandler(void) { }*/ +// Handle a flash (erase/program) interrupt. +void FLASH_IRQHandler(void) { + // This calls the real flash IRQ handler, if needed + /* + uint32_t flash_cr = FLASH->CR; + if ((flash_cr & FLASH_IT_EOP) || (flash_cr & FLASH_IT_ERR)) { + HAL_FLASH_IRQHandler(); + } + */ + // This call the storage IRQ handler, to check if the flash cache needs flushing + storage_irq_handler(); +} + /** * @brief These functions handle the EXTI interrupt requests. * @param None -- cgit v1.2.3