Beispiel #1
0
void config( void )
{
	config_clocks();
	config_sysclock();
	configure_constants();
	config_GPIOs();
	config_timers();
	config_USB();
	config_DMA();
	config_ADC();
}
int main(void)
{
	config_clocks();
	config_gpio();
	scheduler_init();

	/* Start running the tasks. This call will never return. */
	scheduler_yield();

	return 0;
}
Beispiel #3
0
int main(void)
{
	uint32_t i = 0;
	config_clocks();
    /* Write your code here */
	/* Enable Port B */
	SIM->SCGC5 |= SIM_SCGC5_PORTB_MASK;
	SIM->SCGC5 |= SIM_SCGC5_PORTA_MASK;
	SIM->SCGC4 |= 1 << 22;
	config_spi();

	PORTA_PCR8 |= PORT_PCR_MUX(3);
	PORTA_PCR9 |= PORT_PCR_MUX(3);
	GPIOA_PDDR |= (1 << SWD_CLK_PIN);// /*(1 << SWD_IO_PIN) |*/ (1 << 12);
	GPIOA_PCOR = 1 << SWD_CLK_PIN; // Make sure the clock is low when shifting to GPIO
#ifdef _DEBUG
	config_uart();
#endif
	/* Enable RED LED as GPIO */
	PORTB_PCR10 |= PORT_PCR_MUX(1);
	/* Set PTB10, PTB11 and PTB13 as outputs */
	GPIOB_PDDR |= 1 << 10;

	/* Turn off LEDs */
	GPIOB_PSOR = 1 << 10;

	uint32_t data = 0x12345678;
	uint8_t ret = 0;
	// Reset the bus and confirm the target is configured
	reset_and_power_debug();

	swd_write(false, DB_REG_SELECT, 0x01000000);
	swd_write(true, MDM_REG_CTL, 0x4);
	swd_read(true, MDM_REG_STAT, &data);
	swd_read(false, DB_REG_RD_BUFF, &data);
	swd_write(false, DB_REG_SELECT, 0x00);
	swd_write(true, AP_REG_CSW, 0x03000042);
	swd_read(true, AP_REG_CSW, &data);
	swd_read(false, DB_REG_RD_BUFF, &data);

	swd_write_mem((uint32_t)&(CoreDebug->DHCSR), 0xA05F0003);

	swd_write_array(SRAM_START,blink_code,blink_code_len);

	swd_write_reg(0xF,SRAM_START);
	swd_write_reg(0xE,SRAM_START+1);

	swd_write_mem((uint32_t)&(CoreDebug->DHCSR), 0xA05F0000);

//	takeover_and_inject();

    while(1){
    	/* Turn on RED LED */
    	GPIOB_PCOR = 1 << 10;
    	for(i = 0; i < delay; i++); /* delay */
    	/* Turn off RED LED */
    	GPIOB_PSOR = 1 << 10;
    	for(i = 0; i < delay; i++); /* delay */

//    	/* Turn on GREEN LED */
//    	GPIOB_PCOR = 1 << 11;
//    	for(i = 0; i < delay; i++); /* delay */
//    	/* Turn off GREEN LED */
//    	GPIOB_PSOR = 1 << 11;
//    	for(i = 0; i < delay; i++); /* delay */
//
//    	/* Turn on BLUE LED */
//    	GPIOB_PCOR = 1 << 13;
//    	for(i = 0; i < delay; i++); /* delay */
//    	/* Turn off BLUE LED */
//    	GPIOB_PSOR = 1 << 13;
//    	for(i = 0; i < delay; i++); /* delay */

////		ret = swd_write(true,AP_REG_DRW,0xFFFF);
////		ret = swd_read(false,DB_REG_CTRL_STAT,&data);
//    	swd_read(false,0x00,&data);
//    	data++;
    	if (!(GPIOB_PDIR & (1 << 5))) {
    		GPIOB_PCOR = 1 << 10 | 1 << 11 | 1 << 12;
        	for(i = 0; i < delay; i++); /* delay */

    		GPIOB_PSOR = 1 << 10 | 1 << 11 | 1 << 12;
        	for(i = 0; i < delay; i++); /* delay */
    	}
    }
    /* Never leave main */
    return 0;
}