Skip to content

Conversation

maribu
Copy link
Member

@maribu maribu commented Nov 5, 2018

The STM32F103C8 secretly comes with 128KiB flash instead of 64KiB. Still, only
64KiB of it are tested and guaranteed to work. However, most of the times the
whole 128KiB flash works just fine. In the BluePill documentation this fact is
already documented and by using

$ make BOARD=bluepill CPU_MODEL=stm32f103cb

the whole 128 KiB can be used by RIOT. When using this hack routinely, it easier
to use environment variables instead. But allowing to overwrite CPU_MODEL via
environment variables seems to be a bad thing, as it is easy to forget to clear
that environment variable when changing the BOARD variable.

This commit introduces the new STM32F103C8_ROM_HACK variable, which unlocks the
128KiB ROM when set to "y". The BluePill documentation has been updated
accordingly.

@kaspar030
Copy link
Contributor

+1

Personally I find "ROM" misleading. We're usually using it to refer to memory that really can only be read, like on TI chips which have driverlib in ROM. Would you mind calling it "FLASH hack"?

@maribu maribu force-pushed the stm32f103c8_rom_hack branch from 0bd1205 to 88836ba Compare November 5, 2018 11:56
@maribu
Copy link
Member Author

maribu commented Nov 5, 2018

Good point. I renamed it as suggested and squashed the commits.

@kaspar030 kaspar030 added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Area: boards Area: Board ports Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines labels Nov 5, 2018
Copy link
Contributor

@kaspar030 kaspar030 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Untested ACK.

@kaspar030
Copy link
Contributor

If you feel like, change use of "n/y" to "0/1".

The STM32F103C8 secretly comes with 128KiB flash instead of 64KiB. Still, only
64KiB of it are tested and guaranteed to work. However, most of the times the
whole 128KiB flash works just fine. In the BluePill documentation this fact is
already documented and by using

    $ make BOARD=bluepill CPU_MODEL=stm32f103cb

the whole 128 KiB can be used by RIOT. When using this hack routinely, it easier
to use environment variables instead. But allowing to overwrite CPU_MODEL via
environment variables seems to be a bad thing, as it is easy to forget to clear
that environment variable when changing the BOARD variable.

This commit introduces the new STM32F103C8_FLASH_HACK variable, which unlocks
the 128KiB FLASH when set to "1". The BluePill documentation has been updated
accordingly.
@maribu maribu force-pushed the stm32f103c8_rom_hack branch from 88836ba to 82ea9a0 Compare November 5, 2018 13:19
@maribu
Copy link
Member Author

maribu commented Nov 5, 2018

If you feel like, change use of "n/y" to "0/1".

Done and rebased :-)

@maribu
Copy link
Member Author

maribu commented Nov 6, 2018

@kaspar030: Do you mind to let murdock run?

@kYc0o kYc0o added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Nov 6, 2018
@kaspar030 kaspar030 added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Nov 6, 2018
@MrKevinWeiss
Copy link
Contributor

The STM32F103C8 secretly comes with 128KiB flash instead of 64KiB

I guess you mean the the STM32F103CB not STM32F103C8 has the additional memory.

I only have the STM32F103C8 but can confirm different behavior when enabling the STM32F103C8_ROM_HACK.
STM32F103C8_ROM_HACK=0 or default -> region rom overflowed by 12196 bytes
STM32F103C8_ROM_HACK=1 ->

diff 0 address 0x08010000. Was 0xff instead of 0x13
diff 1 address 0x08010001. Was 0xff instead of 0x48
diff 2 address 0x08010002. Was 0xff instead of 0x01
diff 3 address 0x08010003. Was 0xff instead of 0xf0
...

I don't know if this qualifies as tested but I too give it my ACK.

@kaspar030
Copy link
Contributor

Tested OK using STM32F103C8_FLASH_HACK=1 BOARD=bluepill make -C tests/unittests tests-gnrc_ipv6 tests-gnrc_ipv6_hdr tests-qDSA tests-spiffs tests-sixlowpan_ctx tests-sixlowpan tests-ubjson tests-uuid flash -j8. This is a random collection of unittests that happen to cross the 64k flash boundary. Without this PR (or the FLASH hack) linking fails, with hack enabled it succeeds.

Tests also complete OK. ;)

@kaspar030 kaspar030 merged commit 880b331 into RIOT-OS:master Nov 6, 2018
@kaspar030
Copy link
Contributor

kaspar030 commented Nov 6, 2018

(I'm puzzled because my openocd always thinks the bluepill has 128k RAM flash).

@MrKevinWeiss MrKevinWeiss added the Reviewed: 3-testing The PR was tested according to the maintainer guidelines label Nov 6, 2018
@jnohlgard
Copy link
Member

@kaspar030 doesn't OpenOCD look at the actual CPU register values for the flash specs on STM32 though?
On Kinetis the flash banks are automatically configured to the actual size and layout for the connected CPU by reading some flash info registers.
This can obviously not be done for the linking stage, so we need to manually tell the linker about the memory layout.

@maribu
Copy link
Member Author

maribu commented Nov 6, 2018

As minor addition to @gebart: The documentation in the bluepill points that out and suggests to either fiddle with the openocd config (to ignore the flash size the MCU reports in this particular case) or to use a patched version st-flash. I also so far had no problems with flashing more than 64KiB using GDB and the blackmagic probe. (I'm not sure if these tools are aware that the STM32F103C8 has in fact 128 KiB ROM, or if they just ignore whatever the MCU reports at all. I guess the latter.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: boards Area: Board ports CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines 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.

5 participants