Showing results for 
Search instead for 
Did you mean: 

HAL_RCC_OscConfig failure because of OpenOCD debugger in CubeIDE

Pavel A.
Evangelist III

I'm debugging STM32F767NIH6 on a custom board (similar to F767-DISCO).

The program runs in internal RAM (at 0x20000000)

When the debugger is OpenOCD, HAL_RCC_OscConfig fails.

When the debugger is the ST-Link GDB server, all is good. At least, the cube-generated init code passes SystemClock_Config successfully.

The adapter is external ST-LINK v3 mini.

I need the OpenOCD because it can do semihosting.

Any idea why it is failing?

This is my SystemClock_Config:

void SystemClock_Config(void)
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  RCC_OscInitStruct.OscillatorType = 
  RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
  RCC_OscInitStruct.LSEState = RCC_LSE_ON;
  RCC_OscInitStruct.LSIState = RCC_LSI_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLM = 25;
  RCC_OscInitStruct.PLL.PLLN = 432;
  RCC_OscInitStruct.PLL.PLLQ = 9;
  RCC_OscInitStruct.PLL.PLLR = 2;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
    Error_Handler();  //<<<<<<<< here it fails
//................ etc

​Below is the OOCD startup log:

Open On-Chip Debugger 0.11.0-rc2+dev-00044-g8340bb0 (2021-06-02-17:29)
Licensed under GNU GPL v2
For bug reports, read
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : STLINK V3J8M3 (API v3) VID:PID 0483:374E
Info : Target voltage: 0.022222
Error: target voltage may be too low for reliable debugging
Info : clock speed 8000 kHz
Info : stlink_dap_op_connect(connect)
Info : SWD DPIDR 0x5ba02477
Info : STM32F767NIHx.cpu: hardware has 8 breakpoints, 4 watchpoints
Info : STM32F767NIHx.cpu: external reset detected
Info : starting gdb server for STM32F767NIHx.cpu on 3333
Info : Listening on port 3333 for gdb connections
Info : accepting 'gdb' connection on tcp/3333
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08005e94 msp: 0x20000b38
Info : device id = 0x10016451
Info : flash size = 2048 kbytes
Info : Single Bank 2048 kiB STM32F76x/77x found
Info : starting trace server for STM32F767NIHx.tpiu on 3344
Info : Listening on port 3344 for tpiu_swo_trace connections
Info : accepting 'tpiu_swo_trace' connection on tcp/3344

 The ST server does NOT complain about the target voltage.

STMicroelectronics ST-LINK GDB server. Version 5.9.1
Copyright (c) 2021, STMicroelectronics. All rights reserved.
Starting server with the following options:
        Persistent Mode            : Disabled
        Logging Level              : 1
        Listen Port Number         : 61234
        Status Refresh Delay       : 15s
        Verbose Mode               : Disabled
        SWD Debug                  : Enabled
Waiting for debugger connection...
Debugger connected

Chief II

> When the debugger is OpenOCD, HAL_RCC_OscConfig fails.

Determine the exact line in that function and you will have a clue of the problem.