/*********************************************************************//**
 * @brief 		Initial System Tick with Config
 * @param[in]	None
 * @return 		None
 **********************************************************************/
void SYSTICK_Config(void)
{
  //Initialize System Tick with 10ms time interval
  SYSTICK_InternalInit(1);
  //Enable System Tick interrupt
  SYSTICK_IntCmd(ENABLE);
  //Enable System Tick Counter
  SYSTICK_Cmd(ENABLE);
}
/*********************************************************************//**
 * @brief       c_entry: Main program body
 * @param[in]   None
 * @return      None
 **********************************************************************/
void c_entry (void)
{
    uint8_t* pDest =    (uint8_t*)VTOR_OFFSET;
    uint8_t* pSource = NULL;
    GPIO_Init();
    
    /* Initialize debug via UART0
     * – 115200bps
     * – 8 data bit
     * – No parity
     * – 1 stop bit
     * – No flow control
     */
    debug_frmwrk_init();

    // print welcome screen
    print_menu();

    GPIO_SetDir(BRD_LED_1_CONNECTED_PORT, BRD_LED_1_CONNECTED_MASK, 1);

    _DBG(" Remapping Vector Table at address: ");

    _DBH32(VTOR_OFFSET); _DBG_("");

    NVIC_SetVTOR(VTOR_OFFSET);

    /* Copy Vector Table from 0x00000000 to new address
     * In ROM mode: Vector Interrupt Table is initialized at 0x00000000
     * In RAM mode: Vector Interrupt Table is initialized at 0x10000000
     * Aligned: 256 words
     */


#ifdef __RAM_MODE__ //Run in RAM mode
  pSource =  (void*)0x10000000;
  memcpy(pDest,pSource , 256*4);
#else
  pSource = (void*)0x00000000;
  memcpy(pDest,pSource , 256*4);
#endif

    _DBG_(" If Vector Table remapping is successful, LED P2.10 will blink by using\n\r SysTick interrupt");
    //Initialize System Tick with 100ms time interval
    /* Input parameter for SysTick in range 0..174 ms */
    SYSTICK_InternalInit(100);

    //Enable System Tick interrupt
    SYSTICK_IntCmd(ENABLE);

    //Enable System Tick Counter
    SYSTICK_Cmd(ENABLE);

    while(1);

}
Beispiel #3
0
void Timer_Init(void) {
  
        SystemCoreClockUpdate(); // Получим текущую частоту CPU !
  //Инициализируем System Tick на интервал 1ms
	SYSTICK_InternalInit(1);
  // Для порядка запрещаем работу таймера
        SYSTICK_Cmd(DISABLE);
  // Разрешаем прерывания от таймера
       	SYSTICK_IntCmd(ENABLE);
  // Обнуляем счетчик миллисекунд
        msTicks = 0;
}
Beispiel #4
0
/*********************************************************************//**
 * @brief		c_entry: Main program body
 * @param[in]	None
 * @return 		int
 **********************************************************************/
int c_entry (void)
{
	//Use P0.0 to test System Tick interrupt
	GPIO_SetDir(0, (1<<0), 1); //Set P0.0 as output

	//Initialize System Tick with 10ms time interval
	SYSTICK_InternalInit(10);
	//Enable System Tick interrupt
	SYSTICK_IntCmd(ENABLE);
	//Enable System Tick Counter
	SYSTICK_Cmd(ENABLE);

	while(1);
	return 1;
}
int main(void)
{
    CLKPWR_ConfigPPWR(CLKPWR_PCONP_PCGPIO, ENABLE);
    GPIO_SetDir(1, 1 << 18, 1);

    SYSTICK_InternalInit(1);  // 1ms entre ticks
    SYSTICK_IntCmd(ENABLE);   // Habilita interrupcion SYSTICK
    SYSTICK_Cmd(ENABLE);      // Habilita timer SYSTICK

    while(1)
    {
    	Delay(100);
    	GPIO_ClearValue(1, 1 << 18);
    	Delay(250);
    	GPIO_SetValue(1, 1 << 18);
    }
}
/*********************************************************************//**
 * @brief		c_entry: Main program body
 * @param[in]	None
 * @return 		int
 **********************************************************************/
int c_entry (void)
{
	/* Initialize debug via UART0
	 * – 115200bps
	 * – 8 data bit
	 * – No parity
	 * – 1 stop bit
	 * – No flow control
	 */
	debug_frmwrk_init();

	// print welcome screen
	print_menu();

	//Use P0.0 to test System Tick interrupt
	GPIO_SetDir(1, (1<<28), 1); //Set P0.0 as output

	_DBG("Remapping Vector Table at address: ");
	_DBH32(VTOR_OFFSET); _DBG_("");
	NVIC_SetVTOR(VTOR_OFFSET);

	/* Copy Vector Table from 0x00000000 to new address
	 * In ROM mode: Vector Interrupt Table is initialized at 0x00000000
	 * In RAM mode: Vector Interrupt Table is initialized at 0x10000000
	 * Aligned: 256 words
	 */

#if(__RAM_MODE__==0)//Run in ROM mode
	memcpy(VTOR_OFFSET, 0x00000000, 256*4);
#else
	memcpy(VTOR_OFFSET, 0x10000000, 256*4);
#endif

	_DBG_("If Vector Table remapping is successful, LED P1.28 will blink by using SysTick interrupt");
	//Initialize System Tick with 100ms time interval
	SYSTICK_InternalInit(100);
	//Enable System Tick interrupt
	SYSTICK_IntCmd(ENABLE);
	//Enable System Tick Counter
	SYSTICK_Cmd(ENABLE);

	while(1);
	return 1;
}
/*********************************************************************//**
 * @brief       c_entry: Main program body
 * @param[in]   None
 * @return      None
 **********************************************************************/
void c_entry (void)
{
    GPIO_Init();
    
    //Use GPIO to test System Tick interrupt
    GPIO_SetDir(PIO_PORT_USED, PIO_PIN_VALUE, 1);

    //Initialize System Tick with 10ms time interval
    SYSTICK_InternalInit(10);

    //Enable System Tick interrupt
    SYSTICK_IntCmd(ENABLE);

    //Enable System Tick Counter
    SYSTICK_Cmd(ENABLE);

    while(1);
    
}
Beispiel #8
0
int main() {
	BOOT_INIT;

	#ifdef LED_PORT
		LED_PORT->FIODIR |= 1<<LED_PIN;
	#endif
		//init_printf(NULL, vcom_putc);
		//printf("a\n");
//	#ifdef LED_PORT
//		LED_PORT->FIOCLR |= 1<<LED_PIN;
//	#endif

	int rstsrc = LPC_SC->RSID & 0xF;
	uint8_t wdreset = (rstsrc & (1<<2)) /*|| rstsrc == 0*/;

	LPC_SC->RSID = 0xF;

#ifdef P2_10_RESET
	if(!(LPC_GPIO2->FIOPIN & 1<<10)) {
		LPC_SC->RSID = 0xF;
		NVIC_SystemReset();
	}
#endif

	if(!BOOT_ENTRY_CONDITION) {
		if(!wdreset && user_code_present()
#ifdef P2_10_RESET
		&& !(LPC_GPIO2->FIODIR & (1<<10))
#endif

		) {
			//delay_busy(1000);
			execute_user_code();
		}
	}

	SystemInit();
	_segs_init();

	//uart_init();
	//init_printf(NULL, vcom_putc);

	SYSTICK_InternalInit(1);
	SYSTICK_IntCmd(ENABLE);
	SYSTICK_Cmd(ENABLE);

#ifdef USB_CONNECT_PORT
	USB_CONNECT_PORT->FIODIR |= 1<<USB_CONNECT_PIN;
#ifdef USB_CONNECT_INVERT
	USB_CONNECT_PORT->FIOSET |= 1<<USB_CONNECT_PIN;
#endif
#endif

	USBInit();

	USBRegisterDescriptors(abDescriptors);
	//USBHwRegisterDevIntHandler(on_usb_device_status);

	usb_boot_init();

	usbConnect(TRUE);

	NVIC_EnableIRQ(USB_IRQn);

	//printf("labas\n");
	uint8_t timeout = 50;

	while(1) {

		//LED_PORT->FIOSET |= 1<<LED_PIN;


#ifdef LED_PORT
		delay_busy(80);
		LED_PORT->FIOSET |= 1<<LED_PIN;
		delay_busy(80);
		LED_PORT->FIOCLR |= 1<<LED_PIN;
#else
		delay_busy(160);
#endif
		timeout--;
		if(timeout == 0 && wdreset && dfu_state == DFU_STATE_dfuIDLE) {
			//LPC_SC->RSID |= 1<<2; //clear wd reset bit
			usbConnect(FALSE);
			NVIC_SystemReset();
		}

#ifdef P2_10_RESET
		// if P2.10 is low, reset the system to enter ISP
		if(!(LPC_GPIO2->FIOPIN & 1<<10)) {
			NVIC_SystemReset();
		}
#endif


	}
}