Tutorial: Custom initialization

Custom MCU initialization

Instead of writing initial setting functions for each registers, you can call MCU_init() to call the commonly used default initialization.

Define this in ecSTM32F411.h.

void MCU_init(void){
    // CLOCK PLL 84MHz
    RCC_PLL_init();
    
    // SysTick 1msec
    SysTick_init();    
    
    // Button PC13
    GPIO_init(PC_13, INPUT);
    GPIO_pupd(PC_13, EC_PD);    
    
    // LED PA5
    GPIO_init(PA_5, OUTPUT);    

    // TIMx Default Initialization
    // ...
    // PWM Default Initialization
    // ...        
    // USART Default Initialization
    // ...
    // Others
}

In main source code,

#include “ecSTM32F411.h”	// includes all necessary library

// Initialization
void setup(){
	MCU_init();
	// Modify or Add more initializations
	// Modify or Add more initializations
}

// Main 
void main(){
	setup( );
	while(1){
	// polling logic goes here
	};
}

Examples of default initialization

Clock

  • PLL 84MHz

SysTick

  • tick period of 1msec

GPIO

  • Evaluation board Button : PC13

  • Evaluation board LED : PA5

TIMx

  • Timer2 Period: 1msec

  • Timer2 Interrupt: 1mec

Last updated