OK, I found:
I need to set the GPIO's of my target uc in cube IDE (the cube MX part) to the debugger pins.
Then the
__HAL_AFIO_REMAP_SWJ_DISABLE();
is replaced by
__HAL_AFIO_REMAP_SWJ_ENABLE();
The deubgger still does not work in Cube IDE, but it works on the same environment flawlessly with Ozone.
So now I use Cube Ide for compiling and flashing, and Ozone for debugging.
That works for now.