2025-01-09 02:44 AM - edited 2025-01-09 02:46 AM
Hello,
I am trying to output the HSE to a GPIO PA8.
I want to do it from scratch and have added this code to the HID example from ST.
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN; // Enable GPIOA clock
GPIOA->MODER &= ~GPIO_MODER_MODE8; // Clear the mode bits for PA8
GPIOA->MODER |= GPIO_MODER_MODE8_1; // Set PA8 as alternate function
GPIOA->AFR[1] &= ~GPIO_AFRH_AFSEL8; // Clear AF selection for PA8
GPIOA->AFR[1] |= (0x00 << GPIO_AFRH_AFSEL8_Pos); // Set PA8 to AF0 (MCO1)
RCC->CFGR &= ~RCC_CFGR_MCO1; // Clear the MCO1 source
//Choose Source
RCC->CFGR |= RCC_CFGR_MCO1_0; // Select HSE as MCO1 source
RCC->CFGR &= ~RCC_CFGR_MCO1PRE; // Clear the MCO1 prescaler bits
RCC->CFGR |= RCC_CFGR_MCO1PRE; // Set MCO1PRE bits to 010 for division by 5
The code works only for HSI and PLL ( confirmed with an oscilloscope).
What could be causing HSE not to be outputted ?
I tried with and without the prescaler enabled.
I am also attaching the whole project file.
Solved! Go to Solution.
2025-01-09 09:49 AM
And this is exactly the non-systemic naming I've talked about above, not to mention the shifted value which as I explained above is improper.
Also, some of the Cube/HAL symbols are NOT what you'd expect, e.g. including not only values for given bitfield but also markers for Cube/HAL's internal use.
So, I keep insisting on that Cube/HAL symbols are NOT to be used generally, outside Cube/HAL.
JW