GlobLib
HAL and API libraries for MCUs and hardware.
stm32f103cb_core.c
Go to the documentation of this file.
1 
17 #include "stm32f103cb_core.h"
18 
19 void USB_coms(timer_main timerNumber){
20 
21  //From _clock.h
23 
24  //From _usb.h
25  USB_setup();
26 
27  switch (timerNumber){
28 
29  case TIMER_1:
30 
31  //From _timer.h and usb.h
32  TIMER_setupCount(timerNumber,4000,&USB_update); //4KHz update
33  break;
34 
35  case TIMER_2:
36 
37  //From _timer.h and usb.h
38  nvic_set_priority(NVIC_TIM2_IRQ,0);
39  TIMER_setupCount(timerNumber,5000,&USB_update); //4KHz update
40  break;
41 
42  case TIMER_3:
43 
44  //From _timer.h and usb.h
45  TIMER_setupCount(timerNumber,4000,&USB_update); //4KHz update
46  break;
47 
48  case TIMER_4:
49 
50  //From _timer.h and usb.h
51  TIMER_setupCount(timerNumber,4000,&USB_update); //4KHz update
52  break;
53 
54  default:
55 
56  //Systick is the default
57  SYSTICK_setup(250,&USB_update); //4KHz update
58  break;
59  }
60 
61  //Setup the output for the string library
62  STRING11_setOutput(&USB_put);
63 }
64 
65 void delayms(uint32_t delay){
66 
67  switch(CLOCK_getSpeed() / 1000000){
68 
69  case 8:
70 
71  for(volatile uint32_t j = 0; j < delay; j++) {
72 
73  for(volatile uint16_t i = 0; i < 548; i++);
74  }
75 
76  break;
77 
78  case 24:
79 
80  for(volatile uint32_t j = 0; j < delay; j++) {
81 
82  for(volatile uint16_t i = 0; i < 1732; i++);
83  }
84  break;
85 
86  case 48:
87 
88  for(volatile uint32_t j = 0; j < delay; j++) {
89 
90  for(volatile uint16_t i = 0; i < 2995; i++);
91  }
92  break;
93 
94  case 64:
95 
96  for(volatile uint32_t j = 0; j < delay; j++) {
97 
98  for(volatile uint16_t i = 0; i < 3375; i++);
99  }
100  break;
101 
102  case 72:
103 
104  for(volatile uint32_t j = 0; j < delay; j++) {
105 
106  for(volatile uint16_t i = 0; i < 3890; i++);
107  }
108 
109  break;
110 
111  }
112 
113 }
Timer 2.
External 8MHz oscillator, multiplied to 72MHz final.
Timer 1.
Generic header file for all modules.
Timer 3.
void USB_put(uint8_t byte)
Send a single byte on USB.
mcu_error TIMER_setupCount(timer_main timerNumber, uint32_t frequency, void(*handler)(void))
Initialize given timer for standard count with interrupt on timeout.
timer_main
Main timers available on the MCU.
uint32_t CLOCK_getSpeed(void)
Get the current clock speed of the device.
void USB_setup(void)
Initialize the USB device.
void delayms(uint32_t delay)
Millisecond blocking delay.
void USB_update(void)
Update the USB peripheral.
Timer 4.
void USB_coms(timer_main timerNumber)
Set up USB "serial" communication. The passed timer is used to update the device. ...
mcu_error CLOCK_setSpeed(clock_option option)
Set the final clock speed of the device.
mcu_error SYSTICK_setup(uint32_t timeout, void(*handler)(void))
Sets up systick and handler.