Hi @builderx
The AFIO_MAPR register manages the reassignment of alternate functions on the MCU pins, including the configuration of the SWJ (Serial Wire JTAG) debug ports, which cover both JTAG and SWD. Thus, the pins used for debugging (SWD/JTAG) can be reassigned to other functions through this register.
The remapping functions are as follows:
HAL_AFIO_REMAP_SWJ_ENABLE(): Enables JTAG-DP + SW-DP (all pins)
HAL_AFIO_REMAP_SWJ_NOJTAG(): Disables JTAG, keeps SWD active
HAL_AFIO_REMAP_SWJ_DISABLE(): Disables both JTAG and SWD (all pins freed)
After completely disabling SWJ with the function HAL_AFIO_REMAP_SWJ_DISABLE(), all pins dedicated to debugging are freed for other GPIO uses. Calling this function disconnects the pins from the debug module, so even if you then call HAL_AFIO_REMAP_SWJ_NOJTAG(), it is not enough to restore the SWD connection.
Remapping acts like a switch that must be explicitly enabled or disabled.
To reactivate SWD, you must reassign the pins to the debug function by calling HAL_AFIO_REMAP_SWJ_ENABLE() function. This function resets the internal multiplexer to its default state, reconnecting the SWD and JTAG pins to the debug module.
If you want to disable only JTAG while keeping SWD active, you can then call HAL_AFIO_REMAP_SWJ_NOJTAG() function.
You can refer to the Reference Manual RM0008, specifically section 9.3 Alternate function I/O and debug configuration (AFIO), where you will find a detailed description of AFIO.
Thanks,
ELABI.1