The short answer is yes you can.
As to how, at the lowest level (see the Reference Manual), those pins are internally routed to debug (rather than GPIO) by the MODE being set to alternate function i.e. the appropriate bits in GPIOx->MODER are 0b10; you'd want those bits to be 00 for digital input, 01 for output (or 11 for analog).
But there are complications.
- How do you write your code? Using stm32-Cube? LL wrappers? Some other software wrappers? Tell us what you use and some of us (probably not me) can tell you how to select this for that particular environment.
- How do you load your code into your stm32? I use the debug pins - so using them for anything else could cause problems
- How do you debug your code? I use the debug pins - see 2
Hope this helps; expand on point 1 and we might be able to help further.
Danish