summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Schodet2017-02-28 10:34:09 +0100
committerNicolas Schodet2019-10-09 23:05:51 +0200
commit969284df3091116caedc39f66fe7833a19d8fbee (patch)
tree9b90d274f9851ce86b3f1ee75abe5d06510cba55
parentea5c86569380f4d09d8bc68c5131620c332d904c (diff)
ucoo/hal/self_programming: program flash 8 by 8 bits on STM32F4HEADmaster
This is a temporary fix for low voltage boards. This should be updated to use the fastest parallelism possible according to actual supply voltage.
-rw-r--r--ucoo/arch/reg.stm32f4.hh1
-rw-r--r--ucoo/hal/self_programming/self_programming.stm32f4.cc12
2 files changed, 7 insertions, 6 deletions
diff --git a/ucoo/arch/reg.stm32f4.hh b/ucoo/arch/reg.stm32f4.hh
index 6cedaba..cd5d8fb 100644
--- a/ucoo/arch/reg.stm32f4.hh
+++ b/ucoo/arch/reg.stm32f4.hh
@@ -70,6 +70,7 @@
#define USB_OTG_DIEPTSIZ_PKTCNT_Pos 19
#define FLASH_CR_PSIZE_x32 FLASH_CR_PSIZE_1
+#define FLASH_CR_PSIZE_x8 0
#define FMC_SDCR_RPIPE_None 0
#define FMC_SDCR_RPIPE_1Clk FMC_SDCR1_RPIPE_0
diff --git a/ucoo/hal/self_programming/self_programming.stm32f4.cc b/ucoo/hal/self_programming/self_programming.stm32f4.cc
index 4d8418f..b8ff05b 100644
--- a/ucoo/hal/self_programming/self_programming.stm32f4.cc
+++ b/ucoo/hal/self_programming/self_programming.stm32f4.cc
@@ -72,13 +72,13 @@ self_programming_erase (uint32_t addr, int count)
reg::FLASH->KEYR = FLASH_KEYR_KEY2;
while (reg::FLASH->SR & FLASH_SR_BSY)
;
- reg::FLASH->CR = FLASH_CR_PSIZE_x32;
+ reg::FLASH->CR = FLASH_CR_PSIZE_x8;
for (sector = 0; count && sector < lengthof (sector_addr); sector++)
{
if (addr == sector_addr[sector])
{
int snb = sector >= 12 ? sector + 16 - 12 : sector;
- reg::FLASH->CR = FLASH_CR_PSIZE_x32 | (snb * FLASH_CR_SNB_0)
+ reg::FLASH->CR = FLASH_CR_PSIZE_x8 | (snb * FLASH_CR_SNB_0)
| FLASH_CR_SER;
reg::FLASH->CR |= FLASH_CR_STRT;
while (reg::FLASH->SR & FLASH_SR_BSY)
@@ -105,11 +105,11 @@ self_programming_write (uint32_t addr, const char *buf, int count)
reg::FLASH->KEYR = FLASH_KEYR_KEY2;
while (reg::FLASH->SR & FLASH_SR_BSY)
;
- reg::FLASH->CR = FLASH_CR_PSIZE_x32 | FLASH_CR_PG;
- for (int i = 0; i < count; i += 4)
+ reg::FLASH->CR = FLASH_CR_PSIZE_x8 | FLASH_CR_PG;
+ for (int i = 0; i < count; i ++)
{
- *reinterpret_cast<volatile uint32_t *> (addr + i) =
- *reinterpret_cast<const uint32_t *> (buf + i);
+ *reinterpret_cast<volatile uint8_t *> (addr + i) =
+ *reinterpret_cast<const uint8_t *> (buf + i);
while (reg::FLASH->SR & FLASH_SR_BSY)
;
}