cancel
Showing results for 
Search instead for 
Did you mean: 

Target is not responding, retrying... MCO set to HSI in STM32CubeIDE - NUCLEO-F303RE

Birbal
Associate

I am trying to route the HSI clock to an external port of the board and so far I have got this code:

 

#define RCC_BASE_ADDR 0x40021000UL
#define RCC_CFGR_OFFSET 0x04UL
#define RCC_CFGR_ADDR (RCC_BASE_ADDR + RCC_CFGR_OFFSET)

int main(void)
{
	uint32_t *pRccCfgrReg = (uint32_t*) RCC_CFGR_ADDR;
	// Configure RCC_CFGR register MCO select HSI as a source 26:24 = 010
	// Clear bits 26:24
	*pRccCfgrReg &= ~(0x7 << 24);
	// Set bits 26:24 to 101 HSI
 	*pRccCfgrReg |= ~(0x5 << 24);

    /* Loop forever */
	for(;;);
}

 

So all I am trying to do is to set MCO (Microcontroller Clock Output) bits 26:24 of the RCC_CFGR (Clock Configuration Register) to 101 which according to the manual is the HSI clock selected.

However when I execute line 12 (*pRccCfgrReg |= ~(0x5 << 24); ) in debug mode it goes into: 

 

Download verified successfully 


Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Could not halt device (19)
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Failed to read registers from target
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...
Failed to read registers from target
Shutting down...
Exit.

 

Any ideas on what I am doing wrong?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ghofrane GSOURI
ST Employee

Hello @Birbal 

First let me thank you for posting.

It looks like you're trying to configure the Microcontroller Clock Output (MCO) to use the HSI clock on the STM32F303RE, but you are encountering issues when accessing the target device. Here are a few suggestions to help troubleshoot and correct your code:

1. Check Your Bit Manipulation

Instead of using the bitwise NOT operator (~), you should use the bitwise OR operator directly on the value you want to set. Here’s how you can modify your code:

// Clear bits 26:24
*pRccCfgrReg &= ~(0x7 << 24);
// Set bits 26:24 to 101 (HSI)
*pRccCfgrReg |= (0x5 << 24);

2. System Initialization
Ensure that your system is properly initialized before accessing the RCC registers. Typically, this involves:

Enabling the HSI oscillator.
Waiting for the HSI to stabilize.

3. Debugging Connection Issues 

The "Target is not responding" messages could be due to several reasons:

- Connection Issues: Ensure your debugger is properly connected to the NUCLEO board. Check the USB cable and connections.
- Power Supply: Make sure the board is powered correctly. Sometimes, insufficient power can cause issues.
- Reset the Board: Try resetting the board or power cycling it.
- Debug Configuration: Ensure your debug settings in STM32CubeIDE are correct. Check the selected debugger interface (e.g., ST-Link) and settings.

4.Use STM32 HAL or LL Libraries

If you're still having issues, consider using the STM32 HAL (Hardware Abstraction Layer) or LL (Low Layer) libraries for easier register handling.

 

THX

Ghofrane

 

View solution in original post

2 REPLIES 2
Ghofrane GSOURI
ST Employee

Hello @Birbal 

First let me thank you for posting.

It looks like you're trying to configure the Microcontroller Clock Output (MCO) to use the HSI clock on the STM32F303RE, but you are encountering issues when accessing the target device. Here are a few suggestions to help troubleshoot and correct your code:

1. Check Your Bit Manipulation

Instead of using the bitwise NOT operator (~), you should use the bitwise OR operator directly on the value you want to set. Here’s how you can modify your code:

// Clear bits 26:24
*pRccCfgrReg &= ~(0x7 << 24);
// Set bits 26:24 to 101 (HSI)
*pRccCfgrReg |= (0x5 << 24);

2. System Initialization
Ensure that your system is properly initialized before accessing the RCC registers. Typically, this involves:

Enabling the HSI oscillator.
Waiting for the HSI to stabilize.

3. Debugging Connection Issues 

The "Target is not responding" messages could be due to several reasons:

- Connection Issues: Ensure your debugger is properly connected to the NUCLEO board. Check the USB cable and connections.
- Power Supply: Make sure the board is powered correctly. Sometimes, insufficient power can cause issues.
- Reset the Board: Try resetting the board or power cycling it.
- Debug Configuration: Ensure your debug settings in STM32CubeIDE are correct. Check the selected debugger interface (e.g., ST-Link) and settings.

4.Use STM32 HAL or LL Libraries

If you're still having issues, consider using the STM32 HAL (Hardware Abstraction Layer) or LL (Low Layer) libraries for easier register handling.

 

THX

Ghofrane

 

Thank you so much for your reply. Yes, my bad I had the NOT operator on line 12. It was just a copy-paste mistake from the line above and I forgot to remove the NOT operator