Skip to main content
Associate II
November 22, 2023
Solved

HAL_Init() Returns HAL_ERROR due to common_system_clock Being Zero on STM32H747I-Discovery

Dear STM Support Team,

I am currently working on a project using the STM32H747I-Discovery Kit and have encountered an issue during system initialization. After integrating code from the STemWin_HelloWorld example and successfully compiling, the HAL_Init() function returns HAL_ERROR.

Upon debugging, I have found that the common_system_clock variable is being set to zero when returning from the following block of code:

 

#if defined(RCC_D1CFGR_D1CPRE)
 common_system_clock = HAL_RCC_GetSysClockFreq() >> ((D1CorePrescTable[(RCC->D1CFGR & RCC_D1CFGR_D1CPRE)>> RCC_D1CFGR_D1CPRE_Pos]) & 0x1FU);
#else
 // Other conditionals or relevant code
#endif

 

HAL_RCC_GetSysClockFreq() correctly returns a value that corresponds to 64MHz, so the issue seems to arise during the prescaler application. This leads to a situation where common_system_clock becomes zero, which should not be the case.

I have double-checked the clock configurations, prescaler settings, and the relevant RCC registers but have not found any discrepancies that could lead to this issue.

Could you please advise on what might be causing this behavior or provide any additional steps to troubleshoot this problem? I am using the latest HAL library version recommended for STM32H747I-Discovery.

Thank you in advance for your support.

This topic has been closed for replies.
DasBest answer
Associate II
November 24, 2023

@FBL @Tesla DeLorean,

Issue identified and fixed. Thank you for the suggestions and support. Issue was in the linker script. Accidentally I changed the .rodata assigned to RAM. 

13 replies

Tesla DeLorean
Guru
November 22, 2023

RCC->D1CFGR contains What?

What about DBGMCU->IDCODE ?

I suspect D1CorePrescTable isn't deep enough

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
DasAuthor
Associate II
November 22, 2023

I noticed a weird thing, with my application in debug mode, I can't see the register values instead it shows(Debug Current Instruction Pointer). But I could see the current value of  D1CorePrescTable. 

 

Name : D1CorePrescTable
	Details:"Þ\0 `ßßP\032\thI\aúúúú"
	Default:0x24000020 <D1CorePrescTable>
	Decimal:603979808
	Hex:0x24000020
	Binary:100100000000000000000000100000
	Octal:04400000040

 

 

But for the STemWin_HelloWorld Example, the same IDE gives a different result for the same line. 

Debug Output for the same line looks as below. 

 

Name : D1CorePrescTable
	Details:"\0\0\0\0\001\002\003\004\001\002\003\004\006\a\b\t"
	Default:0x801377c <D1CorePrescTable>
	Decimal:134297468
	Hex:0x801377c
	Binary:1000000000010011011101111100
	Octal:01000233574
Name : RCC_D1CFGR_D1CPRE_Pos
	Details:8
	Default:8
	Decimal:8
	Hex:0x8
	Binary:1000
	Octal:010
Name : RCC->D1CFGR
	Details:0
	Default:0
	Decimal:0
	Hex:0x0
	Binary:0
	Octal:0
Name : RCC_D1CFGR_D1CPRE_Pos
	Details:8
	Default:8
	Decimal:8
	Hex:0x8
	Binary:1000
	Octal:010

 

 If you need more info please let me know. Looking forward to get some clue from given info. 

 

ST Technical Moderator
November 22, 2023

Hello @Das 

Thank you for you feedback I will check it and get back to you soon.

To give better visibility on the answered topics, please click on "Best answer" on the reply which solved your issue or answered your question.Best regards,FBL
DasAuthor
Associate II
November 23, 2023

Thanks @FBL. 

One more noted thing between the above mentioned two application(STemWin HelloWorld and my application) is that one is STM32 Project(makefile) and my application is manually created project(CMAKE). Let me if this kind of approach is wrong or not. 

Thanks. 

ST Technical Moderator
November 23, 2023

Hello @Das 

 

Are you generating the main clock using internal RC oscillator?  It is possible when removing resistor R73, the system cannot run from the internal HSI while executing HAL_Init().

In my eval board, it is working without issues.

FBelaid_0-1700745490799.png

 

To give better visibility on the answered topics, please click on "Best answer" on the reply which solved your issue or answered your question.Best regards,FBL
DasAuthor
Associate II
November 23, 2023

Hi @FBL ,

I didn't make any change in my hardware. Let me tell you one thing, I have simply used STM provided Hello World Example for STM32H747I-Discovery Kit to my project.  Hello World Example works fine if I import as STM project. But with the same code on my project created as Cmake based project having the above mentioned issue. 

I don't understand about the R73 resistor. Where should I check for RC Oscillator? 

Tesla DeLorean
Guru
November 23, 2023

Check defines pushed into the compilers command line.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
DasAuthor
Associate II
November 24, 2023

@FBL ,

I could resolve the IDE related problems with my project(I believe so). Now I am able to see the values for the RCC registers while debugging. But the D1CorePrescTable value seem to be different from what I saw in the example. What could be the possible reasons for that value get changed. 

DasAuthor
Associate II
November 24, 2023

@FBL  Can you tell me what could be the possible reasons for change in D1CorePrescTable? 

 

Name : D1CorePrescTable
Details:"# \036IûhQø#0yh\003û\001ñ"
Default:0x240029e0 <D1CorePrescTable>
Decimal:603990496
Hex:0x240029e0
Binary:100100000000000010100111100000
Octal:04400024740
common_system_clock = HAL_RCC_GetSysClockFreq() >> ((D1CorePrescTable[(RCC->D1CFGR & RCC_D1CFGR_D1CPRE)>> RCC_D1CFGR_D1CPRE_Pos]) & 0x1FU)

 

HAL_RCC_GetSysClockFreq returns 64000000

RCC->D1CFGR = 0

RCC_D1CFGR_D1CPRE = 3840

RCC_D1CFGR_D1CPRE_Pos = 8

But the  D1CorePrescTable[16] = {0, 0, 0, 0, 1, 2, 3, 4, 1, 2, 3, 4, 6, 7, 8, 9} initialised got changed due to some reason. I don't know how and why. Any suggestion to debug to understand this. 

DasAuthorBest answer
Associate II
November 24, 2023

@FBL @Tesla DeLorean,

Issue identified and fixed. Thank you for the suggestions and support. Issue was in the linker script. Accidentally I changed the .rodata assigned to RAM.