cancel
Showing results for 
Search instead for 
Did you mean: 

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

Alfonso L
Associate
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
1 ACCEPTED SOLUTION

Accepted Solutions
Posted on July 19, 2017 at 14:05

Hello!!

you must call first __HAL_RCC_AFIO_CLK_ENABLE();

View solution in original post

2 REPLIES 2
Posted on July 19, 2017 at 14:05

Hello!!

you must call first __HAL_RCC_AFIO_CLK_ENABLE();

Posted on July 19, 2017 at 19:29

That was it, thanks!