[Gnuk-users] Proposed patch to fix regnual on "blue pill" board

Jeremy Drake jeremydrake+gnuk at eacceleration.com
Wed Aug 2 23:11:34 UTC 2017


As mentioned in my previous mail, "Gnuk (on "Blue Pill") issues", I ran 
into an issue with regnual while testing on my blue pill board.  I tracked 
it down to the fact that both regnual as well as chopstx use the 
FLASH_SIZE_REG to determine the size of flash.  The reason that the blue 
pill boards work for Gnuk is that, despite the chip used (STM32F103C8T6) 
officially having only 64KiB of flash, they actually seem to have 128KiB 
of flash.  Unfortunately, the FLASH_SIZE_REG value seems to indicate (at 
least on mine) that it only has 64KiB, causing regnual to error out.

What I did to get this working is add an if defined 
(STM32F103_OVERRIDE_FLASH_SIZE_KB) check to the code that tries to see how 
much flash there is.  If this is defined, it is used as the number of KiB 
of flash the device has, otherwise the FLASH_SIZE_REG is believed.  I am 
on the fence if this should be a configure option (since those seem to 
mostly control Gnuk itself), or be left as something that has to be 
manually defined.


Unfortunately, this required changes in both chopstx and regnual.

I don't know how git will appreciate having patches for two different 
repos in the same email, but here goes.  The first patch will be against 
chopstx, the second against gnuk (which just touches regnual).

-- >8 --
Subject: [PATCH] Allow compile-time override of detected flash size.

On the STM32F103C8, as used in the "blue pill" boards, it has been
determined that, despite these only officially having 64KiB flash, it is
possible to actually use 128KiB of flash.

This commit allows for a preprocessor define
STM32F103_OVERRIDE_FLASH_SIZE which, when set, is used as the size of
flash in KiB instead of reading it from the FLASH_SIZE_REG.
---
 mcu/sys-stm32f103.c |    8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/mcu/sys-stm32f103.c b/mcu/sys-stm32f103.c
index 05e1f2f..81d8ec1 100644
--- a/mcu/sys-stm32f103.c
+++ b/mcu/sys-stm32f103.c
@@ -213,7 +213,11 @@ static int
 flash_write (uint32_t dst_addr, const uint8_t *src, size_t len)
 {
   int status;
+#if defined(STM32F103_OVERRIDE_FLASH_SIZE_KB)
+  uint32_t flash_end = FLASH_START_ADDR + STM32F103_OVERRIDE_FLASH_SIZE_KB*1024;
+#else
   uint32_t flash_end = FLASH_START_ADDR + (*FLASH_SIZE_REG)*1024;
+#endif

   if (dst_addr < FLASH_START || dst_addr + len > flash_end)
     return 0;
@@ -269,7 +273,11 @@ static void __attribute__((naked))
 flash_erase_all_and_exec (void (*entry)(void))
 {
   uint32_t addr = FLASH_START;
+#if defined(STM32F103_OVERRIDE_FLASH_SIZE_KB)
+  uint32_t end = FLASH_START_ADDR + STM32F103_OVERRIDE_FLASH_SIZE_KB*1024;
+#else
   uint32_t end = FLASH_START_ADDR + (*FLASH_SIZE_REG)*1024;
+#endif
   uint32_t page_size = 1024;
   int r;

-- 
1.7.10.4

-- >8 --
Subject: [PATCH] Allow compile-time override of detected flash size.

On the STM32F103C8, as used in the "blue pill" boards, it has been
determined that, despite these only officially having 64KiB flash, it is
possible to actually use 128KiB of flash.

This commit allows for a preprocessor define
STM32F103_OVERRIDE_FLASH_SIZE which, when set, is used as the size of
flash in KiB instead of reading it from the FLASH_SIZE_REG.
---
 regnual/regnual.c |    4 ++++
 1 file changed, 4 insertions(+)

--- a/regnual/regnual.c
+++ b/regnual/regnual.c
@@ -365,7 +365,11 @@ main (int argc, char *argv[])

   set_led (0);

+#if defined(STM32F103_OVERRIDE_FLASH_SIZE_KB)
+  flash_end = FLASH_START_ADDR + STM32F103_OVERRIDE_FLASH_SIZE_KB*1024;
+#else
   flash_end = FLASH_START_ADDR + (*FLASH_SIZE_REG)*1024;
+#endif

   /*
    * NVIC interrupt priority was set by Gnuk.
-- 
1.7.10.4




More information about the gnuk-users mailing list