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

Fix initialization of USB HID and PB2 pull down #42

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

Conversation

jcdevel
Copy link

@jcdevel jcdevel commented Jan 23, 2021

These are fixes to a couple of issues that I found while trying to use the HID bootloader in my custom STM32 board (based on BluePill, but with some customizations). I share them here if it is of interest to other developers.

PB2 Pull Down activation had an issue because the pins_init() function was not clearing the CNF2_0 bit, so the pin was entering a Reserved state (CNF='11'), according to STM32 programming manual.

I am using the HID bootloader to flash a custom application (not created with Arduino-STM32). Since my application does not write the magic word in the backup registers (yet), I set Boo1 (PB2) to high level for reflashing, then press reset. In this scenario, the HID bootloader does not reset the USB connection back to HID mode, so the previous state is preserved and the hid_flash tool cannot find the board.

I think the HID bootloader should not rely on the application to reset the USB connection into HID mode, but always perform reset (this is what my patch does).

'make DEBUG=1' sets compiler flags -O0 -g3. Otherwise, -Os is used.
If bit 0 of CFN is not cleared (it is set to 1 after reset), the
pin goes into Reserved mode (11), instead of Input PU/PD (10).
This fixes the issue.
Currently, the HID bootloader checks if the application has written
a magic word in the backup registers in order to reset the USB
connection in HID mode. However, if we loaded a faulty application
that does not write the backup registers, USB is not reinitialized
and flashing is no longer possible, even if we use the BOO1 button.

This change fixes the issue by resetting the USB to HID mode every
time we enter flashing mode, no matter the origin of the request.
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.

1 participant