stm32f103c8t6, pins B3 and B4 doesn't work, CubeIDE, HAL

82 views Asked by At

I did something wrong in CubeIDE and two pins stopped working. (Maybe something else stopped working until I saw it). To check, I created a new project for stm32f103c8t6 and added the following code in "main.c":

while (1)
{
  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_7, GPIO_PIN_SET); //
  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_SET); //
  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_SET); //
  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, GPIO_PIN_SET); //
  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_SET); //
      HAL_Delay (1000);
  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_7, GPIO_PIN_RESET); //
  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_RESET); //
  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_RESET); //
  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, GPIO_PIN_RESET); //
  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET); //
      HAL_Delay (1000);
/* USER CODE END WHILE */

/* USER CODE BEGIN 3 */

}

I tried other chips, the pins are not connected to anything, I tested with the device, the problem remains - the pins B3 and B4 do not work, the rest work. Pins B3-B7 configured as outputs. What could I have done wrong?

I found a solution. But I still didn't understand why the problem arose.

__HAL_RCC_AFIO_CLK_ENABLE();
__HAL_AFIO_REMAP_SWJ_NOJTAG();
1

There are 1 answers

0
David Grayson On

If you look in the pin definitions table of STM32F103x8 datasheet, you can see that PB3 and PB4 are JTAG pins, which means you might be using them to flash and debug the board. You should probably just use some other pins, but if you need to use those ones, I think you have to do add some special code to turn off the JTAG module at the beginning of your program.