diff options
author | Nick Sanders <nsanders@chromium.org> | 2016-07-26 13:17:09 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-08-17 16:19:07 -0700 |
commit | 6fcd163da5169bfca36ab8c15cfd9d0624acae19 (patch) | |
tree | cc1e3cd999fa3df95547356e8160fd966aa26bc3 /chip/stm32/flash-f.c | |
parent | 6fad4f8588242cd6202e1177e145073c6aff6b7a (diff) | |
download | chrome-ec-6fcd163da5169bfca36ab8c15cfd9d0624acae19.tar.gz |
stm32f446e-eval: add support for stm32f446
This adds basic support for the stm32f446.
This consists of:
* New DMA model for stm32f4
* New clock domain support.
* MCO oscillator gpio export support.
* Flash support for irregular blocks.
BUG=chromium:608039
TEST=boots w/ correct clock, stm32f0 also boots.
BRANCH=None
Change-Id: I1c5cf6ddca09009c9dac60da8a3d0c5ceedfcf4d
Signed-off-by: Nick Sanders <nsanders@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/363992
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Diffstat (limited to 'chip/stm32/flash-f.c')
-rw-r--r-- | chip/stm32/flash-f.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/chip/stm32/flash-f.c b/chip/stm32/flash-f.c index c57f072fc2..09a52ded2e 100644 --- a/chip/stm32/flash-f.c +++ b/chip/stm32/flash-f.c @@ -7,6 +7,7 @@ #include "battery.h" #include "console.h" +#include "clock.h" #include "flash.h" #include "hooks.h" #include "registers.h" @@ -25,8 +26,6 @@ /* Flash page programming timeout. This is 2x the datasheet max. */ #define FLASH_TIMEOUT_US 16000 -#define FLASH_TIMEOUT_LOOP \ - (FLASH_TIMEOUT_US * (CPU_CLOCK / SECOND) / CYCLE_PER_FLASH_LOOP) /* Flash unlocking keys */ #define KEY1 0x45670123 @@ -44,9 +43,15 @@ static int write_optb(int byte, uint8_t value); +static inline int calculate_flash_timeout(void) +{ + return (FLASH_TIMEOUT_US * + (clock_get_freq() / SECOND) / CYCLE_PER_FLASH_LOOP); +} + static int wait_busy(void) { - int timeout = FLASH_TIMEOUT_LOOP; + int timeout = calculate_flash_timeout(); while (STM32_FLASH_SR & (1 << 0) && timeout-- > 0) udelay(CYCLE_PER_FLASH_LOOP); return (timeout > 0) ? EC_SUCCESS : EC_ERROR_TIMEOUT; @@ -207,6 +212,7 @@ int flash_physical_write(int offset, int size, const char *data) { uint16_t *address = (uint16_t *)(CONFIG_PROGRAM_MEMORY_BASE + offset); int res = EC_SUCCESS; + int timeout = calculate_flash_timeout(); int i; if (unlock(PRG_LOCK) != EC_SUCCESS) { @@ -228,7 +234,7 @@ int flash_physical_write(int offset, int size, const char *data) watchdog_reload(); /* wait to be ready */ - for (i = 0; (STM32_FLASH_SR & 1) && (i < FLASH_TIMEOUT_LOOP); + for (i = 0; (STM32_FLASH_SR & 1) && (i < timeout); i++) ; @@ -237,7 +243,7 @@ int flash_physical_write(int offset, int size, const char *data) data += 2; /* Wait for writes to complete */ - for (i = 0; (STM32_FLASH_SR & 1) && (i < FLASH_TIMEOUT_LOOP); + for (i = 0; (STM32_FLASH_SR & 1) && (i < timeout); i++) ; |