Skip to content

Conversation

maribu
Copy link
Member

@maribu maribu commented Jan 30, 2019

Contribution description

This change of the openocd.cfg overwrites the flash size to 128 KiB and, thus, allows flashing using make flash. Please note that STM32F103C8_FLASH_HACK has to be set to 1 in order for the link time checks to also assume 128 KiB flash.

Be aware that - as of January 2019 - the latest stable release of OpenOCD does not allow overwriting the flash size, so you will currently need the development version for this to work.

Testing procedure

Using the development version of OpenOCD:

Run STM32F103C8_FLASH_HACK=1 make flash e.g. in examples/gnrc_networking. (Because no network device is present an assertion will be triggered on boot, but flashing would not be possible with 64 KiB flash.)

Using the current stable version of OpenOCD:

Run make flash in e.g. examples/default. This should still work.

Issues/PRs references

Follow up of #10323

This change of the openocd.cfg overwrites the flash size to 128 KiB and, thus,
allows flashing using `make flash`. Please note that STM32F103C8_FLASH_HACK has
to be set to 1 in order for the link time checks to also assume 128 KiB flash.
Be aware that - as of January 2019 - the latest stable release of OpenOCD does
not allow overwriting the flash size, so you will currently need the development
version for this to work.
@maribu maribu added the Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation label Jan 30, 2019
@maribu maribu requested a review from kaspar030 January 30, 2019 08:50
@maribu
Copy link
Member Author

maribu commented Jan 30, 2019

@kaspar030: If I remember correctly, you have some interest in using the full flash of the Bluepill. Would you mind to review?

@maribu maribu requested a review from jia200x February 23, 2019 18:59
@maribu
Copy link
Member Author

maribu commented Mar 3, 2019

Ping :-)

@maribu maribu requested a review from MrKevinWeiss March 25, 2019 16:21
@maribu
Copy link
Member Author

maribu commented Apr 9, 2019

Ping?

@MrKevinWeiss
Copy link
Contributor

I tested with

STM32F103C8_FLASH_HACK=1 PATH=~/opt/gnu-mcu-eclipse/openocd/0.10.0-11-20190118-1134-64/bin/:$PATH BOARD=bluepill make flash -C examples/gnrc_networking

GNU MCU Eclipse 64-bit Open On-Chip Debugger 0.10.0+dev-00462-gdd1d90111 (2019-01-18-11:37)

verified 65636 bytes in 0.985497s (65.041 KiB/s)

when it should fail since I have a 64 kB chip

(on master it shows Error: checksum mismatch - attempting binary compare)

With this PR it always says the flash size is 128kB not 64kB like on master.

@MrKevinWeiss
Copy link
Contributor

Note: it fails correctly on this PR with the Open On-Chip Debugger 0.10.0+dev-00399-g09076d1 (2018-04-12-17:12) version of openocd

@maribu
Copy link
Member Author

maribu commented Apr 9, 2019

With this PR it always says the flash size is 128kB not 64kB like on master.

This is basically what the change does. If STM32F103C8_FLASH_HACK is set to 1, the flash size reported by the MCU is ignored by OpenOCD and it will just write up to 128KiB. This is something that might or might not work. It seems to me that the ST does not produce any STM32F103C8 (64KiB flash), but only STM32F103B8 (128KiB flash). The devices shipped as STM32F103C8 seem to have just some fuse blown.

I think the reasons for that are:

  1. Only one production line is needed to manufacture two different MCUs
  2. This allows ST to product binning. E.g. all MCUs with a broken flash can still be sold as STM32F103C8, provided that the first 64KiB flash is fully functional

@benpicco
Copy link
Contributor

I think you still need to edit cpu/stm32_common/stm32_mem_lengths.mk, only editing openocd.cfg gives me

/usr/lib/gcc/arm-none-eabi/7.3.1/../../../arm-none-eabi/bin/ld: /home/benpicco/dev/RIOT/examples/gnrc_networking/bin/blackpill/gnrc_networking.elf section `.text' will not fit in region `rom'
/usr/lib/gcc/arm-none-eabi/7.3.1/../../../arm-none-eabi/bin/ld: region `rom' overflowed by 25840 bytes
collect2: error: ld returned 1 exit status

(.text is about 90 kiB)

@maribu
Copy link
Member Author

maribu commented Aug 22, 2019

@benpicco: Please check again after running export STM32F103C8_FLASH_HACK=1 ;-)

@benpicco
Copy link
Contributor

benpicco commented Aug 22, 2019

Oh sorry, I should read the contribution description till the end instead of just looking at the commits 😅

Could this also be achieved by

--- a/boards/common/stm32f103c8/Makefile.include
+++ b/boards/common/stm32f103c8/Makefile.include
@@ -3,6 +3,7 @@ export CPU = stm32f1
 STM32F103C8_FLASH_HACK ?= 0
 ifneq ($(STM32F103C8_FLASH_HACK),0)
   export CPU_MODEL = stm32f103cb
+  export OPENOCD_EXTRA_INIT += -c 'set FLASH_SIZE 0x20000'
 else
   export CPU_MODEL = stm32f103c8
 endif

so we avoid confusing OpenOCD if the hack is not to be applied? Sorry I can't test it right now, I only just realized that I need an external programmer for the blackpill and I don't have that with me right now.

@maribu
Copy link
Member Author

maribu commented Aug 23, 2019

@benpicco: That would be super nice, but it didn't work for me. I added now a modified OpenOCD config as openocfg-flash-hack.cfg and this is used instead of the default file if STM32F103C8_FLASH_HACK is used. This would be just as good to me, if this config could just source the standard OpenOCD config and add / overwrite based on that. However, I could not get source [find <FILE>] to work for files outside of OpenOCD's standard folder, so it contains a verbatim copy now :-/

@benpicco
Copy link
Contributor

I think this is better. Since the config should be Tcl, we should be able to use the source command without [find].

But I'd also find that bit of duplication acceptable. @MrKevinWeiss what do you think?

@maribu
Copy link
Member Author

maribu commented Aug 30, 2019

With the latest emails from @cladmi in the devel list in mind, I guess this PR could be integrated into th split of the bluepill board and the bluebill-128kib board. (And likewise for the blackpill.)

@maribu maribu deleted the stm32f103c8_flash branch September 29, 2019 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants