Skip to main content
Explorer
September 14, 2025
Solved

Problem with HSE and XSPI2 on STM32N657

  • September 14, 2025
  • 2 replies
  • 488 views

In this example, if instead of using HSI I enable HSE, I can’t get memory-mapped mode working on XSPI2.

Baord I am using is NUCLEO-N657X0-Q-C01

I replaced this function
https://github.com/stm32-hotspot/STM32N6_FSBL_Modes/blob/main/LoadAndRun/FSBL/Core/Src/main.c#L119-L198

with my SystemClock_Config 

SystemClock_Config(void) {
 RCC_OscInitTypeDef RCC_OscInitStruct = {0};
 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

 /** Configure the System Power Supply
 */
 if (HAL_PWREx_ConfigSupply(PWR_EXTERNAL_SOURCE_SUPPLY) != HAL_OK) {
 Error_Handler();
 }

 /* Enable HSI */
 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
 RCC_OscInitStruct.HSIState = RCC_HSI_ON;
 RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1;
 RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
 RCC_OscInitStruct.PLL1.PLLState = RCC_PLL_NONE;
 RCC_OscInitStruct.PLL2.PLLState = RCC_PLL_NONE;
 RCC_OscInitStruct.PLL3.PLLState = RCC_PLL_NONE;
 RCC_OscInitStruct.PLL4.PLLState = RCC_PLL_NONE;
 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
 Error_Handler();
 }

 /* Wait HSE stabilization time before its selection as PLL source. */
 HAL_Delay(HSE_STARTUP_TIMEOUT);

 /** Get current CPU/System buses clocks configuration and if necessary switch
 to intermediate HSI clock to ensure target clock can be set
 */
 HAL_RCC_GetClockConfig(&RCC_ClkInitStruct);
 if ((RCC_ClkInitStruct.CPUCLKSource == RCC_CPUCLKSOURCE_IC1) ||
 (RCC_ClkInitStruct.SYSCLKSource == RCC_SYSCLKSOURCE_IC2_IC6_IC11)) {
 RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_CPUCLK | RCC_CLOCKTYPE_SYSCLK);
 RCC_ClkInitStruct.CPUCLKSource = RCC_CPUCLKSOURCE_HSI;
 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct) != HAL_OK) {
 /* Initialization Error */
 Error_Handler();
 }
 }

 /** Initializes the RCC Oscillators according to the specified parameters
 * in the RCC_OscInitTypeDef structure.
 */
 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
 RCC_OscInitStruct.HSEState = RCC_HSE_ON;
 RCC_OscInitStruct.PLL1.PLLState = RCC_PLL_ON;
 RCC_OscInitStruct.PLL1.PLLSource = RCC_PLLSOURCE_HSE;
 RCC_OscInitStruct.PLL1.PLLM = 1;
 RCC_OscInitStruct.PLL1.PLLN = 50;
 RCC_OscInitStruct.PLL1.PLLFractional = 0;
 RCC_OscInitStruct.PLL1.PLLP1 = 1;
 RCC_OscInitStruct.PLL1.PLLP2 = 1;
 RCC_OscInitStruct.PLL2.PLLState = RCC_PLL_NONE;
 RCC_OscInitStruct.PLL3.PLLState = RCC_PLL_NONE;
 RCC_OscInitStruct.PLL4.PLLState = RCC_PLL_NONE;
 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
 Error_Handler();
 }

 /** Initializes the CPU, AHB and APB buses clocks
 */
 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_CPUCLK | RCC_CLOCKTYPE_HCLK
 | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1
 | RCC_CLOCKTYPE_PCLK2 | RCC_CLOCKTYPE_PCLK5
 | RCC_CLOCKTYPE_PCLK4;
 RCC_ClkInitStruct.CPUCLKSource = RCC_CPUCLKSOURCE_IC1;
 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_IC2_IC6_IC11;
 RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV2;
 RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV1;
 RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV1;
 RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV1;
 RCC_ClkInitStruct.APB5CLKDivider = RCC_APB5_DIV1;
 RCC_ClkInitStruct.IC1Selection.ClockSelection = RCC_ICCLKSOURCE_PLL1;
 RCC_ClkInitStruct.IC1Selection.ClockDivider = 3;
 RCC_ClkInitStruct.IC2Selection.ClockSelection = RCC_ICCLKSOURCE_PLL1;
 RCC_ClkInitStruct.IC2Selection.ClockDivider = 6;
 RCC_ClkInitStruct.IC6Selection.ClockSelection = RCC_ICCLKSOURCE_PLL1;
 RCC_ClkInitStruct.IC6Selection.ClockDivider = 4;
 RCC_ClkInitStruct.IC11Selection.ClockSelection = RCC_ICCLKSOURCE_PLL1;
 RCC_ClkInitStruct.IC11Selection.ClockDivider = 3;

 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct) != HAL_OK) {
 Error_Handler();
 }
 PeriphClkInitStruct.ICSelection[RCC_IC3].ClockDivider = 48;



In comparison original clock is setup like this:

IgorMisic_0-1757849993840.png


To new one:

IgorMisic_1-1757850078383.png

 

As it can be seen both IC3 clocks are 50 MHz.

With original setup I see this on 0x7000000 address:

IgorMisic_3-1757854488071.png

With HSE enabled I got this:

IgorMisic_2-1757850327379.png


What could be wrong?



    This topic has been closed for replies.
    Best answer by IgorMisic

    I eventually solved it by replacing the drivers and middleware of the project  with the latest version.

    Link to code: https://github.com/IMProject/IMBootloader/pull/39

     

    2 replies

    Super User
    September 14, 2025

    i dont think, changing to HSE as clock source doing something "strange".

    But to compare, all clocks+PLL setting have to be same, so adjust it and then try again.

    sys not same, maybe others also:

    AScha3_0-1757855871357.png

    vs

    AScha3_1-1757855904562.png

    +

    Just set the clock tree in Cube , with HSE as source; then try.

    IgorMisicAuthor
    Explorer
    September 14, 2025

    I used CubeMX just to show that the clock for IC3 is the same in both cases. I don’t use it to generate the code, as you can see from the code I pasted.

    IgorMisicAuthor
    Explorer
    September 14, 2025

    In addition, this is the code where I am trying to enable memory-mapped mode for the MX25UM51245G on XSPI2. It has HSE enabled and working.
    https://github.com/IMProject/IMBootloader/blob/master/Bootloader/Adapters/Src/system_clock_adapter.c#L191-L275

    Since I was unable to do it, I tested this example that has working HSI + XSPI2. Then I tried to enable HSE + XSPI2, without success. 
    https://github.com/stm32-hotspot/STM32N6_FSBL_Modes/blob/main/LoadAndRun/FSBL/Core/Src/main.c#L119-L198

    IgorMisicAuthorAnswer
    Explorer
    September 16, 2025

    I eventually solved it by replacing the drivers and middleware of the project  with the latest version.

    Link to code: https://github.com/IMProject/IMBootloader/pull/39