Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for STM32F412Zx MCU #2011

Merged
merged 2 commits into from
May 16, 2023
Merged

Added support for STM32F412Zx MCU #2011

merged 2 commits into from
May 16, 2023

Conversation

Toritos01
Copy link

@Toritos01 Toritos01 commented Apr 26, 2023

This PR fixes/implements generic support for the STM32F412Zx variant, using the steps at this link: https://github.com/stm32duino/Arduino_Core_STM32/wiki/Add-a-new-variant-%28board%29

The motivation for stm32duino to have support for more variants, and to allow me to use this repo with a board that I personally have.

@fpistm fpistm added this to the 2.6.0 milestone Apr 26, 2023
@fpistm fpistm added this to In progress in STM32 core based on ST HAL via automation Apr 26, 2023
Copy link
Member

@fpistm fpistm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor changes to be done.
Is USB clock configured to 48MHz?

variants/STM32F4xx/F412Z(E-G)(J-T)/generic_clock.c Outdated Show resolved Hide resolved
variants/STM32F4xx/F412Z(E-G)(J-T)/generic_clock.c Outdated Show resolved Hide resolved
variants/STM32F4xx/F412Z(E-G)(J-T)/generic_clock.c Outdated Show resolved Hide resolved
STM32 core based on ST HAL automation moved this from In progress to Needs review Apr 26, 2023
@Toritos01
Copy link
Author

Some minor changes to be done. Is USB clock configured to 48MHz?

I tried enabling UST_OTG_FS on STM32CubeMx, but doing so breaks the clock configuration

Copy link
Member

@fpistm fpistm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update.
One line to remove and a proposal for system core clock config to have USB clokk at 48Mhz.
If you can test it and give your feedback, I could not test as I do not have a STM32F412Zx board.

variants/STM32F4xx/F412Z(E-G)(J-T)/generic_clock.c Outdated Show resolved Hide resolved
variants/STM32F4xx/F412Z(E-G)(J-T)/generic_clock.c Outdated Show resolved Hide resolved
STM32 core based on ST HAL automation moved this from Needs review to Reviewer approved Apr 28, 2023
@Toritos01
Copy link
Author

Sorry for the delay with testing this, didn't have access to my STM32F4 for a few days. I tested out the proposed fixes, but when I try running the CheckVariant.ino program, my LED does not blink and nothing shows up the serial monitor. Any recommendations on additional steps to take for this to work?

@fpistm
Copy link
Member

fpistm commented May 2, 2023

Hi @Toritos01
No worry.
The main changes was to configure clock for the USB:

+  RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {};
 
   /** Configure the main internal regulator output voltage
  */
   __HAL_RCC_PWR_CLK_ENABLE();
   __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
 
   /** Initializes the RCC Oscillators according to the specified parameters
  * in the RCC_OscInitTypeDef structure.
  */
   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
   RCC_OscInitStruct.HSIState = RCC_HSI_ON;
   RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
   RCC_OscInitStruct.PLL.PLLM = 8;
-  RCC_OscInitStruct.PLL.PLLN = 100;
+  RCC_OscInitStruct.PLL.PLLN = 96;
   RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
-  RCC_OscInitStruct.PLL.PLLQ = 2;
+  RCC_OscInitStruct.PLL.PLLQ = 4;
   RCC_OscInitStruct.PLL.PLLR = 2;
   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
     Error_Handler();
   }
 
   /** Initializes the CPU, AHB and APB buses clocks
-   */
-  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
+  */
+  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
+                                | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
@@ -58,6 +59,14 @@ WEAK void SystemClock_Config(void)
   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3) != HAL_OK) {
     Error_Handler();
   }
+
+  /** Initializes the peripherals clock
+  */
+  PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_CLK48;
+  PeriphClkInitStruct.Clk48ClockSelection = RCC_CLK48CLKSOURCE_PLLQ;
+  if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) {
+    Error_Handler();
+  }

It was generated thanks CubeMx and should be fine.
Main changes is we change the clock freq from 100 to 96 MHz in order to have a 48MHz for USB.
That's strange it does not works. I guess it fails in the HAL_RCCEx_PeriphCLKConfig but don't know why. You could try to debug with Arduino IDE 2.1.0 by enabling the -Og and -g in the menu. Then you should be able to debug.

Toritos01 and others added 2 commits May 16, 2023 10:02
Signed-off-by: Brandon Diaz <bld68@cornell.edu>
Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
@fpistm
Copy link
Member

fpistm commented May 16, 2023

Hi @Toritos01
I've been able to test with a Nucelo F412ZG. I've simplify the clock config and tested the generic and it works with or without USB.
I've also added the Nucelo F412ZG variant.

@fpistm fpistm linked an issue May 16, 2023 that may be closed by this pull request
@fpistm
Copy link
Member

fpistm commented May 16, 2023

Fixes #1899

@fpistm fpistm merged commit 5c7107b into stm32duino:main May 16, 2023
22 checks passed
STM32 core based on ST HAL automation moved this from Reviewer approved to Done May 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

Stm32f412zg support
2 participants