cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F407 clock setup using registers

rohitkumarkv07
Associate II

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.

8 REPLIES 8
rohitkumarkv07
Associate II
 
Andrew Neil
Evangelist III

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

 

 

#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.

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
		}
};

 

#include "Mcu.h"
#include "Mcu_Config.h"
#include "Mcu_Internal.h"
#include "Mcu_RegTypes.h"

Mcu_ConfigType* Mcu_pConfigPtr = NULL_PTR;

static FUNC(void, MCU_CODE) Mcu_Pwr_Init(VAR( void, AUTOMATIC));
static FUNC(void, MCU_CODE) Mcu_Flash_Init(VAR( void, AUTOMATIC));
static FUNC(void, MCU_CODE) Mcu_AllPeriphralReset(VAR( void, AUTOMATIC));
static FUNC(void, MCU_CODE) Mcu_AHB1Init(VAR( void, AUTOMATIC));
static FUNC(void, MCU_CODE) Mcu_AHB2Init(VAR( void, AUTOMATIC));
static FUNC(void, MCU_CODE) Mcu_AHB3Init(VAR( void, AUTOMATIC));
static FUNC(void, MCU_CODE) Mcu_APB1Init(VAR( void, AUTOMATIC));
static FUNC(void, MCU_CODE) Mcu_APB2Init(VAR( void, AUTOMATIC));

static FUNC(void, MCU_CODE) Mcu_Pwr_Init(VAR( void, AUTOMATIC))
{
	PwrConfigType* LpPwrConfigPtr;
	PWR_RegTypedef* LpPWR_Reg = PWR_REGADDRESS;

	LpPwrConfigPtr = Mcu_pConfigPtr->PWRConfgSet;
#if(MCU_VOS_SCALE_USED == STD_ON)
	LpPWR_Reg->CR |= LpPwrConfigPtr->PwrCRConfgVal.VOS;
#endif
#if(MCU_FPDS_USED == STD_ON)
	LpPWR_Reg->CR |= LpPwrConfigPtr->PwrCRConfgVal.FPDS;
#endif
#if(MCU_DBP_USED == STD_ON)
	LpPWR_Reg->CR |= LpPwrConfigPtr->PwrCRConfgVal.DBP;
#endif
#if(MCU_PLS_USED == STD_ON)
	LpPWR_Reg->CR |= LpPwrConfigPtr->PwrCRConfgVal.PLS;
#endif
#if(MCU_PVDE_USED == STD_ON)
	LpPWR_Reg->CR |= LpPwrConfigPtr->PwrCRConfgVal.PVDE;
#endif
#if(MCU_PDDS_USED == STD_ON)
	LpPWR_Reg->CR |= LpPwrConfigPtr->PwrCRConfgVal.PDDS;
#endif
#if(MCU_LPDS_USED == STD_ON)
	LpPWR_Reg->CR |= LpPwrConfigPtr->PwrCRConfgVal.LPDS;
#endif

#if(MCU_BRE_USED == STD_ON)
	LpPWR_Reg->CSR |= LpPwrConfigPtr->PwrCSRConfgVal.BRE;
#endif
#if(MCU_EWUP_USED == STD_ON)
	LpPWR_Reg->CSR |= LpPwrConfigPtr->PwrCSRConfgVal.EWUP;
#endif

}
static FUNC(void, MCU_CODE) Mcu_Flash_Init(VAR( void, AUTOMATIC))
{
	FLASHConfigType* LpFlashconfigPtr;
	FLASH_RegTypedef* LpFLASH_Reg = FLASH_REGADDRESS;
	LpFlashconfigPtr = Mcu_pConfigPtr->FlashConfgSet;
#if(MCU_DCRST_USED == STD_ON)
	LpFLASH_Reg->ACR |= LpFlashconfigPtr->FLASHACRConfgVal.DCRST;
#endif
#if(MCU_DCRST_USED == STD_ON)
	LpFLASH_Reg->ACR |= LpFlashconfigPtr->FLASHACRConfgVal.ICRST;
#endif
#if(MCU_DCRST_USED == STD_ON)
	LpFLASH_Reg->ACR |= LpFlashconfigPtr->FLASHACRConfgVal.LATENCY;
#endif
#if(MCU_DCRST_USED == STD_ON)
	LpFLASH_Reg->ACR |= LpFlashconfigPtr->FLASHACRConfgVal.DCEN;
#endif
#if(MCU_DCRST_USED == STD_ON)
	LpFLASH_Reg->ACR |= LpFlashconfigPtr->FLASHACRConfgVal.ICEN;
#endif
#if(MCU_DCRST_USED == STD_ON)
	LpFLASH_Reg->ACR |= LpFlashconfigPtr->FLASHACRConfgVal.PRFTEN;
#endif

}
static FUNC(void, MCU_CODE) Mcu_AllPeriphralReset(VAR( void, AUTOMATIC))
{
	RCC_RegTypedef* LpRCC_Reg = RCC_REGADDRESS;

	/*Reset the MCU Peripherals */
	LpRCC_Reg->AHB1RSTR =(uint32)(RCC_AHB1RSTR_RESET);
	LpRCC_Reg->AHB2RSTR =(uint32)(RCC_AHB2RSTR_RESET);
	LpRCC_Reg->AHB3RSTR =(uint32)(RCC_AHB3RSTR_RESET);
	LpRCC_Reg->APB1RSTR =(uint32)(RCC_APB1RSTR_RESET);
	LpRCC_Reg->APB2RSTR =(uint32)(RCC_APB2RSTR_RESET);
}
static FUNC(void, MCU_CODE) Mcu_AHB1Init(VAR( void, AUTOMATIC))
{
	McuClockConfigType* LpMcuClockConfigPtr;

	RCC_RegTypedef* LpRCC_Reg = RCC_REGADDRESS;

	LpMcuClockConfigPtr = Mcu_pConfigPtr->McuClockConfgSet;

	/*McuAHB1ENRConfgVal*/
#ifdef MCU_USB_OTG_USED
#if(OTGHSULPIEN_USED == STD_ON)
	LpRCC_Reg->AHB1ENR |= LpMcuClockConfigPtr->McuAHB1ENRConfgVal.OTGHSULPIEN;
#endif
#if(OTGHSEN_USED == STD_ON)
	LpRCC_Reg->AHB1ENR |= LpMcuClockConfigPtr->McuAHB1ENRConfgVal.OTGHSEN;
#endif
#endif

#ifdef MCU_ETHMAC_USED
#if(ETHMACPTPEN_USED == STD_ON)
	LpRCC_Reg->AHB1ENR |= LpMcuClockConfigPtr->McuAHB1ENRConfgVal.ETHMACPTPEN;
#endif
#if(ETHMACRXEN_USED == STD_ON)
	LpRCC_Reg->AHB1ENR |= LpMcuClockConfigPtr->McuAHB1ENRConfgVal.ETHMACRXEN;
#endif
#if(ETHMACTXEN_USED == STD_ON)
	LpRCC_Reg->AHB1ENR |= LpMcuClockConfigPtr->McuAHB1ENRConfgVal.ETHMACTXEN;
#endif
#if(ETHMACEN_USED == STD_ON)
	LpRCC_Reg->AHB1ENR |= LpMcuClockConfigPtr->McuAHB1ENRConfgVal.ETHMACEN;
#endif
#endif

#ifdef MCU_DMA_USED
#if(DMA2EN_USED == STD_ON)
	LpRCC_Reg->AHB1ENR |= LpMcuClockConfigPtr->McuAHB1ENRConfgVal.DMA2EN;
#endif
#if(DMA2EN_USED == STD_ON)
	LpRCC_Reg->AHB1ENR |= LpMcuClockConfigPtr->McuAHB1ENRConfgVal.DMA1EN;
#endif
#endif

#ifdef MCU_CCM_DATA_RAM_USED
#if(CCMDATARAMEN_USED == STD_ON)
	LpRCC_Reg->AHB1ENR |= LpMcuClockConfigPtr->McuAHB1ENRConfgVal.CCMDATARAMEN;
#endif
#endif

#ifdef MCU_BKP_SRAM_USED
#if(BKPSRAMEN_USED == STD_ON)
	LpRCC_Reg->AHB1ENR |= LpMcuClockConfigPtr->McuAHB1ENRConfgVal.BKPSRAMEN;
#endif
#endif

#ifdef MCU_CRC_USED
#if(CRCEN_USED == STD_ON)
	LpRCC_Reg->AHB1ENR |= LpMcuClockConfigPtr->McuAHB1ENRConfgVal.CRCEN;
#endif
#endif

#ifdef MCU_GPIO_USED
#if(GPIOIEN_USED == STD_ON)
	LpRCC_Reg->AHB1ENR |= LpMcuClockConfigPtr->McuAHB1ENRConfgVal.GPIOIEN;
#endif
#if(GPIOHEN_USED == STD_ON)
	LpRCC_Reg->AHB1ENR |= LpMcuClockConfigPtr->McuAHB1ENRConfgVal.GPIOHEN;
#endif
#if(GPIOGEN_USED == STD_ON)
	LpRCC_Reg->AHB1ENR |= LpMcuClockConfigPtr->McuAHB1ENRConfgVal.GPIOGEN;
#endif
#if(GPIOFEN_USED == STD_ON)
	LpRCC_Reg->AHB1ENR |= LpMcuClockConfigPtr->McuAHB1ENRConfgVal.GPIOFEN;
#endif
#if(GPIOEEN_USED == STD_ON)
	LpRCC_Reg->AHB1ENR |= LpMcuClockConfigPtr->McuAHB1ENRConfgVal.GPIOEEN;
#endif
#if(GPIODEN_USED == STD_ON)
	LpRCC_Reg->AHB1ENR |= LpMcuClockConfigPtr->McuAHB1ENRConfgVal.GPIODEN;
#endif
#if(GPIOCEN_USED == STD_ON)
	LpRCC_Reg->AHB1ENR |= LpMcuClockConfigPtr->McuAHB1ENRConfgVal.GPIOCEN;
#endif
#if(GPIOBEN_USED == STD_ON)
	LpRCC_Reg->AHB1ENR |= LpMcuClockConfigPtr->McuAHB1ENRConfgVal.GPIOBEN;
#endif
#if(GPIOAEN_USED == STD_ON)
	LpRCC_Reg->AHB1ENR |= LpMcuClockConfigPtr->McuAHB1ENRConfgVal.GPIOAEN;
#endif
#endif
}
static FUNC(void, MCU_CODE) Mcu_AHB2Init(VAR( void, AUTOMATIC))
{
	McuClockConfigType* LpMcuClockConfigPtr;

	RCC_RegTypedef* LpRCC_Reg = RCC_REGADDRESS;

	LpMcuClockConfigPtr = Mcu_pConfigPtr->McuClockConfgSet;

    /*McuAHB2ENRConfgVal*/
#if(OTGFSEN_USED == STD_ON)
	LpRCC_Reg->AHB2ENR |= LpMcuClockConfigPtr->McuAHB2ENRConfgVal.OTGFSEN;
#endif
#if(RNGEN_USED == STD_ON)
	LpRCC_Reg->AHB2ENR |= LpMcuClockConfigPtr->McuAHB2ENRConfgVal.RNGEN;
#endif
#if(HASHEN_USED == STD_ON)
	LpRCC_Reg->AHB2ENR |= LpMcuClockConfigPtr->McuAHB2ENRConfgVal.HASHEN;
#endif
#if(CRYPEN_USED == STD_ON)
	LpRCC_Reg->AHB2ENR |= LpMcuClockConfigPtr->McuAHB2ENRConfgVal.CRYPEN;
#endif
#if(DCMIEN_USED == STD_ON)
	LpRCC_Reg->AHB2ENR |= LpMcuClockConfigPtr->McuAHB2ENRConfgVal.DCMIEN;
#endif


}
static FUNC(void, MCU_CODE) Mcu_AHB3Init(VAR( void, AUTOMATIC))
{
	McuClockConfigType* LpMcuClockConfigPtr;

	RCC_RegTypedef* LpRCC_Reg = RCC_REGADDRESS;

	LpMcuClockConfigPtr = Mcu_pConfigPtr->McuClockConfgSet;

	/*McuAHB3ENRConfgVal*/
#if(DCMIEN_USED == STD_ON)
	LpRCC_Reg->AHB3ENR |= LpMcuClockConfigPtr->McuAHB3ENRConfgVal.FSMCEN;
#endif
}
static FUNC(void, MCU_CODE) Mcu_APB1Init(VAR( void, AUTOMATIC))
{
	McuClockConfigType* LpMcuClockConfigPtr;

	RCC_RegTypedef* LpRCC_Reg = RCC_REGADDRESS;

	LpMcuClockConfigPtr = Mcu_pConfigPtr->McuClockConfgSet;


	/*McuAPB1ENRConfgVal*/
#ifdef MCU_DAC_USED
#if(DACEN_USED == STD_ON)
	LpRCC_Reg->APB1ENR |= LpMcuClockConfigPtr->McuAPB1ENRConfgVal.DACEN;
#endif
#endif
#ifdef MCU_PWR_USED
#if(PWREN_USED == STD_ON)
	LpRCC_Reg->APB1ENR |= LpMcuClockConfigPtr->McuAPB1ENRConfgVal.PWREN;
#endif
#endif
#ifdef MCU_CAN_USED
#if(CAN2EN_USED == STD_ON)
	LpRCC_Reg->APB1ENR |= LpMcuClockConfigPtr->McuAPB1ENRConfgVal.CAN2EN;
#endif
#if(CAN1EN_USED == STD_ON)
	LpRCC_Reg->APB1ENR |= LpMcuClockConfigPtr->McuAPB1ENRConfgVal.CAN1EN;
#endif
#endif

#ifdef MCU_I2C_USED
#if(I2C3EN_USED == STD_ON)
	LpRCC_Reg->APB1ENR |= LpMcuClockConfigPtr->McuAPB1ENRConfgVal.I2C3EN;
#endif
#if(I2C2EN_USED == STD_ON)
	LpRCC_Reg->APB1ENR |= LpMcuClockConfigPtr->McuAPB1ENRConfgVal.I2C2EN;
#endif
#if(I2C1EN_USED == STD_ON)
	LpRCC_Reg->APB1ENR |= LpMcuClockConfigPtr->McuAPB1ENRConfgVal.I2C1EN;
#endif
#endif
#ifdef MCU_UART_USED
#if(UART5EN_USED == STD_ON)
	LpRCC_Reg->APB1ENR |= LpMcuClockConfigPtr->McuAPB1ENRConfgVal.UART5EN;
#endif
#if(UART4EN_USED == STD_ON)
	LpRCC_Reg->APB1ENR |= LpMcuClockConfigPtr->McuAPB1ENRConfgVal.UART4EN;
#endif
#endif
#ifdef MCU_USART_USED
#if(USART3EN_USED == STD_ON)
	LpRCC_Reg->APB1ENR |= LpMcuClockConfigPtr->McuAPB1ENRConfgVal.USART3EN;
#endif
#if(USART2EN_USED == STD_ON)
	LpRCC_Reg->APB1ENR |= LpMcuClockConfigPtr->McuAPB1ENRConfgVal.USART2EN;
#endif
#endif
#ifdef MCU_SPI_USED
#if(SPI3EN_USED == STD_ON)
	LpRCC_Reg->APB1ENR |= LpMcuClockConfigPtr->McuAPB1ENRConfgVal.SPI3EN;
#endif
#if(SPI2EN_USED == STD_ON)
	LpRCC_Reg->APB1ENR |= LpMcuClockConfigPtr->McuAPB1ENRConfgVal.SPI2EN;
#endif
#endif
#if(WWDGEN_USED == STD_ON)
	LpRCC_Reg->APB1ENR |= LpMcuClockConfigPtr->McuAPB1ENRConfgVal.WWDGEN;
#endif
#ifdef MCU_TIM_USED
#if(TIM14EN_USED == STD_ON)
	LpRCC_Reg->APB1ENR |= LpMcuClockConfigPtr->McuAPB1ENRConfgVal.UART4EN;
#endif
#if(TIM13EN_USED == STD_ON)
	LpRCC_Reg->APB1ENR |= LpMcuClockConfigPtr->McuAPB1ENRConfgVal.TIM13EN;
#endif
#if(TIM12EN_USED == STD_ON)
	LpRCC_Reg->APB1ENR |= LpMcuClockConfigPtr->McuAPB1ENRConfgVal.TIM12EN;
#endif
#if(TIM7EN_USED == STD_ON)
	LpRCC_Reg->APB1ENR |= LpMcuClockConfigPtr->McuAPB1ENRConfgVal.TIM7EN;
#endif
#if(TIM6EN_USED == STD_ON)
	LpRCC_Reg->APB1ENR |= LpMcuClockConfigPtr->McuAPB1ENRConfgVal.TIM6EN;
#endif
#if(TIM5EN_USED == STD_ON)
	LpRCC_Reg->APB1ENR |= LpMcuClockConfigPtr->McuAPB1ENRConfgVal.TIM5EN;
#endif
#if(TIM4EN_USED == STD_ON)
	LpRCC_Reg->APB1ENR |= LpMcuClockConfigPtr->McuAPB1ENRConfgVal.TIM4EN;
#endif
#if(TIM3EN_USED == STD_ON)
	LpRCC_Reg->APB1ENR |= LpMcuClockConfigPtr->McuAPB1ENRConfgVal.TIM3EN;
#endif
#if(TIM2EN_USED == STD_ON)
	LpRCC_Reg->APB1ENR |= LpMcuClockConfigPtr->McuAPB1ENRConfgVal.TIM2EN;
#endif
#endif

}
static FUNC(void, MCU_CODE) Mcu_APB2Init(VAR( void, AUTOMATIC))
{
	McuClockConfigType* LpMcuClockConfigPtr;

	RCC_RegTypedef* LpRCC_Reg = RCC_REGADDRESS;

	LpMcuClockConfigPtr = Mcu_pConfigPtr->McuClockConfgSet;


	/*McuAPB2ENRConfgVal*/
#ifdef MCU_TIM_USED
#if(TIM11EN_USED == STD_ON)
	LpRCC_Reg->APB2ENR |= LpMcuClockConfigPtr->McuAPB2ENRConfgVal.TIM11EN;
#endif
#if(TIM10EN_USED == STD_ON)
	LpRCC_Reg->APB2ENR |= LpMcuClockConfigPtr->McuAPB2ENRConfgVal.TIM10EN;
#endif
#if(TIM9EN_USED == STD_ON)
	LpRCC_Reg->APB2ENR |= LpMcuClockConfigPtr->McuAPB2ENRConfgVal.TIM9EN;
#endif
#endif
#if(SYSCFGEN_USED == STD_ON)
	LpRCC_Reg->APB2ENR |= LpMcuClockConfigPtr->McuAPB2ENRConfgVal.SYSCFGEN;
#endif
#if(SPI1EN_USED == STD_ON)
	LpRCC_Reg->APB2ENR |= LpMcuClockConfigPtr->McuAPB2ENRConfgVal.SPI1EN;
#endif
#if(SPI1EN_USED == STD_ON)
	LpRCC_Reg->APB2ENR |= LpMcuClockConfigPtr->McuAPB2ENRConfgVal.SDIOEN;
#endif
#ifdef MCU_ADC_USED
#if(ADC3EN_USED == STD_ON)
	LpRCC_Reg->APB2ENR |= LpMcuClockConfigPtr->McuAPB2ENRConfgVal.ADC3EN;
#endif
#if(ADC3EN_USED == STD_ON)
	LpRCC_Reg->APB2ENR |= LpMcuClockConfigPtr->McuAPB2ENRConfgVal.ADC2EN;
#endif
#if(ADC3EN_USED == STD_ON)
	LpRCC_Reg->APB2ENR |= LpMcuClockConfigPtr->McuAPB2ENRConfgVal.ADC1EN;
#endif
#endif
#ifdef MCU_USART_USED
#if(USART6EN_USED == STD_ON)
	LpRCC_Reg->APB2ENR |= LpMcuClockConfigPtr->McuAPB2ENRConfgVal.USART6EN;
#endif
#if(USART5EN_USED == STD_ON)
	LpRCC_Reg->APB2ENR |= LpMcuClockConfigPtr->McuAPB2ENRConfgVal.USART1EN;
#endif
#endif
#ifdef MCU_TIM_USED
#if(TIM8EN_USED == STD_ON)
	LpRCC_Reg->APB2ENR |= LpMcuClockConfigPtr->McuAPB2ENRConfgVal.TIM8EN;
#endif
#if(TIM1EN_USED == STD_ON)
	LpRCC_Reg->APB2ENR |= LpMcuClockConfigPtr->McuAPB2ENRConfgVal.TIM1EN;
#endif
#endif
}

FUNC(void, MCU_CODE) Mcu_Init( Mcu_ConfigType* pConfigPtr)
{
	Mcu_pConfigPtr = pConfigPtr;

	Mcu_Pwr_Init();
	Mcu_Flash_Init();
	Mcu_AllPeriphralReset();
	Mcu_AHB1Init();
	Mcu_AHB2Init();
	Mcu_AHB3Init();
	Mcu_APB1Init();
	Mcu_APB2Init();
}

FUNC( Std_ReturnType, MCU_CODE) Mcu_InitClock( VAR( uint8, AUTOMATIC) ClockSetting)
{
	McuClockConfigType* LpMcuClockConfigPtr;
	RCC_RegTypedef* LpRCC_Reg = RCC_REGADDRESS;
	LpMcuClockConfigPtr = Mcu_pConfigPtr->McuClockConfgSet;
	//uint32 LddHSERdyBitVal = (uint32)0x00000000UL;



	LpRCC_Reg->CR |= LpMcuClockConfigPtr->McuCRConfgVal.HSEON;

	while(!LpRCC_Reg->CR)
	LpRCC_Reg->CR |= LpMcuClockConfigPtr->McuCRConfgVal.PLLON;


	LpRCC_Reg->PLLCFGR |= LpMcuClockConfigPtr->McuPLLCFGRConfgVal.PLLM;
	LpRCC_Reg->PLLCFGR |= LpMcuClockConfigPtr->McuPLLCFGRConfgVal.PLLN;
	LpRCC_Reg->PLLCFGR |= LpMcuClockConfigPtr->McuPLLCFGRConfgVal.PLLP;
	LpRCC_Reg->PLLCFGR |= LpMcuClockConfigPtr->McuPLLCFGRConfgVal.PLLSRC;
	LpRCC_Reg->PLLCFGR |= LpMcuClockConfigPtr->McuPLLCFGRConfgVal.PLLQ;



	LpRCC_Reg->CFGR |= LpMcuClockConfigPtr->McuCFGRConfgVal.HPRE;
	LpRCC_Reg->CFGR |= LpMcuClockConfigPtr->McuCFGRConfgVal.PPRE1;
	LpRCC_Reg->CFGR |= LpMcuClockConfigPtr->McuCFGRConfgVal.PPRE2;
	LpRCC_Reg->CFGR |= LpMcuClockConfigPtr->McuCFGRConfgVal.SW;
	LpRCC_Reg->CFGR |= LpMcuClockConfigPtr->McuCFGRConfgVal.MCO2;
	LpRCC_Reg->CFGR |= LpMcuClockConfigPtr->McuCFGRConfgVal.MCO2PRE;
	LpRCC_Reg->CFGR |= LpMcuClockConfigPtr->McuCFGRConfgVal.MCO1PRE;
	LpRCC_Reg->CFGR |= LpMcuClockConfigPtr->McuCFGRConfgVal.I2SSRC;
	LpRCC_Reg->CFGR |= LpMcuClockConfigPtr->McuCFGRConfgVal.MCO1;
	LpRCC_Reg->CFGR |= LpMcuClockConfigPtr->McuCFGRConfgVal.RTCPRE;

	LpRCC_Reg->CIR|=LpMcuClockConfigPtr->McuCIRConfgVal.PLLI2SRDYIE;
	LpRCC_Reg->CIR|=LpMcuClockConfigPtr->McuCIRConfgVal.PLLRDYIE;
	LpRCC_Reg->CIR|=LpMcuClockConfigPtr->McuCIRConfgVal.HSERDYIE;
	LpRCC_Reg->CIR|=LpMcuClockConfigPtr->McuCIRConfgVal.HSIRDYIE;
	LpRCC_Reg->CIR|=LpMcuClockConfigPtr->McuCIRConfgVal.LSERDYIE;
	LpRCC_Reg->CIR|=LpMcuClockConfigPtr->McuCIRConfgVal.LSIRDYIE;
#if 0
	LpRCC_Reg->BDCR = LpMcuClockConfigPtr->McuBDCRConfgVal.BDRST;
	LpRCC_Reg->BDCR = LpMcuClockConfigPtr->McuBDCRConfgVal.RTCEN;
	LpRCC_Reg->BDCR = LpMcuClockConfigPtr->McuBDCRConfgVal.RTCSEL;
	LpRCC_Reg->BDCR = LpMcuClockConfigPtr->McuBDCRConfgVal.LSEBYP;
	LpRCC_Reg->BDCR = LpMcuClockConfigPtr->McuBDCRConfgVal.LSEON;
	LpRCC_Reg->CSR = LpMcuClockConfigPtr->McuCSRConfgVal.LSION;
	LpRCC_Reg->SSCGR = LpMcuClockConfigPtr->McuSSCGRConfgVal.SSCGEN;
	LpRCC_Reg->SSCGR = LpMcuClockConfigPtr->McuSSCGRConfgVal.SPREADSEL;
	LpRCC_Reg->SSCGR = LpMcuClockConfigPtr->McuSSCGRConfgVal.INCSTEP;
	LpRCC_Reg->SSCGR = LpMcuClockConfigPtr->McuSSCGRConfgVal.MODPER;
	LpRCC_Reg->PLLI2SCFGR = LpMcuClockConfigPtr->McuPLLI2SCFGRConfgVal.PLLI2SR;
	LpRCC_Reg->PLLI2SCFGR = LpMcuClockConfigPtr->McuPLLI2SCFGRConfgVal.PLLI2SN;
#endif
	return E_OK;
}
/*
FUNC(Mcu_ResetType, MCU_CODE) Mcu_GetResetReason(VAR( void, AUTOMATIC))
{
	McuClockConfigType* LpMcuClockConfigPtr;
	RCC_RegTypedef* LpRCC_Reg = RCC_REGADDRESS;
	LpMcuClockConfigPtr = Mcu_pConfigPtr->McuClockConfgSet;

	VAR(Mcu_ResetType, AUTOMATIC) eResetReason;
    eResetReason = (uint32)LpRCC_Reg->CSR;

    return (Mcu_ResetType)eResetReason;

}*/




Here is my mcu_init and mcu_initclock

Not sure that all these partial writes (read-modify-writes) are a good idea?

	LpRCC_Reg->PLLCFGR |= LpMcuClockConfigPtr->McuPLLCFGRConfgVal.PLLM;
	LpRCC_Reg->PLLCFGR |= LpMcuClockConfigPtr->McuPLLCFGRConfgVal.PLLN;
	LpRCC_Reg->PLLCFGR |= LpMcuClockConfigPtr->McuPLLCFGRConfgVal.PLLP;
	LpRCC_Reg->PLLCFGR |= LpMcuClockConfigPtr->McuPLLCFGRConfgVal.PLLSRC;
	LpRCC_Reg->PLLCFGR |= LpMcuClockConfigPtr->McuPLLCFGRConfgVal.PLLQ;

 

Why not make it just a single write, with the value you require?

LpRCC_Reg->PLLCFGR = LpMcuClockConfigPtr->McuPLLCFGRConfgVal.PLLM |
	LpMcuClockConfigPtr->McuPLLCFGRConfgVal.PLLN    |
	LpMcuClockConfigPtr->McuPLLCFGRConfgVal.PLLP    |
	LpMcuClockConfigPtr->McuPLLCFGRConfgVal.PLLSRC  |
	LpMcuClockConfigPtr->McuPLLCFGRConfgVal.PLLQ;

etc.

Or could you not just make you McuPLLCFGRConfgVal directly compatible with the register, then do

	LpRCC_Reg->PLLCFGR = LpMcuClockConfigPtr->McuPLLCFGRConfgVal;

@rohitkumarkv07 wrote:

 

static FUNC(void, MCU_CODE) Mcu_Pwr_Init(VAR( void, AUTOMATIC));
static FUNC(void, MCU_CODE) Mcu_Flash_Init(VAR( void, AUTOMATIC));
static FUNC(void, MCU_CODE) Mcu_AllPeriphralReset(VAR( void, AUTOMATIC));
static FUNC(void, MCU_CODE) Mcu_AHB1Init(VAR( void, AUTOMATIC));
static FUNC(void, MCU_CODE) Mcu_AHB2Init(VAR( void, AUTOMATIC));
static FUNC(void, MCU_CODE) Mcu_AHB3Init(VAR( void, AUTOMATIC));
static FUNC(void, MCU_CODE) Mcu_APB1Init(VAR( void, AUTOMATIC));
static FUNC(void, MCU_CODE) Mcu_APB2Init(VAR( void, AUTOMATIC));

 

 


Presumably FUNC, MCU_CODE, VAR, and AUTOMATIC are all macros here?

What do they do?

I am just following the autosar standards here. I am enabling the PWREN register of APB1, but the ETHMACPTEN register got updated in the SFRs window. Could you please help me out.