Skip to main content
Explorer II
October 15, 2025
Question

Strange behavior on open-drain output mode for blue pill (STM32F103C8T6)

  • October 15, 2025
  • 2 replies
  • 535 views

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
};
 
Could you guys please tell me what I did wrong? 

Edited to apply source code formatting - please see How to insert source code for future reference.

    This topic has been closed for replies.

    2 replies

    Super User
    October 15, 2025

    Maybe the overwhelmingly likely counterfeit chip on the board doesn't have 5 V tolerant pins.

    Luki_GrinAuthor
    Explorer II
    October 15, 2025

    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 =(

    Technical Moderator
    October 15, 2025

    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).

    • You are confusing 5V tolerance (of an input) with 5V capability of an output

    Regards
    /Peter

    Luki_GrinAuthor
    Explorer II
    October 15, 2025

    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? 

    Technical Moderator
    October 15, 2025

    This depends on:

    • whether the specific GPIO has an alternative analogue function
    • and, as mentioned, whether it is an original or a counterfeit.

    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