summaryrefslogtreecommitdiffstats
path: root/app/main.c
blob: 495d2401889fc2d530ba191ae08a7dfba7ac5d1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "project.h"
extern uint32_t dfu_flag;

void
sys_tick_handler (void)
{
uint8_t d;

while (!ring_read_byte(&rx_ring,&d))
	kvm_recv(d);

led_tick();
}

int
main (void)
{
  int i;


//  rcc_clock_setup_in_hsi_out_48mhz ();
  //nvic_set_priority_grouping(NVIC_PriorityGroup_4);

  rcc_clock_setup_in_hse_8mhz_out_72mhz();

  rcc_periph_clock_enable (RCC_GPIOA);
  rcc_periph_clock_enable (RCC_GPIOB);
  rcc_periph_clock_enable (RCC_GPIOC);
  rcc_periph_clock_enable (RCC_AFIO);
  rcc_periph_clock_enable (RCC_USART1);


  usart_init ();

  usb_init ();

  systick_set_clocksource (STK_CSR_CLKSOURCE_AHB_DIV8);
  /* 48MHz / 8 = > 6Mhz */
  systick_set_reload (6000);
  /* 6MHz / 6000 => 1kHz */

  systick_interrupt_enable ();
  systick_counter_enable ();

  nvic_set_priority(NVIC_USART1_IRQ, 0x40);
  nvic_set_priority(NVIC_SYSTICK_IRQ, 0xff);

  //nvic_set_priority(SysTick_IRQn, NVIC_EncodePriority(4,0,0));
  //nvic_set_priority(USART1_IRQn, NVIC_EncodePriority(4,1,0));


  gpio_set (GPIOC, GPIO11);
  gpio_set_mode (GPIOC, GPIO_MODE_OUTPUT_2_MHZ,
                 GPIO_CNF_OUTPUT_PUSHPULL, GPIO11);

  gpio_set_mode (GPIOB, GPIO_MODE_OUTPUT_2_MHZ,
                 GPIO_CNF_OUTPUT_PUSHPULL, GPIO8);
  gpio_set_mode (GPIOB, GPIO_MODE_OUTPUT_2_MHZ,
                 GPIO_CNF_OUTPUT_PUSHPULL, GPIO9);

  led_clear();


  for (i = 0; i < 0x80000; i++)
    __asm__ ("nop");

  gpio_clear (GPIOC, GPIO11);

  printf ("Hello world main=%p\r\n", main);
  printf ("dfu_flag=%08lx\r\n", dfu_flag);

  usb_run ();

  return 0;
}