Subversion Repositories CharLCD

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 mjames 1
/* USER CODE BEGIN Header */
2
/**
3
  ******************************************************************************
4
  * @file           : main.c
5
  * @brief          : Main program body
6
  ******************************************************************************
7
  * @attention
8
  *
9
  * Copyright (c) 2022 STMicroelectronics.
10
  * All rights reserved.
11
  *
12
  * This software is licensed under terms that can be found in the LICENSE file
13
  * in the root directory of this software component.
14
  * If no LICENSE file comes with this software, it is provided AS-IS.
15
  *
16
  ******************************************************************************
17
  */
18
/* USER CODE END Header */
19
/* Includes ------------------------------------------------------------------*/
20
#include "main.h"
21
 
22
/* Private includes ----------------------------------------------------------*/
23
/* USER CODE BEGIN Includes */
24
#include "runner.h"
25
/* USER CODE END Includes */
26
 
27
/* Private typedef -----------------------------------------------------------*/
28
/* USER CODE BEGIN PTD */
29
 
30
/* USER CODE END PTD */
31
 
32
/* Private define ------------------------------------------------------------*/
33
/* USER CODE BEGIN PD */
34
/* USER CODE END PD */
35
 
36
/* Private macro -------------------------------------------------------------*/
37
/* USER CODE BEGIN PM */
38
 
39
/* USER CODE END PM */
40
 
41
/* Private variables ---------------------------------------------------------*/
42
 TIM_HandleTypeDef htim1;
43
 
44
/* USER CODE BEGIN PV */
45
 
46
/* USER CODE END PV */
47
 
48
/* Private function prototypes -----------------------------------------------*/
49
void SystemClock_Config(void);
50
static void MX_GPIO_Init(void);
51
static void MX_TIM1_Init(void);
52
/* USER CODE BEGIN PFP */
53
 
54
/* USER CODE END PFP */
55
 
56
/* Private user code ---------------------------------------------------------*/
57
/* USER CODE BEGIN 0 */
58
 
59
/* USER CODE END 0 */
60
 
61
/**
62
  * @brief  The application entry point.
63
  * @retval int
64
  */
65
int main(void)
66
{
67
  /* USER CODE BEGIN 1 */
68
 
69
  /* USER CODE END 1 */
70
 
71
  /* MCU Configuration--------------------------------------------------------*/
72
 
73
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
74
  HAL_Init();
75
 
76
  /* USER CODE BEGIN Init */
77
 
78
  /* USER CODE END Init */
79
 
80
  /* Configure the system clock */
81
  SystemClock_Config();
82
 
83
  /* USER CODE BEGIN SysInit */
84
 
85
  /* USER CODE END SysInit */
86
 
87
  /* Initialize all configured peripherals */
88
  MX_GPIO_Init();
89
  MX_TIM1_Init();
90
  /* USER CODE BEGIN 2 */
91
 // Start timer
92
  HAL_TIM_Base_Start(&htim1);
93
 
94
  initialise();
95
  /* USER CODE END 2 */
96
 
97
  /* Infinite loop */
98
  /* USER CODE BEGIN WHILE */
99
  while (1)
100
  {
101
    runner();
102
    /* USER CODE END WHILE */
103
 
104
    /* USER CODE BEGIN 3 */
105
  }
106
  /* USER CODE END 3 */
107
}
108
 
109
/**
110
  * @brief System Clock Configuration
111
  * @retval None
112
  */
113
void SystemClock_Config(void)
114
{
115
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
116
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
117
 
118
  /** Initializes the RCC Oscillators according to the specified parameters
119
  * in the RCC_OscInitTypeDef structure.
120
  */
121
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
122
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
123
  RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
124
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
125
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
126
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
127
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
128
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
129
  {
130
    Error_Handler();
131
  }
132
 
133
  /** Initializes the CPU, AHB and APB buses clocks
134
  */
135
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
136
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
137
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
138
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
139
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
140
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
141
 
142
  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
143
  {
144
    Error_Handler();
145
  }
146
}
147
 
148
/**
149
  * @brief TIM1 Initialization Function
150
  * @param None
151
  * @retval None
152
  */
153
static void MX_TIM1_Init(void)
154
{
155
 
156
  /* USER CODE BEGIN TIM1_Init 0 */
157
 
158
  /* USER CODE END TIM1_Init 0 */
159
 
160
  TIM_ClockConfigTypeDef sClockSourceConfig = {0};
161
  TIM_MasterConfigTypeDef sMasterConfig = {0};
162
 
163
  /* USER CODE BEGIN TIM1_Init 1 */
164
 
165
  /* USER CODE END TIM1_Init 1 */
166
  htim1.Instance = TIM1;
167
  htim1.Init.Prescaler = 35;
168
  htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
169
  htim1.Init.Period = 65535;
170
  htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
171
  htim1.Init.RepetitionCounter = 0;
172
  htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
173
  if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
174
  {
175
    Error_Handler();
176
  }
177
  sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
178
  if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
179
  {
180
    Error_Handler();
181
  }
182
  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
183
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
184
  if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
185
  {
186
    Error_Handler();
187
  }
188
  /* USER CODE BEGIN TIM1_Init 2 */
189
 
190
  /* USER CODE END TIM1_Init 2 */
191
 
192
}
193
 
194
/**
195
  * @brief GPIO Initialization Function
196
  * @param None
197
  * @retval None
198
  */
199
static void MX_GPIO_Init(void)
200
{
201
  GPIO_InitTypeDef GPIO_InitStruct = {0};
202
 
203
  /* GPIO Ports Clock Enable */
204
  __HAL_RCC_GPIOD_CLK_ENABLE();
205
  __HAL_RCC_GPIOA_CLK_ENABLE();
206
 
207
  /*Configure GPIO pin Output Level */
208
  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3
209
                          |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6, GPIO_PIN_RESET);
210
 
211
  /*Configure GPIO pins : PA0 PA1 PA2 PA3
212
                           PA4 PA5 PA6 */
213
  GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3
214
                          |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6;
215
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
216
  GPIO_InitStruct.Pull = GPIO_NOPULL;
217
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
218
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
219
 
220
}
221
 
222
/* USER CODE BEGIN 4 */
223
 
224
/* USER CODE END 4 */
225
 
226
/**
227
  * @brief  This function is executed in case of error occurrence.
228
  * @retval None
229
  */
230
void Error_Handler(void)
231
{
232
  /* USER CODE BEGIN Error_Handler_Debug */
233
  /* User can add his own implementation to report the HAL error return state */
234
  __disable_irq();
235
  while (1)
236
  {
237
  }
238
  /* USER CODE END Error_Handler_Debug */
239
}
240
 
241
#ifdef  USE_FULL_ASSERT
242
/**
243
  * @brief  Reports the name of the source file and the source line number
244
  *         where the assert_param error has occurred.
245
  * @param  file: pointer to the source file name
246
  * @param  line: assert_param error line source number
247
  * @retval None
248
  */
249
void assert_failed(uint8_t *file, uint32_t line)
250
{
251
  /* USER CODE BEGIN 6 */
252
  /* User can add his own implementation to report the file name and line number,
253
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
254
  /* USER CODE END 6 */
255
}
256
#endif /* USE_FULL_ASSERT */