Exemplo n.º 1
0
void systick_setup(void)
{
    systick_set_reload(rcc_ahb_frequency / SYSTICK_HZ);
    systick_set_clocksource(STK_CSR_CLKSOURCE_AHB);
    systick_counter_enable();
    systick_interrupt_enable();
}
Exemplo n.º 2
0
/*
 * Initialise the Cortex-M3 SysTick timer
 */
void timer_init(void) {
	system_millis = 0;

	/*
	 * MCU clock (120 MHz) as source
	 *
	 *     (120 MHz / 8) = 15 clock pulses
	 *
	 */
	systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8);
	STK_CVR = 0;

	/*
	 * 1 tick = 1 ms @ 120 MHz
	 *
	 *     (15 clock pulses * 1000 ms) = 15000 clock pulses
	 *
	 * Send an interrupt every (N - 1) clock pulses
	 */
	systick_set_reload(14999);

	/* SysTick as interrupt */
	systick_interrupt_enable();

	systick_counter_enable();
}
Exemplo n.º 3
0
void systick_init(void)
{
	systick_ms = 0;
	systick_set_frequency(1000, rcc_ppre2_frequency*2);
	systick_interrupt_enable();
	systick_counter_enable();
}
Exemplo n.º 4
0
void tick_init(void)
{
  uint32_t systick_reload_val;
  g_ulSysTickCount = 0;

  /* Disable IRQ globally */
  asm volatile ("cpsid i");

  /* Set processor Clock as Source Clock */
  systick_set_clocksource(STK_CSR_CLKSOURCE_AHB);

  systick_set_reload(rcc_ahb_frequency / 1000);

  systick_interrupt_enable();

  /* Start counting. */
  systick_counter_enable();

  /* Set SysTick Priority to maximum */
  nvic_set_priority(NVIC_SYSTICK_IRQ, 255);

  /* Enable IRQ globally */
  asm volatile ("cpsie i");
  scs_dwt_cycle_counter_enabled();
}
Exemplo n.º 5
0
int main(void)
{
	/* Check the force bootloader pin*/
	rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPAEN);
	if(!gpio_get(GPIOA, GPIO0))
		dfu_jump_app_if_valid();

	dfu_protect_enable();

	/* Set up clock*/
	rcc_clock_setup_hse_3v3(&hse_8mhz_3v3[CLOCK_3V3_168MHZ]);
	systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8);
	systick_set_reload(2100000);

	systick_interrupt_enable();
	systick_counter_enable();

	/* Handle LED */
	rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPDEN);
	gpio_clear(GPIOA, GPIO4);
	gpio_mode_setup(GPIOA, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE,
			GPIO4);

	/* Set up USB*/
	rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPAEN);
	rcc_peripheral_enable_clock(&RCC_AHB2ENR, RCC_AHB2ENR_OTGFSEN);

	/* Set up USB Pins and alternate function*/
	gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE,
		GPIO9 | GPIO10 | GPIO11 | GPIO12);
	gpio_set_af(GPIOA, GPIO_AF10, GPIO9 | GPIO10| GPIO11 | GPIO12);
	dfu_init(&stm32f107_usb_driver);

	dfu_main();
}
Exemplo n.º 6
0
void time_init() {
  systick_set_reload(0xffffff);
  systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB);
  rollovers = 0;
  systick_interrupt_enable();
  systick_counter_enable();
}
Exemplo n.º 7
0
void init_systick(void)
{
	systick_set_frequency(HZ, 72000000);

	systick_interrupt_enable();
	systick_counter_enable();
}
Exemplo n.º 8
0
int main(void)
{
	rcc_clock_setup_in_hse_8mhz_out_72mhz();
	gpio_setup();

	gpio_clear(GPIOA, GPIO7);	/* LED1 on */
	gpio_set(GPIOA, GPIO6);		/* LED2 off */

	temp32 = 0;

	/* 72MHz / 8 => 9000000 counts per second */
	systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8);

	/* 9000000/9000 = 1000 overflows per second - every 1ms one interrupt */
	/* SysTick interrupt every N clock pulses: set reload to N-1 */
	systick_set_reload(8999);

	systick_interrupt_enable();

	/* Start counting. */
	systick_counter_enable();

	while (1); /* Halt. */

	return 0;
}
Exemplo n.º 9
0
void systick_setup(void)
{
    uint32_t systick_reload_val;
    g_ulSysTickCount = 0;

    /* Disable IRQ globally */
    __asm__("cpsid i");

    /* Set processor Clock as Source Clock */
    systick_set_clocksource(STK_CTRL_CLKSOURCE);

    /* Get SysTick calibration value to obtain by default 1 tick = 10ms */
    systick_reload_val = systick_get_calib();
    /*
     * Calibration seems wrong on LPC43xx(TBC) for default Freq it assume System Clock is 12MHz but it is 12*17=204MHz
     * Fix the Calibration value bu multiplication by 17
     */
    systick_reload_val = (systick_reload_val*17);

    /* To obtain 1ms per tick just divide by 10 the 10ms base tick and set the reload */
    systick_reload_val = systick_reload_val/10;
    systick_set_reload(systick_reload_val);

    systick_interrupt_enable();

    /* Start counting. */
    systick_counter_enable();

    /* Set SysTick Priority to maximum */
    nvic_set_priority(NVIC_SYSTICK_IRQ, 0xFF);

    /* Enable IRQ globally */
    __asm__("cpsie i");
}
Exemplo n.º 10
0
int main(void)
{
	/* Check the force bootloader pin*/
	rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN);
	if(gpio_get(GPIOB, GPIO12))
		dfu_jump_app_if_valid();

	dfu_protect_enable();

	rcc_clock_setup_in_hse_8mhz_out_72mhz();
	systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8);
	systick_set_reload(900000);

	rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
        rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_USBEN);
	gpio_set_mode(GPIOA, GPIO_MODE_INPUT, 0, GPIO8);

	systick_interrupt_enable();
	systick_counter_enable();

	gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ,
			GPIO_CNF_OUTPUT_PUSHPULL, GPIO11);
	gpio_set_mode(GPIOB, GPIO_MODE_INPUT,
			GPIO_CNF_INPUT_FLOAT, GPIO2 | GPIO10);

	dfu_init(&stm32f103_usb_driver);

	gpio_set(GPIOA, GPIO8);
	gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
			GPIO_CNF_OUTPUT_PUSHPULL, GPIO8);

	dfu_main();
}
Exemplo n.º 11
0
void time_init(void) {
  system_ms = 0;
  systick_set_clocksource(STK_CSR_CLKSOURCE_AHB);
  STK_CVR = 0;
  systick_set_reload(32000000/1000 -1);
  systick_counter_enable();
  systick_interrupt_enable();
}
Exemplo n.º 12
0
void systick_setup(void)
{
	systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8); // 24meg / 8 = 3Mhz
	// one interrupt per ms..
	systick_set_reload(3000);
	systick_interrupt_enable();
	systick_counter_enable();
}
Exemplo n.º 13
0
/* Implementing a usleep alternative*/
void _delay_us(u32 delay_us)
{
    tick_us = 0;
    desired_us = delay_us;
    systick_counter_enable();
    while( tick_us < desired_us);// This provides the busy-wait
    systick_counter_disable();// Kill the interrupt if not using it.  The ISR just slows down the uC
}
Exemplo n.º 14
0
void stick_init(int32_t hz)
{
	ticks = 0;

	systick_set_frequency(hz, rcc_ppre2_frequency*2);
	systick_interrupt_enable();
	systick_counter_enable();
}
Exemplo n.º 15
0
void SetupSystick(void)
{
	// Clock rate / 1000 = 168000 for one ms
	systick_set_reload(168000);
	systick_set_clocksource(STK_CSR_CLKSOURCE_AHB);
	systick_counter_enable();
	systick_interrupt_enable();
}
Exemplo n.º 16
0
int platform_init(void)
{
	rcc_clock_setup_hse_3v3(&hse_8mhz_3v3[CLOCK_3V3_168MHZ]);

	/* Enable peripherals */
	rcc_peripheral_enable_clock(&RCC_AHB2ENR, RCC_AHB2ENR_OTGFSEN);
	rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPAEN);
	rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPBEN);
	rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPCEN);

        /* Fix all flaoting pins*/
	gpio_mode_setup(GPIOA, GPIO_MODE_INPUT, GPIO_PUPD_PULLDOWN,
                        0x1ff);

	gpio_mode_setup(GPIOB, GPIO_MODE_INPUT, GPIO_PUPD_PULLDOWN,
                        0xffe2);

	gpio_mode_setup(GPIOC, GPIO_MODE_INPUT, GPIO_PUPD_PULLDOWN,
                        0xf3ff);

	/* Set up USB Pins and alternate function*/
	gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE,
		GPIO9 | GPIO10| GPIO11 | GPIO12);
	gpio_set_af(GPIOA, GPIO_AF10, GPIO9 | GPIO10| GPIO11 | GPIO12);

        /* Set TMS/TCK/TDI to high speed*/
        GPIOA_OSPEEDR &=~0xfc00;
        GPIOA_OSPEEDR |= 0xa800;
	gpio_mode_setup(JTAG_PORT, GPIO_MODE_OUTPUT,
			GPIO_PUPD_NONE,
			TMS_PIN | TCK_PIN | TDI_PIN);

	gpio_mode_setup(TDO_PORT, GPIO_MODE_INPUT,
			GPIO_PUPD_NONE,
			TDO_PIN | TRST_PIN);

	gpio_mode_setup(LED_PORT, GPIO_MODE_OUTPUT,
			GPIO_PUPD_NONE,
			LED_UART );

	/* Setup heartbeat timer */
	systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8);
	systick_set_reload(168000000/(10*8));	/* Interrupt us at 10 Hz */
	SCB_SHPR(11) &= ~((15 << 4) & 0xff);
	SCB_SHPR(11) |= ((14 << 4) & 0xff);
	systick_interrupt_enable();
	systick_counter_enable();

	usbuart_init();

	SCB_VTOR = 0x10000;	// Relocate interrupt vector table here

	cdcacm_init();

	jtag_scan(NULL);

	return 0;
}
Exemplo n.º 17
0
void time_init() {
  { CriticalSection cs;
    systick_set_reload(0xffffff);
    systick_set_clocksource(STK_CSR_CLKSOURCE_AHB);
    rollovers = 0;
    systick_interrupt_enable();
    systick_counter_enable();
  }
}
Exemplo n.º 18
0
/*
 * systick_setup(void)
 *
 * This function sets up the 1khz "system tick" count. The SYSTICK counter is a
 * standard feature of the Cortex-M series.
 */
static void systick_setup(void)
{
	/* clock rate / 1000 to get 1mS interrupt rate */
	systick_set_reload(168000);
	systick_set_clocksource(STK_CSR_CLKSOURCE_AHB);
	systick_counter_enable();
	/* this done last */
	systick_interrupt_enable();
}
Exemplo n.º 19
0
/* Set up timer to fire freq times per second */
static void systick_setup(int freq)
{
	systick_set_clocksource(STK_CSR_CLKSOURCE_AHB);
	/* clear counter so it starts right away */
	STK_CVR = 0;
	systick_set_reload(32000000 / freq);
	systick_counter_enable();
	systick_interrupt_enable();
}
Exemplo n.º 20
0
static void systick_setup(void) {
    /* 72 MHz with DIV 8 -> systick clock source of 9MHz */
    systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8);

    /* Systick interrupt period 1ms -> 9MHz / 1kHz = 9000 */
    systick_set_reload(9000 - 1);
    systick_interrupt_enable();
    systick_counter_enable();
}
Exemplo n.º 21
0
/**
 * initialise and start SysTick counter. This will trigger the
 * sys_tick_handler() periodically once interrupts have been enabled
 * by archFirstThreadRestore()
 */
static void systick_setup(void)
{

    //systick_set_frequency(SYSTEM_TICKS_PER_SEC, 72000000); OLD :: MOD
    systick_set_frequency(SYSTEM_TICKS_PER_SEC, 24000000);

    systick_interrupt_enable();

    systick_counter_enable();
}
Exemplo n.º 22
0
void time_delay_ms(unsigned int delay) {
  uint32_t wake = system_ms + delay;
  uint32_t cnt;
  do {
    systick_counter_disable();
    cnt = system_ms;
    systick_counter_enable();
  }
  while (wake > cnt);
}
Exemplo n.º 23
0
void clock_setup(void)
{
	rcc_clock_setup_hse_3v3(&rcc_hse_8mhz_3v3[RCC_CLOCK_3V3_168MHZ]);

	/* set up the SysTick function (1mS interrupts) */
	systick_set_clocksource(STK_CSR_CLKSOURCE_AHB);
	STK_CVR = 0;
	systick_set_reload(rcc_ahb_frequency / 1000);
	systick_counter_enable();
	systick_interrupt_enable();
}
Exemplo n.º 24
0
void setup_clock(void)
{
    /* Setup clock source @ 32MHz */
    rcc_clock_setup_pll(&rcc_clock_config[1]);

    /* Setup sysclock to trigger every 1ms */
    systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8);
    systick_set_reload(3999);
    systick_interrupt_enable();
    systick_counter_enable();
}
Exemplo n.º 25
0
/* Setup systick */
void systick_init(void)
{
    /* 48MHz / 8 => 6,000,000 counts per second */
    systick_set_clocksource(STK_CSR_CLKSOURCE_AHB);

    /* 6,000,000/6000 = 1000 overflows per second - every 1ms one interrupt */
    /* SysTick interrupt every N clock pulses: set reload to N-1 */
    systick_set_reload(47999);
    systick_interrupt_enable();
    systick_counter_enable();
}
Exemplo n.º 26
0
/*
 * Set up timer to fire every x milliseconds
 * This is a unusual usage of systick, be very careful with the 24bit range
 * of the systick counter!  You can range from 1 to 2796ms with this.
 */
static void systick_setup(int xms)
{
    /* div8 per ST, stays compatible with M3/M4 parts, well done ST */
    systick_set_clocksource(STK_CSR_CLKSOURCE_EXT);
    /* clear counter so it starts right away */
    STK_CVR = 0;

    systick_set_reload(rcc_ahb_frequency / 8 / 1000 * xms);
    systick_counter_enable();
    systick_interrupt_enable();
}
static void config_clocks(void)
{
	rcc_clock_setup_in_hse_8mhz_out_24mhz();

	/* Set systick timer to strike every 1ms (1kHz),
	 * enable its interrupt and start it. */
	systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8);
	systick_set_reload(rcc_apb2_frequency / 8 / 1000 - 1);
	systick_interrupt_enable();
	systick_counter_enable();
}
Exemplo n.º 28
0
/*
 * clock_setup(void)
 *
 * This function sets up both the base board clock rate
 * and a 1khz "system tick" count. The SYSTICK counter is
 * a standard feature of the Cortex-M series.
 */
void clock_setup(void)
{
	/* Base board frequency, set to 168Mhz */
	rcc_clock_setup_hse_3v3(&hse_8mhz_3v3[CLOCK_3V3_168MHZ]);

	/* clock rate / 168000 to get 1mS interrupt rate */
	systick_set_reload(168000);
	systick_set_clocksource(STK_CSR_CLKSOURCE_AHB);
	systick_counter_enable();

	/* this done last */
	systick_interrupt_enable();
}
Exemplo n.º 29
0
void systick_setup(void)
{
	/* 72MHz / 8 => 9000000 counts per second */
	systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8);

	/* 9000000/9000 = 1000 overflows per second - every 1ms one interrupt */
	systick_set_reload(9000);

	systick_interrupt_enable();

	/* Start counting. */
	systick_counter_enable();
}
Exemplo n.º 30
0
Arquivo: em-stop.c Projeto: GBert/misc
static void systick_setup(void) {
    /* 72MHz / 8 => 9000000 counts per second */
    systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8);

    /* 9000000/9000 = 1000 overflows per second - every 1ms one interrupt */
    /* SysTick interrupt every N clock pulses: set reload to N-1 */
    systick_set_reload(8999);

    systick_interrupt_enable();

    /* Start counting */
    systick_counter_enable();
}