AnsweredAssumed Answered

Issues when setting SWJ_CFG in AFIO->MAPR to SWJ_NOJTAG

Question asked by kraske.robert on Oct 7, 2016
Latest reply on Apr 13, 2018 by Jalon Wong
I'm using the STM32F103.

Setting the controller to __HAL_AFIO_REMAP_SWJ_NOJTAG on startup. Which means I want to use only the SW pins and the port pins PA15, PB3 and PB4 should be normal IO pins.

I observed the following problem:

Unfortunately the related bits in AFIO->MAPR are write only. Reading these three bits is undefined. In fact, depending on the settings of AFIO->MAPR I observed that a 0x4 is read back if a 0x2 was written. So far it is ok as we can't rely on the read bits.

Unfortunately the code in stm32f1xx_hal_gpio_ex.h relies on these read back bits of SWJ_CFG. This is the case in all of the macros which uses MODIFY_REG(AFIO->MAPR...
These macros reads back AFIO_MAPR. When reading back AFIO_MAPR you also read back the undefined bits of SWJ_CFG. And when writing back to AFIO_MAPR, you write a different (or wrong) value into SWJ_CFG.

Outcomes