Skip to main content
Associate III
Apr 17, 2024 7:57 AM UTC
Question

STM32F407 clock setup using registers

Hello, 

I ty to configure the clock setup of stm32f407 board using registers .

But I am not getting the values of Registers in the SFR while debugging.

Since I am enabling the GPIOD in the AHB1ENR registers but still I am not getting the value during the debug.

This topic has been closed for replies.

8 replies

Associate III
Apr 17, 2024 7:58 AM UTC

..

Andrew Neil
Super User
Apr 17, 2024 8:00 AM UTC

Try using CubeMX to generate the setup you require, then extract the register values from that.

 

Please use this button to properly post source code:

AndrewNeil_0-1713340992769.png

 

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Associate III
Apr 17, 2024 8:09 AM UTC
#include "Mcu.h"
#include"stm32f407xx.h"
int main()
{


	Mcu_Init(&Mcu_ConfigSet[0]);
	Mcu_InitClock(0);
	Mcu_Init(&Mcu_ConfigSet[0]);
	while(1)
	{
		;
	}
}
#include <Mcu_Internal.h>



PwrConfigType PWR_ConfigSet[1] =
{
		{
				/*PwrCRConfgVal*/
				{
						VOS_SCALE_1 ,
						FPDS_NOT_POWER_DOWN ,
						DBP_DISABLED,
						PLS20V ,
						PVDE_DISABLED ,
						PDDS_STOP_MODE ,
						LPDS_STOP_MODE,
				},

				/*PwrCSRConfgVal*/
				{
						BRE_DISABLED ,
						EWUP_NOT_WAKEUP,
				}
		}
};

FLASHConfigType FLASH_ConfigSet[1]=
{
		{
				/*FLASHACRConfgVal*/
				{
						DCRST_NOT_RESET ,
						ICRST_NOT_RESET,
						LATENCY_FIVE_STATE,
						DCEN_ENABLED,
						ICEN_ENABLED,
						PRFTEN_ENABLED,
				}
		}
};

McuClockConfigType Mcu_ClockConfigSet[1] =
{
		/*Mcu_ClockConfigSet-1*/
		{
				/*McuCRConfgVal*/
				{
						/*HSION */
						HSION_OFF,
						/*HSITRIM */
						HSITRIM,
						/*HSEON */
						HSE_ON,
						/*HSEBYP */
						HSEBYP_OFF,
						/*CSSON */
						CSS_OFF,
						/*PLLON */
						PLL_ON,
						/*PLLI2SON */
						PLLI2S_OFF,

				},
				/*McuPLLCFGRConfgVal*/
				{

						/*PLLM*/
						PLLM_8,
						/*PLLN*/
						PLLN_336,
						/*PLLP*/
						PLLP_2,
						/*PLLSRC_HSE*/
						PLLSRC_HSE,
						/*PLLQ*/
						PLLQ_7,

				},

				/*McuCFGRConfgVal*/
				{
						PRE2_AHB_2,
						PRE1_AHB_4,
						HRPE_SYSCLK_1,
						SW_PLL ,
						MCO2_SYSCLK,
					 MCO2PRE_2 ,
						MCO1PRE_2 ,
						I2SSRC_PLL ,
						MCO1_HSE ,
			 		RTC_PREHSE_1,
				},


				/*McuCIRConfgVal*/
				{
						PLLI2SRDYIELI_DISABLED,
						PLLRDYIELI_DISABLED ,
						HSERDYIEI_DISABLED ,
						HSIRDYIEI_DISABLED ,
						LSERDYIEI_DISABLED ,
						LSIRDYIEI_DISABLED,

				},
				/*McuAHB1ENRConfgVal*/
				{
						OTGHSULPIEN_DISABLED,
						OTGHSEN_DISABLED,
						ETHMACPTPEN_DISABLED,
						ETHMACRXEN_DISABLED,
						ETHMACTXEN_DISABLED,
						ETHMACEN_DISABLED,
						DMA2EN_DISABLED,
						DMA1EN_DISABLED,
						CCMDATARAMEN_DISABLED,
						BKPSRAMEN_DISABLED,
						CRCEN_DISABLED,
						GPIOIEN_DISABLED,
						GPIOHEN_DISABLED,
						GPIOGEN_DISABLED,
						GPIOFEN_DISABLED,
						GPIOEEN_DISABLED,
						GPIODEN_ENABLED,
						GPIOCEN_DISABLED,
						GPIOBEN_DISABLED,
						GPIOAEN_DISABLED
				},
				/*McuAHB2ENRConfgVal*/
				{
						OTGFSEN_DISABLED,
						RNGEN_DISABLED,
						HASHEN_DISABLED,
						CRYPEN_DISABLED,
						DCMIEN_DISABLED,
				},
				/*McuAPB3ENRConfgVal*/
				{
						FSMCEN_DISABLED,
				},
				/*McuAPB1ENRConfgVal*/
				{
						DACEN_DISABLED,
						PWREN_ENABLED,
						CAN2EN_DISABLED,
						CAN1EN_DISABLED,
						I2C3EN_DISABLED,
						I2C2EN_DISABLED,
						I2C1EN_DISABLED,
						UART5EN_DISABLED,
						UART4EN_DISABLED,
						USART3EN_DISABLED,
						USART2EN_DISABLED,
						SPI3EN_DISABLED,
						SPI2EN_DISABLED,
						WWDGEN_DISABLED,
						TIM14EN_DISABLED,
						TIM13EN_DISABLED,
						TIM12EN_DISABLED,
						TIM7EN_DISABLED,
						TIM6EN_DISABLED,
						TIM5EN_DISABLED,
						TIM4EN_DISABLED,
						TIM3EN_DISABLED,
						TIM2EN_ENABLED,
				},
				/*McuAPB2ENRConfgVal*/
				{
						TIM11EN_DISABLED,
						TIM10EN_DISABLED,
						TIM9EN_DISABLED,
						SYSCFGEN_DISABLED,
						SPI1EN_DISABLED,
						SDIOEN_DISABLED,
						ADC3EN_DISABLED,
						ADC2EN_DISABLED,
						ADC1EN_DISABLED,
						USART6EN_DISABLED,
						USART1EN_DISABLED,
						TIM8EN_DISABLED,
						TIM1EN_DISABLED,
				},
				/*McuBDCRConfgVal*/
				{

						BDRST_RESET_NOTACTIVATED ,
						RTCEN_CLOCK_DISABLED ,
						RTCSEL_NO ,
						LSEBYP_NOT_BYPASSED ,
						LSEON_OFF,

				},
				/*McuCSRConfgVal*/
				{
						LSION_OFF,
				},
				/*McuSSCGRConfgVal*/
				{

						SSCGEN_DISABLE,
						SPREADSEL_CENTRE,

				},
				/*McuPLLI2SCFGRConfgVal*/
				{

						PLLI2SR2 ,
						PLLI2SN0,

				},
		}

};


Mcu_ConfigType Mcu_ConfigSet[1]=
{
		{
				&PWR_ConfigSet[0],

				&Mcu_ClockConfigSet[0],

				&FLASH_ConfigSet[0]
		}
};

 

This is my code for stm32f407 board for the clock setup using registers. can you look at this and help me with this.

Andrew Neil
Super User
Apr 17, 2024 8:18 AM UTC

You haven't showed the code for your Mcu_InitClock() function.

Again, why not create a working setup using CubeMX - then take the required settings from that?

Then debug your code against the Cube code.

Just on a question of style why:

Mcu_ConfigType Mcu_ConfigSet[1]=
{
		{
				&PWR_ConfigSet[0],
				&Mcu_ClockConfigSet[0],
				&FLASH_ConfigSet[0]
		}
};

instead of just

Mcu_ConfigType Mcu_ConfigSet[1]=
{
		{
				PWR_ConfigSet,
				Mcu_ClockConfigSet,
				FLASH_ConfigSet
		}
};

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.