Skip to main content
Alfonso L
Associate
July 18, 2017
Solved

STM32F103: How to use PB4 as normal GPIO? NJTRST remap not working.

  • July 18, 2017
  • 1 reply
  • 2900 views
Posted on July 18, 2017 at 20:05

Hello. I need to use PB4 as a normal GPIO digital output pin. I�m using the HAL for developing the firmware. The code I use for configuring GPIO is:

__HAL_AFIO_REMAP_SWJ_NONJTRST();

__HAL_RCC_GPIOB_CLK_ENABLE();

GPIO_InitTypeDef config_gpio = {0};

config_gpio.Pin = GPIO_PIN_4;

config_gpio.Mode = GPIO_MODE_OUTPUT_PP;

config_gpio.Pull = GPIO_NOPULL;

config_gpio.Speed = GPIO_SPEED_FREQ_HIGH;

HAL_GPIO_Init(GPIOB, &config_gpio);

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, GPIO_PIN_RESET);

After that, PB4 is always pulled high and I can't set it low, probably because it keeps behaving as NJTRST, so I can�t use it as a normal output.

It seems that the macro __HAL_AFIO_REMAP_SWJ_NONJTRST() doesn�t do anything.

I would appreciate any advice.

Thanks.

#stm32f103 #afio #njtrst #jntrst #pb4 #remap #swj #stm32 #stm32f1
This topic has been closed for replies.
Best answer by Vangelis Fortounas
Posted on July 19, 2017 at 14:05

Hello!!

you must call first __HAL_RCC_AFIO_CLK_ENABLE();

1 reply

Vangelis Fortounas
Associate II
July 19, 2017
Posted on July 19, 2017 at 14:05

Hello!!

you must call first __HAL_RCC_AFIO_CLK_ENABLE();

Alfonso L
Alfonso LAuthor
Associate
July 19, 2017
Posted on July 19, 2017 at 19:29

That was it, thanks!