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 generalised support for stm32 f103 to simplify bluepill based boards #5669

Closed
wants to merge 7 commits into from

Conversation

zvecr
Copy link
Member

@zvecr zvecr commented Apr 20, 2019

Description

Similar to how the Proton C support was integrated into the core of the firmware, the aim is to provide a solid base for bluepill boards. The main goals are to minimise the amount of configuration by just requiring the MCU (and maybe the bootloader type) to be set.

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Keyboard (addition or update)
  • Keymap/layout/userspace (addition or update)
  • Documentation

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

@noroadsleft
Copy link
Member

If I'm reading this right, this extends the STM32 support so quantum/stm32 gets a subdirectory for each supported MCU (F103, F303, etc.) and sets up the defaults that are appropriate for it, correct? (I'm not really familiar with this area of the codebase.)

If so, I like this change. Anything that helps boost STM32 adoption (lowers the barrier of entry, eases integration with QMK, etc.) is good by me.

@zvecr
Copy link
Member Author

zvecr commented Apr 20, 2019

Correct, it should help reduce the duplication within the code base by providing those defaults.

As bluepill is the same width (slightly longer) as a pro micro, but more importantly a similar price, I can see it as a potential successor. Its not quite a Proton C, but at less than $2 its a solid alternative when designing a PCB.

@drashna
Copy link
Member

drashna commented Apr 28, 2019

@zvecr DFU_ARGS is for passing along arguments to the dfu programmer when you flash from command line. You can see how and where they are implemented here:

dfu-util: $(BUILD_DIR)/$(TARGET).bin cpfirmware sizeafter
$(DFU_UTIL) $(DFU_ARGS) -D $(BUILD_DIR)/$(TARGET).bin

Understand use of cannonkeys\ortho48 linker setup
What do you mean by that?

@zvecr
Copy link
Member Author

zvecr commented Apr 28, 2019

@drashna I understand the concept of the option DFU_ARGS but not what DFU_ARGS = -d 0483:df11 -a 0 -s 0x08000000:leave is doing for the proton_c and if it applies to blue pill.

ortho48 has a STM32F103x8_stm32duino_bootloader.ld file and has the following rules.mk config

# GENERIC STM32F103C8T6 board - stm32duino bootloader
OPT_DEFS = -DCORTEX_VTOR_INIT=0x2000
MCU_LDSCRIPT = STM32F103x8_stm32duino_bootloader
BOARD = GENERIC_STM32_F103

Makes me think there should be something like BOOTLOADER = stm32duino for this case where is configures the above? Any idea @awkannan

@awkannan
Copy link
Contributor

we can use DFU_ARGS to properly pass the correct dfu-util parameters for bluepills

We need these:

-d 1eaf:0003 -a2 -R

If the stm32duino bootloader is present, -a 2 exposes 0x8002000 as the starting flash zone, and -R will reset into the normal firmware at the end of flashing

@zvecr
Copy link
Member Author

zvecr commented May 2, 2019

@awkannan Awesome, thanks for that info. Whats your view on the BOOTLOADER = stm32duino idea to configure your suggestions?

That way, bluepill support is basically a 2 liner

MCU = STM32F103
BOOTLOADER = stm32duino

@zvecr zvecr changed the title Refactor of onekey to support multiple development boards Add generalised support for stm32 f103 to simplify bluepill based boards May 29, 2019
@zvecr zvecr force-pushed the feature/bluepill_onekey branch 2 times, most recently from 70c535b to 1e9e3c9 Compare June 30, 2019 21:14
@zvecr
Copy link
Member Author

zvecr commented Jun 30, 2019

Currently the rules.mk file is cut down to only the following,

# MCU name
MCU = STM32F103

# bluepill (with stm32duino bootloader) overrides
OPT_DEFS = -DCORTEX_VTOR_INIT=0x2000
MCU_LDSCRIPT = STM32F103x8_stm32duino_bootloader
DFU_ARGS = -d 1eaf:0003 -a2 -R
DFU_SUFFIX_ARGS ?= -v 1eaf -p 0003

Just need a decision if BOOTLOADER = stm32duino is overkill or if the above is acceptable.

@zvecr zvecr marked this pull request as ready for review June 30, 2019 23:30
Copy link
Contributor

@yanfali yanfali left a comment

Choose a reason for hiding this comment

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

---How hard would it be to add stm32f3xx support? I have a couple of bluepills in a draw I could use to test.--- My bad, I see you already added it?

@zvecr
Copy link
Member Author

zvecr commented Jul 1, 2019

@yanfali We currently have STM32F303 done in the same way for the Proton C, and I would been keen to do it for some of the other popular MCU. There will always be a place for the obscure, but reducing the duplication for something like the Teensy 3.2 can provide a ton of benefits.

@yanfali
Copy link
Contributor

yanfali commented Jul 1, 2019

OK, just for posterity's sake. Turns out there are some chinese clones for STM32 chips in the CS32 family. They are almost perfectly compatible, except they have a different chipid which is the same as chips in the F3 family from STM. So stlink doesn't officially support them. However if you follow this issue: stlink-org/stlink#756 you will find a commit which will allow you to use st-flash on these chips and be able to follow instructions like the ones from cannonkeys to flash them with QMK and stm32 boot loader.

@drashna
Copy link
Member

drashna commented Jul 2, 2019

Yeah. I know that the Planck Rev6, Planck EZ, and Preonic Rev3 use this method already.

Copy link
Contributor

@yanfali yanfali left a comment

Choose a reason for hiding this comment

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

Tested on cs32 bluepill clone boards, registers as one key keyboards. shorting pins produces expected 'a'

dancing

@zvecr zvecr mentioned this pull request Jul 2, 2019
13 tasks
@yanfali
Copy link
Contributor

yanfali commented Jul 4, 2019

tested this on a blackpill. works perfectly

@yiancar
Copy link
Contributor

yiancar commented Jul 5, 2019

Can you confirm what -R in dfu actually resets. it didnt work for me...

@zvecr
Copy link
Member Author

zvecr commented Jul 5, 2019

-R from the man page,

Issue USB reset signalling after upload or download has finished.

I will have to test my end to confirm the behaviour as I cannot remember seeing mine reboot. MCU reboots after flashing fine on my machine, Ubuntu 19.04 and dfu-util 0.9.

@yiancar
Copy link
Contributor

yiancar commented Jul 5, 2019

Yes but it didnt work on me so:)

@zvecr
Copy link
Member Author

zvecr commented Jul 5, 2019

@yiancar I'm not sure I can help if you don't list your environmental differences, so we can start to figure out the issue.

@yanfali Do you also see this issue?

@yiancar
Copy link
Contributor

yiancar commented Jul 5, 2019

im on mac dfu-util 0.9 which bootloader u using?

@zvecr
Copy link
Member Author

zvecr commented Jul 5, 2019

stm32duino as mentioned above, with the flashing steps provided at https://docs.cannonkeys.com/flashing/

@yiancar
Copy link
Contributor

yiancar commented Jul 5, 2019

ah sorry, yes thats what I got as well:)

@yiancar
Copy link
Contributor

yiancar commented Jul 5, 2019

Might be the MacOS

@yanfali
Copy link
Contributor

yanfali commented Jul 5, 2019

@zvecr mine doesn't reset, I usually just unplug.

@zvecr
Copy link
Member Author

zvecr commented Jul 5, 2019

I would then consider it a best effort until the exact circumstances can be worked out.

@drashna drashna requested review from a team and removed request for fredizzimo July 23, 2019 07:02
@drashna
Copy link
Member

drashna commented Jul 30, 2019

Is this ready to ship, as is? Or should it wait?

@zvecr
Copy link
Member Author

zvecr commented Jul 31, 2019

There might be some extra stuff, as @yanfali sent me a PR to add some docs, and given the extra time with my bluepills, I was thinking of some suggested changes to the defaults.

@yanfali
Copy link
Contributor

yanfali commented Aug 1, 2019

Yeah, -R did not work on the clones. Sorry it took me a while to notice this question.

@drashna
Copy link
Member

drashna commented Sep 21, 2019

There are some merge conflicts here.

@zvecr
Copy link
Member Author

zvecr commented Feb 27, 2020

Most of this PR has now been reimplemented, missing bits are just default central conf files. This will be tackled separately.

@zvecr zvecr closed this Feb 27, 2020
@zvecr zvecr deleted the feature/bluepill_onekey branch April 28, 2020 00:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants