Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for STM32F103 (Blue Pill) #541

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Risca
Copy link

@Risca Risca commented Jan 26, 2025

The Blue Pill board is typically fitted with a STM32F103C8T6, but
reports online seem to indicate that it sometimes can come with its
bigger sibling the STM32F103C8TB as is the case with my board.

This patch adds support for all low- to medium-density STM32F103
devices. All of these devices have their flash divided in 1 KB pages, up
to 128 KB. The high-density and connectivity line of devices, sometimes
called XL devices, use 2 KB pages and are not supported.

Similar to the STM32F4 support, the code will spin up the PLL for
maximum speed during init and turn it off just before booting the
application. the maxium speed is 72 MHz.

Booting with the example config takes around 6 seconds.
Updating takes about 15.

Copy link
Member

@danielinux danielinux left a comment

Choose a reason for hiding this comment

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

Thanks @Risca for the proposed port. This looks good so far.

  • Please do get in touch with us at [email protected] to fill our Contributor Agreement form, if you haven't already, mentioning this PR.
  • The hal_flash_write function is not supposed to erase sectors. Please remove all erase commands from hal_flash_write.
  • Please rename the TARGET and file names to stm32f1 for consistency with other ports.
  • Our ports usually include also one paragraph of instructions in docs/Targets.md, and a non-regression build test in github actions, but I could also commit those on top while testing, once the above points are solved.

hal/stm32f103.c Outdated
return 0;
}

int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
Copy link
Member

Choose a reason for hiding this comment

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

Don't worry at all about erasing the page before write. This task is performed by wolfBoot, that will always call erase before writing. If the flash memory does not support consecutive writes after erase, just add NVM_FLASH_WRITEONCE=1 to the example config, like for similar STM32 targets.

Please remove any erase commands issued in hal_flash_write.

Copy link
Author

Choose a reason for hiding this comment

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

Ah, I see! I couldn't figure out if this was the case so I opted for the safe approach. This makes the implementation much simpler!

arch.mk Outdated
@@ -139,6 +139,12 @@ ifeq ($(ARCH),ARM)
ARCH_FLASH_OFFSET=0x08000000
endif

ifeq ($(TARGET),stm32f103)
Copy link
Member

Choose a reason for hiding this comment

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

I think we should rename the target (and the associated files) to stm32f1 for consistency with the other ports, to cover the entire family.

Comments in the files, referring to STM32F103, are OK, and even mentioning the BluePill in the test-app as you did is actually helpful as reference if anyone is testing on a different STM32F1.

Copy link
Author

Choose a reason for hiding this comment

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

Sure!

Risca added 4 commits January 29, 2025 21:48
The Blue Pill board is typically fitted with a STM32F103C8T6, but
reports online seem to indicate that it sometimes can come with its
bigger sibling the STM32F103C8TB as is the case with my board.

This patch adds support for all low- to medium-density STM32F103
devices. All of these devices have their flash divided in 1 KB pages, up
to 128 KB. The high-density and connectivity line of devices, sometimes
called XL devices, use 2 KB pages and are not supported.

Similar to the STM32F4 support, the code will spin up the PLL for
maximum speed during init and turn it off just before booting the
application. the maxium speed is 72 MHz.

Signed-off-by: Patrik Dahlström <[email protected]>
The test application used during development of STM32F103 support. If
booting version 1 of the software, trigger an update. If running ver. 2,
all is good.

Signed-off-by: Patrik Dahlström <[email protected]>
Config based on the STM32F4 ditto.

Booting takes about 6 seconds and update around 15.

Signed-off-by: Patrik Dahlström <[email protected]>
Signed-off-by: Patrik Dahlström <[email protected]>
@Risca
Copy link
Author

Risca commented Jan 29, 2025

Thanks @Risca for the proposed port. This looks good so far.

  • Please do get in touch with us at [email protected] to fill our Contributor Agreement form, if you haven't already, mentioning this PR.

  • The hal_flash_write function is not supposed to erase sectors. Please remove all erase commands from hal_flash_write.

  • Please rename the TARGET and file names to stm32f1 for consistency with other ports.

  • Our ports usually include also one paragraph of instructions in docs/Targets.md, and a non-regression build test in github actions, but I could also commit those on top while testing, once the above points are solved.

I've fixed the rename and (hopefully) the build test. The rest will be a few days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants