2026-04-23 12:04 AM - last edited on 2026-04-23 2:24 AM by mƎALLEm
This is probably an old hat to most of you here but I'm facing this problem momentarily:
Using an STM32F103CBT6 (Blue Pill) where GPIOB Port is used already with the following
PB3 - SPI1_SCK
PB5 - SP1_MOSI
PB6 - Some Interface Function (OUTPUT)
PB7 - Some Interface Function (OUTPUT)
I want to use PB0, PB1, PB4, PB8, PB12,PB13,PB14,PB15 for a keyboard matrix scan and output
a running pattern to these pins. Writing the bits should be nondestructive what the remaining bits is concerned.
At the back of my mind I recall something like BSRR, but could someone help me to get on the right track?
I'm using HAL in this app (under STM32CubeIDE).
Solved! Go to Solution.
2026-04-23 12:42 AM
I'd recommend to consult the reference manual.
The F103 has a BSRR register for setting and resetting of individual bits, and a BRR for resetting bits.
Section 9.2.5 and 9.2.6 in RM008 : https://www.st.com/resource/en/reference_manual/rm0008-stm32f101xx-stm32f102xx-stm32f103xx-stm32f105xx-and-stm32f107xx-advanced-armbased-32bit-mcus-stmicroelectronics.pdf
2026-04-23 12:42 AM
I'd recommend to consult the reference manual.
The F103 has a BSRR register for setting and resetting of individual bits, and a BRR for resetting bits.
Section 9.2.5 and 9.2.6 in RM008 : https://www.st.com/resource/en/reference_manual/rm0008-stm32f101xx-stm32f102xx-stm32f103xx-stm32f105xx-and-stm32f107xx-advanced-armbased-32bit-mcus-stmicroelectronics.pdf
2026-04-23 12:53 AM
And additionally, I would like to point out once again that the Bluepills have contained almost exclusively fakes for years, which we cannot support. It would make more sense to contact the manufacturer of the counterfeits.
Regards
/Peter
2026-04-23 1:07 AM - edited 2026-04-24 7:43 AM
LL_GPIO_SetOutputPin sets individual pins or masks of pins on the same port using lower 16 bits of BSRR: BSy:.
LL_GPIO_ResetOutputPin clears individual pins or masks of pins on the same port using upper 16 bits of BSRR: BRy.
HAL_GPIO_WritePin sets or clears individual pins or masks of pins on the same port using BSRR.
If you want to set and clear multiple pins on the same port in one operation you need to write to BSRR yourself:
BSRR = (pinsToClear<<16) | pinsToSet;