Exemple #1
0
void init(void){
// reset & clock configure
	init_RCC();

// set vector table
#ifdef VECTOR_ON_SRAM
	SCB->VTOR = SRAM_BASE;	// vector table from top of SRAM
#else
	SCB->VTOR = FLASH_BASE;	// vector table from top of FLASH
#endif

// .data and .bss,.COMM area initializing
	memmove(_sdata, _sidata, _edata - _sdata);	// set initial values onto .data 
	memset(_sbss, 0, _ebss - _sbss);	// clear .bss, .COMM

//
// GPIOD configure
// LED_15=BL,14=RE,13=OR,12=GR is output
//
	GPIOD->MODER = (GPIO_MODER_MODER15_0 | GPIO_MODER_MODER14_0 | GPIO_MODER_MODER13_0 | GPIO_MODER_MODER12_0);
	GPIOD->ODR = 0;

//
// set up sysTick facility
// 10ms ごとにsysTickイベントを発生させる
//
#define user_SysTick_CTRL (SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk)
	SysTick->LOAD= (10 * (SysClock / 1000)) - 1; // SysTick event every a ten milli-seconds
	SysTick->CTRL= user_SysTick_CTRL;
}
Exemple #2
0
void init(void){
// reset & clock configure
	init_RCC();

// set vector table
#ifdef VECTOR_ON_SRAM
	SCB->VTOR = SRAM_BASE;	// vector table from top of SRAM
#else
	SCB->VTOR = FLASH_BASE;	// vector table from top of FLASH
#endif

// .data and .bss,.COMM area initializing
	memmove(_sdata, _sidata, _edata - _sdata);	// set initial values onto .data 
	memset(_sbss, 0, _ebss - _sbss);	// clear .bss, .COMM


//
// GPIOD configure
	GPIOD->PUPDR = 0x00aaa2aa; // GPIOD_11..0:input_PullDown(except PD5)
#ifdef SOFT_PWM
// GPIOD_15=BL,14=RE,13=OR,12=GR is output mode
// default I/O_LEVEL=L
	GPIOD->MODER = (GPIO_MODER_MODER15_0 | GPIO_MODER_MODER14_0 | GPIO_MODER_MODER13_0 | GPIO_MODER_MODER12_0);
	GPIOD->ODR = 0;
#else
// GPIOD_15..12 set alternate function mode (TIM4 = AF2)
	GPIOD->MODER = (GPIO_MODER_MODER15_1 | GPIO_MODER_MODER14_1 | GPIO_MODER_MODER13_1 | GPIO_MODER_MODER12_1);
	GPIOD->AFR[1]= 0x22220000; // DPIOD_15..12 as TIM4_CH4..CH1
#endif /* SOFT_PWM */

//
// TIM4 configure
// TIM4_CH4=BL,3=RE,2=OR,1=GR is output PWM-edgeAlign mode
//
#define	default_TIMx_CR1	(0)
#define	default_TIMx_CR2	(0)
#define	CCER_SET(x) 1<<(4*(x))
TIM4->CR1= default_TIMx_CR1; // reset value
TIM4->CR2= default_TIMx_CR2; // reset value

TIM4->ARR= 255; // auto reload 255 as like a 8bit-timer :)
TIM4->CCR1= TIM4->CCR2= TIM4->CCR3= TIM4->CCR4= 0; // clear compair value(PWM OFF)
TIM4->CCER=  TIM_CCER_CC4E | TIM_CCER_CC3E | TIM_CCER_CC2E | TIM_CCER_CC1E; // enable output all channels
TIM4->CCMR1= TIM_CCMR1_OC2M_2 | TIM_CCMR1_OC2M_1 | TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_1;
TIM4->CCMR2= TIM_CCMR2_OC4M_2 | TIM_CCMR2_OC4M_1 | TIM_CCMR2_OC3M_2 | TIM_CCMR2_OC3M_1;
TIM4->CNT= 0;
TIM4->SR=  0;
TIM4->CR1= TIM_CR1_CEN; // f/1,PWM-edgeAligned,upcount,countEnable
TIM4->BDTR = TIM_BDTR_MOE;
//
// set up sysTick facility
// 10ms ごとにsysTickイベントを発生させる
//
#define user_SysTick_CTRL (SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk)
	SysTick->LOAD= (10 * (SysClock / 1000)) - 1; // SysTick event every a ten milli-seconds
	SysTick->CTRL= user_SysTick_CTRL;
}