0
\$\begingroup\$

I am following a course on USB programming on STM32 platform. My board is a STM32F746G-DISCO with a STM32F746NG microcontroller.

In the course, the teacher sets his board to these frequencies:

SYSCLK = 72MHz
HCLK = 72MHz
APB1 CLK = 36MHz
APB2 CLK = 72MHz

The settings he uses are:
enter image description here

So CubeMX also confirms that these settings are correct.

However when I try to set these settings on my board, It always crashes and goes into this infinite loop:
enter image description here

Here is my code:
enter image description here

I checked my oscillator on the scope and it works as expected with a 8MHz frequency, so this config is supposed to work according to the datasheet...

The problem seems to come from the P parameter of the PLL. See line 29 in my code, if I change P = 0 to P = 2, then there is no crashes. (in the datasheet, it is written than a P = 0 value in the register sets PLL P parameter to 2, and a P = 2 value in the register sets PLL P parameter to 4).

Has someone encountered this problem? I've tried many things, I checked my oscillator, checked with the debugger than my configuration registers have the correct value, etc.

Edit: I forgot to say that the program crashes as soon as it exits the ClkConfig function.

\$\endgroup\$
10
  • 2
    \$\begingroup\$ The IDE claims you hit a WWDG interrup handler. Please figure out if that is true or if it's some other exception handler and why it gets triggered as they all end up running the same loop. \$\endgroup\$
    – Justme
    Sep 19, 2022 at 12:28
  • \$\begingroup\$ @Justme ok, I've checked the WWDG and it is disabled. Then I've checked the xpsr register and found that the interrupt triggered is interrupt number 3. Seems this is a hard fault then \$\endgroup\$
    – Wheatley
    Sep 19, 2022 at 13:32
  • 1
    \$\begingroup\$ Yes, there you go. Now to find what's causing it. Where's your stack and how much there is? \$\endgroup\$
    – Justme
    Sep 19, 2022 at 13:33
  • \$\begingroup\$ @Justme I have no idea how to check this. I have found only this information for now: "_Min_Stack_Size = 0x400;". When it crashes, SP = 0x2004ffd0 but I don't know how to check the stack origin and its actual size \$\endgroup\$
    – Wheatley
    Sep 19, 2022 at 13:38
  • \$\begingroup\$ Also, the value at memory address 0 is 0x06CE9076 so this is supposed to be the stack origin, right? But if so, it would mean that the stack size is 422Mb so something is wrong ... \$\endgroup\$
    – Wheatley
    Sep 19, 2022 at 13:42

1 Answer 1

1
\$\begingroup\$

Ok, I've finally fixed this problem, and it was really simple in fact, althought it took me a week to find the solution

The schematics and the BOM of my board have an error: the external oscillator frequency is 25MHz, but is written as 8MHz on the documents ...

I don't know what I've measured on the scope, but it was 8MHz so there was a coincidence ...

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.