2025-10-15 12:45 PM - last edited on 2025-10-16 4:46 AM by Andrew Neil
Guys, I need to put 5V on a pin. For this, I configured my pin as an open-drain output with a pull-up resistor (10k) between the pin and the 5V line. I checked the 5V-tolerant pins in the Blue Pill datasheet and tested many of them, but the conclusion is always the same: the output is 3.7V when the pin is in high impedance. I used Keil uVision to write my code in C (at startup, I only used CMSIS and DEVICE for pre-configuration). My code is below. I used PB10 as a reference.
#include "stm32f10x.h"
int main(){
RCC->APB2ENR |= (1 << 3); // Clock for GPIOB
// Open-drain output and HIGH impedance PB10
GPIOB->CRH &= ~(0b1111 << 8); // Cleaning bits
GPIOB->CRH |= (0b0111 << 8); // Setting up bits
GPIOB->ODR |= (1 << 10); // HIGH impedance
};Edited to apply source code formatting - please see How to insert source code for future reference.
2025-10-15 12:57 PM
Maybe the overwhelmingly likely counterfeit chip on the board doesn't have 5 V tolerant pins.
2025-10-15 2:43 PM
You have (at least) made two mistakes:
You are using a so-called Blue Pill that has only been used with counterfeits for years (and you are asking for a solution for the counterfeit in the forum of the original manufacturer).
Regards
/Peter
2025-10-15 2:44 PM
Thanks for your comment! I didn't think it was a clone, as the debugger with STM32CubeIDE worked perfectly fine. However, after checking some IDs, I found very strange values, so it's probably fake =(
2025-10-15 3:03 PM
Thanks for the clarification, Peter. I'm new to the world of microcontrollers, and I'm diving into bare metal to understand how things really work. Didn't know there were clones. I will probably move to a NUCLEO one in the future (to avoid spending many hours on these bugs).
"You are confusing 5V tolerance (of an input) with 5V capability of an output" --> Could you explain what you mean? I know the output voltage on a pin is normally 3.3V, but if I configure the output as open-drain (high impedance) and connect a pull-up resistor to it, I can get higher values of voltage, right?
2025-10-15 3:28 PM
This depends on:
Details on GPIO behaviour can be found for the original device in the data sheet and in the Reference Manual RM0008.
Hope that helps?
Regard
/Peter
2025-10-17 3:31 PM
I know the output voltage on a pin is normally 3.3V, but if I configure the output as open-drain (high impedance) and connect a pull-up resistor to it, I can get higher values of voltage, right?
The pins will have clamping diodes. Even if the pin is an input or output, It'll protect the pin. In this case, the diodes are preventing the resistor from pulling the pin up to 5V.
2025-10-18 1:50 AM - edited 2025-10-18 1:51 AM
Not exactly true. In STM32, 5V-tolerant pins have clamping diodes with the cathodes connected to a circuit that provides clamping to 6V or little above. So, for normal 5V-tolerant pins it's perfectly correct to use external pull-up resistor to 5V and with such a resistor the output voltage will be close to 5V.
Chinese clones may behave differently.