From 947acd6c1a1eef21c97f147b58224fd85e8dc880 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 22 Mar 2017 15:53:12 -0600 Subject: [PATCH] Small changes from review of last PR --- arch/arm/src/stm32/Kconfig | 10 +++--- arch/arm/src/stm32/chip/stm32_flash.h | 1 - arch/arm/src/stm32/stm32_flash.c | 43 ++++++++++---------------- configs/clicker2-stm32/src/stm32_spi.c | 2 +- 4 files changed, 24 insertions(+), 32 deletions(-) diff --git a/arch/arm/src/stm32/Kconfig b/arch/arm/src/stm32/Kconfig index 72f8a17fbb..9e3ce56127 100644 --- a/arch/arm/src/stm32/Kconfig +++ b/arch/arm/src/stm32/Kconfig @@ -2634,10 +2634,12 @@ config STM32_FLASH_PREFETCH properly and enabling this option may interfere with ADC accuracy. config STM32_FLASH_WORKAROUND_DATA_CACHE_CORRUPTION_ON_RWW - bool "Enable the workaround to fix flash data cache corruption when reading from one flash bank while writing on other flash bank" - default n - ---help--- - See your STM32 errata to check if your STM32 is affected by this problem. + bool "Workaround for FLASH data cache corruption" + default n + ---help--- + Enable the workaround to fix flash data cache corruption when reading + from one flash bank while writing on other flash bank. See your STM32 + errata to check if your STM32 is affected by this problem. choice prompt "JTAG Configuration" diff --git a/arch/arm/src/stm32/chip/stm32_flash.h b/arch/arm/src/stm32/chip/stm32_flash.h index 16c67a933e..32eeaf90dd 100644 --- a/arch/arm/src/stm32/chip/stm32_flash.h +++ b/arch/arm/src/stm32/chip/stm32_flash.h @@ -392,7 +392,6 @@ * Public Functions ************************************************************************************/ -void stm32_flash_initialize(void); void stm32_flash_lock(void); void stm32_flash_unlock(void); diff --git a/arch/arm/src/stm32/stm32_flash.c b/arch/arm/src/stm32/stm32_flash.c index 4907aa9f0a..8ba48a8262 100644 --- a/arch/arm/src/stm32/stm32_flash.c +++ b/arch/arm/src/stm32/stm32_flash.c @@ -48,8 +48,10 @@ #include #include -#include #include +#include +#include +#include #include "stm32_flash.h" #include "stm32_rcc.h" @@ -82,31 +84,27 @@ #define FLASH_SR_WRITE_PROTECTION_ERROR FLASH_SR_WRPERR #endif +/************************************************************************************ + * Private Data + ************************************************************************************/ + +static sem_t g_sem = SEM_INITIALIZER(1); + /************************************************************************************ * Private Functions ************************************************************************************/ -static sem_t g_sem; -/* - * After all SMT32 boards starts calling stm32_flash_initialize() this can - * be removed. - */ -static bool g_initialized = false; - static void sem_lock(void) { - if (g_initialized) + while (sem_wait(&g_sem) < 0) { - sem_wait(&g_sem); + DEBUGASSERT(errno == EINTR); } } -static void sem_unlock(void) +static inline void sem_unlock(void) { - if (g_initialized) - { - sem_post(&g_sem); - } + sem_post(&g_sem); } static void flash_unlock(void) @@ -137,24 +135,18 @@ static void data_cache_disable(void) static void data_cache_enable(void) { - /* reset data cache */ + /* Reset data cache */ + modifyreg32(STM32_FLASH_ACR, 0, FLASH_ACR_DCRST); - /* enable data cache */ + /* Enable data cache */ + modifyreg32(STM32_FLASH_ACR, 0, FLASH_ACR_DCEN); } /************************************************************************************ * Public Functions ************************************************************************************/ -void stm32_flash_initialize(void) -{ - g_initialized = true; - /* - * Initialize the semaphore that manages exclusive access flash registers - */ - sem_init(&g_sem, 0, 1); -} void stm32_flash_unlock(void) { @@ -171,7 +163,6 @@ void stm32_flash_lock(void) } #if defined(CONFIG_STM32_STM32F10XX) || defined(CONFIG_STM32_STM32F30XX) - size_t up_progmem_pagesize(size_t page) { return STM32_FLASH_PAGESIZE; diff --git a/configs/clicker2-stm32/src/stm32_spi.c b/configs/clicker2-stm32/src/stm32_spi.c index 7e231d108b..87e6e8d1d1 100644 --- a/configs/clicker2-stm32/src/stm32_spi.c +++ b/configs/clicker2-stm32/src/stm32_spi.c @@ -63,7 +63,7 @@ * Name: stm32_spidev_initialize * * Description: - * Called to configure SPI chip select GPIO pins for the stm32f4discovery board. + * Called to configure SPI chip select GPIO pins for the Mikroe Clicker2 STM32 board. * ************************************************************************************/