I'm trying to initialize the debug trace SWO output pin on STM32H743. I have tried various code snippets for initializing the port, currently this one:
void SWD_Init(void) { *(__IO uint32_t*)(0x5C001004) |= 0x00700000; // DBGMCU_CR D3DBGCKEN D1DBGCKEN TRACECLKEN //UNLOCK FUNNEL *(__IO uint32_t*)(0x5C004FB0) = 0xC5ACCE55; // SWTF_LAR *(__IO uint32_t*)(0x5C003FB0) = 0xC5ACCE55; // SWO_LAR //SWO current output divisor register //This divisor value (0x000000C7) corresponds to 400Mhz //To change it, you can use the following rule // value = (CPU Freq/sw speed )-1 *(__IO uint32_t*)(0x5C003010) = ((SystemCoreClock / 2000000) - 1); // SWO_CODR //SWO selected pin protocol register *(__IO uint32_t*)(0x5C0030F0) = 0x00000002; // SWO_SPPR //Enable ITM input of SWO trace funnel *(__IO uint32_t*)(0x5C004000) |= 0x00000001; // SWFT_CTRL //RCC_AHB4ENR enable GPIOB clock *(__IO uint32_t*)(0x580244E0) |= 0x00000002; // Configure GPIOB pin 3 as AF *(__IO uint32_t*)(0x58020400) = (*(__IO uint32_t*)(0x58020400) & 0xffffff3f) | 0x00000080; // Configure GPIOB pin 3 Speed *(__IO uint32_t*)(0x58020408) |= 0x00000080; // Force AF0 for GPIOB pin 3 *(__IO uint32_t*)(0x58020420) &= 0xFFFF0FFF; }
However whatever I do, the CPU hangs during the SWO register access. This also causes debugger to lose connection. If I comment the SWO register initialization lines, the code runs ok but of course SWO output doesn't work.