I am currently building a project with a STM32F103RCT6 (shouldn't matter) and I ran into a problem.
CubeMX does initialize the SWD-Pins for programming. The problem seems to occur when I enable a timer peripheral on the same Port (PA8 in my case).
My workaround atm is to include a second call to "__HAL_AFIO_REMAP_SWJ_NOJTAG();" in the " /* USER CODE BEGIN 2 */" after CubeMX is finished initializing.
I found some information in the web pointing towards this being a problem with CubeMX doing invalid read/modify/write operations on the write-only MAPR register.
I didn't find an official way to report bugs with the CubeMX tool (like github os something like that), therefore I am writing into this forum.