Browse code

Add source code of the firmware for the IO Board

Pawel Jablonski authored on 05/06/2023 17:01:27
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,113 @@
1
+/*
2
+ * Author: Pawel Jablonski
3
+ * E-mail: pj@xirx.net
4
+ * WWW: xirx.net
5
+ * GIT: git.xirx.net
6
+ *
7
+ * License: You can use this code however you like
8
+ * but leave information about the original author.
9
+ * Code is free for non-commercial and commercial use.
10
+ */
11
+
12
+#include <stm32f0xx.h>
13
+#include <stm32f0xx_hal.h>
14
+#include <stm32f0xx_hal_gpio.h>
15
+#include <stm32f0xx_hal_rcc.h>
16
+#include <system_stm32f0xx.h>
17
+
18
+#include "type.h"
19
+#include "led.h"
20
+#include "rtc.h"
21
+#include "keyboard.h"
22
+#include "speaker.h"
23
+#include "lcd.h"
24
+#include "flash.h"
25
+#include "io.h"
26
+#include "rs232.h"
27
+#include "usb.h"
28
+#include "fs.h"
29
+
30
+bool initIsEnded = FALSE; //!< Status of end initializing all devices
31
+
32
+//! Init main clock
33
+static void initClock(void)
34
+{
35
+	RCC_OscInitTypeDef oscInit;
36
+
37
+	oscInit.OscillatorType = (RCC_OSCILLATORTYPE_HSE | RCC_OSCILLATORTYPE_LSE);
38
+	oscInit.HSEState = RCC_HSE_ON;
39
+	oscInit.HSICalibrationValue = 16;
40
+	oscInit.LSEState = RCC_LSE_ON;
41
+	oscInit.PLL.PLLState = RCC_PLL_ON;
42
+	oscInit.PLL.PLLSource = RCC_PLLSOURCE_HSE;
43
+	oscInit.PLL.PLLMUL = RCC_PLL_MUL6;
44
+	oscInit.PLL.PREDIV = RCC_PREDIV_DIV1;
45
+	
46
+	if(HAL_RCC_OscConfig(&oscInit) != HAL_OK)
47
+	{
48
+		while(1);
49
+	}
50
+	
51
+	RCC_ClkInitTypeDef clkInit;
52
+	
53
+	clkInit.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1);
54
+	clkInit.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
55
+	clkInit.AHBCLKDivider = RCC_SYSCLK_DIV1;
56
+	clkInit.APB1CLKDivider = RCC_HCLK_DIV1;
57
+	
58
+	if(HAL_RCC_ClockConfig(&clkInit, FLASH_LATENCY_1) != HAL_OK)
59
+	{
60
+		while(1);
61
+	}
62
+
63
+	__HAL_RCC_SYSCFG_CLK_ENABLE();
64
+	
65
+	HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000);
66
+	HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
67
+
68
+	HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
69
+}
70
+
71
+//! Main clock ticks handler. It executes a fire function if the time counter reach maximum delay for connected device.
72
+void SysTick_Handler(void)
73
+{	
74
+	HAL_IncTick();
75
+	
76
+	if(initIsEnded)
77
+	{
78
+		static unsigned long long time = 0;
79
+		
80
+		if((time % KEYBOARD_FIRE_DELAY) == 0) keyboardFire();
81
+		if((time % IO_FIRE_CLOCK_DELAY) == 0) ioFireClock();
82
+		if((time % IO_FIRE_PERIPHERIAL_DELAY) == 0) ioFirePeripherial();
83
+
84
+		time++;
85
+	}
86
+}
87
+
88
+//! Main entry function of the firmware
89
+int main(void)
90
+{
91
+	HAL_Init();
92
+	
93
+	initClock();
94
+	
95
+	ioPreInit();
96
+	
97
+	ledInit();
98
+	rtcInit();
99
+	keyboardInit();
100
+	speakerInit();
101
+	lcdInit();
102
+	flashInit();
103
+	rs232Init();
104
+	usbInit();
105
+	fsInit();
106
+	ioInit();
107
+	
108
+	initIsEnded = TRUE;
109
+	
110
+	lcdDrawLoop();
111
+		
112
+	return(0);
113
+}