I am trying to configure the STM32F411CEU6 onboard button (PA0), but cannot configure it to use the internal pull-down resistor. My current setup allows it to trigger an interrupt when using a pull-up resistor, but when I change it to a pull-down resistor it no longer works. I would appreciate if anyone could guide me on what I did wrong, and could clarify my understanding of the process. I am using the STM32 Standard Peripheral Library. I have put my GPIO initialization code below.
// enable clocks for the the KEY button (PA0) GPIO and
// the system configuration controller (SYSCFG) for GPIO interrupts
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
// initialize the GPIO pin, PA0, with an internal Pull-Down resistor
GPIO_InitTypeDef GPIO_Button_InitStructure = {
.GPIO_Pin = GPIO_Pin_0,
.GPIO_Mode = GPIO_Mode_IN,
.GPIO_PuPd = GPIO_PuPd_DOWN /* works with GPIO_PuPd_UP... */
};
GPIO_Init(GPIOA, &GPIO_Button_InitStructure);
/* ... Other interrupt enabling configuration stuff that is known to work here... */
The user push button on your black pill board is connected between PA0 and GND. It makes no sense to configure PA0 with pull-down configuration. In this case, pushing the button won't affect the state of the PA0 pin; it was logic 0 before the push and remain at logic 0 during and after the push. Obviously, the the hardware and software can't detect this push.
Edit:
Unlike the older blue pill boards, the schematic of the black pill boards is harder to find on internet. I was able to find it on their official Github repo. However, connecting push buttons to GND and pulling-up uC pins to logic 1 using either internal or external pull-up resistors is a common practice, so I'm not surprised that black pill board follows the same tradition.