Subversion Repositories LedShow

Rev

Rev 5 | Go to most recent revision | 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
  * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
10
  * All rights reserved.</center></h2>
11
  *
12
  * This software component is licensed by ST under Ultimate Liberty license
13
  * SLA0044, the "License"; You may not use this file except in compliance with
14
  * the License. You may obtain a copy of the License at:
15
  *                             www.st.com/SLA0044
16
  *
17
  ******************************************************************************
18
  */
19
/* USER CODE END Header */
20
 
21
/* Includes ------------------------------------------------------------------*/
22
#include "main.h"
23
#include "usb_device.h"
24
 
25
/* Private includes ----------------------------------------------------------*/
26
/* USER CODE BEGIN Includes */
27
#include "leds.h"
28
/* Includes ------------------------------------------------------------------*/
29
#include "usbd_cdc_if.h"
30
 
31
/* USER CODE END Includes */
32
 
33
/* Private typedef -----------------------------------------------------------*/
34
/* USER CODE BEGIN PTD */
35
 
36
/* USER CODE END PTD */
37
 
38
/* Private define ------------------------------------------------------------*/
39
/* USER CODE BEGIN PD */
40
 
41
/* USER CODE END PD */
42
 
43
/* Private macro -------------------------------------------------------------*/
44
/* USER CODE BEGIN PM */
45
 
46
/* USER CODE END PM */
47
 
48
/* Private variables ---------------------------------------------------------*/
49
SPI_HandleTypeDef hspi1;
50
DMA_HandleTypeDef hdma_spi1_tx;
51
 
52
UART_HandleTypeDef huart1;
53
 
54
/* USER CODE BEGIN PV */
55
 
56
/* USER CODE END PV */
57
 
58
/* Private function prototypes -----------------------------------------------*/
59
void SystemClock_Config(void);
60
static void MX_GPIO_Init(void);
61
static void MX_DMA_Init(void);
62
static void MX_SPI1_Init(void);
63
static void MX_USART1_UART_Init(void);
64
/* USER CODE BEGIN PFP */
65
 
66
/* USER CODE END PFP */
67
 
68
/* Private user code ---------------------------------------------------------*/
69
/* USER CODE BEGIN 0 */
70
 
71
/* USER CODE END 0 */
72
 
73
/**
74
  * @brief  The application entry point.
75
  * @retval int
76
  */
77
int main(void)
78
{
79
  /* USER CODE BEGIN 1 */
80
 
81
  /* USER CODE END 1 */
82
 
83
 
84
  /* MCU Configuration--------------------------------------------------------*/
85
 
86
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
87
  HAL_Init();
88
 
89
  /* USER CODE BEGIN Init */
90
 
91
  /* USER CODE END Init */
92
 
93
  /* Configure the system clock */
94
  SystemClock_Config();
95
 
96
  /* USER CODE BEGIN SysInit */
97
 
98
  /* USER CODE END SysInit */
99
 
100
  /* Initialize all configured peripherals */
101
  MX_GPIO_Init();
102
  MX_DMA_Init();
103
  MX_SPI1_Init();
104
  MX_USART1_UART_Init();
105
  MX_USB_DEVICE_Init();
106
  /* USER CODE BEGIN 2 */
107
 
108
  /* USER CODE END 2 */
109
 
110
  /* Infinite loop */
111
  /* USER CODE BEGIN WHILE */
112
  while (1)
113
  {
114
    /* USER CODE END WHILE */
115
 
116
    /* USER CODE BEGIN 3 */
117
    CDC_Transmit_FS("boop\r\n",6);
118
    sendLeds();
119
    HAL_Delay(100);
120
 
121
  }
122
  /* USER CODE END 3 */
123
}
124
 
125
/**
126
  * @brief System Clock Configuration
127
  * @retval None
128
  */
129
void SystemClock_Config(void)
130
{
131
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
132
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
133
  RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
134
 
135
  /** Initializes the CPU, AHB and APB busses clocks
136
  */
137
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
138
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
139
  RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
140
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
141
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
142
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
143
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
144
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
145
  {
146
    Error_Handler();
147
  }
148
  /** Initializes the CPU, AHB and APB busses clocks
149
  */
150
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
151
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
152
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
153
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
154
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
155
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
156
 
157
  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
158
  {
159
    Error_Handler();
160
  }
161
  PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB;
162
  PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLL_DIV1_5;
163
  if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
164
  {
165
    Error_Handler();
166
  }
167
}
168
 
169
/**
170
  * @brief SPI1 Initialization Function
171
  * @param None
172
  * @retval None
173
  */
174
static void MX_SPI1_Init(void)
175
{
176
 
177
  /* USER CODE BEGIN SPI1_Init 0 */
178
 
179
  /* USER CODE END SPI1_Init 0 */
180
 
181
  /* USER CODE BEGIN SPI1_Init 1 */
182
 
183
  /* USER CODE END SPI1_Init 1 */
184
  /* SPI1 parameter configuration*/
185
  hspi1.Instance = SPI1;
186
  hspi1.Init.Mode = SPI_MODE_MASTER;
187
  hspi1.Init.Direction = SPI_DIRECTION_2LINES;
188
  hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
189
  hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
190
  hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
191
  hspi1.Init.NSS = SPI_NSS_SOFT;
192
  hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
193
  hspi1.Init.FirstBit = SPI_FIRSTBIT_LSB;
194
  hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
195
  hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
196
  hspi1.Init.CRCPolynomial = 10;
197
  if (HAL_SPI_Init(&hspi1) != HAL_OK)
198
  {
199
    Error_Handler();
200
  }
201
  /* USER CODE BEGIN SPI1_Init 2 */
202
 
203
  /* USER CODE END SPI1_Init 2 */
204
 
205
}
206
 
207
/**
208
  * @brief USART1 Initialization Function
209
  * @param None
210
  * @retval None
211
  */
212
static void MX_USART1_UART_Init(void)
213
{
214
 
215
  /* USER CODE BEGIN USART1_Init 0 */
216
 
217
  /* USER CODE END USART1_Init 0 */
218
 
219
  /* USER CODE BEGIN USART1_Init 1 */
220
 
221
  /* USER CODE END USART1_Init 1 */
222
  huart1.Instance = USART1;
223
  huart1.Init.BaudRate = 115200;
224
  huart1.Init.WordLength = UART_WORDLENGTH_8B;
225
  huart1.Init.StopBits = UART_STOPBITS_1;
226
  huart1.Init.Parity = UART_PARITY_NONE;
227
  huart1.Init.Mode = UART_MODE_TX_RX;
228
  huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
229
  huart1.Init.OverSampling = UART_OVERSAMPLING_16;
230
  if (HAL_UART_Init(&huart1) != HAL_OK)
231
  {
232
    Error_Handler();
233
  }
234
  /* USER CODE BEGIN USART1_Init 2 */
235
 
236
  /* USER CODE END USART1_Init 2 */
237
 
238
}
239
 
240
/**
241
  * Enable DMA controller clock
242
  */
243
static void MX_DMA_Init(void)
244
{
245
  /* DMA controller clock enable */
246
  __HAL_RCC_DMA1_CLK_ENABLE();
247
 
248
  /* DMA interrupt init */
249
  /* DMA1_Channel3_IRQn interrupt configuration */
250
  HAL_NVIC_SetPriority(DMA1_Channel3_IRQn, 0, 0);
251
  HAL_NVIC_EnableIRQ(DMA1_Channel3_IRQn);
252
 
253
}
254
 
255
/**
256
  * @brief GPIO Initialization Function
257
  * @param None
258
  * @retval None
259
  */
260
static void MX_GPIO_Init(void)
261
{
262
 
263
  /* GPIO Ports Clock Enable */
264
  __HAL_RCC_GPIOD_CLK_ENABLE();
265
  __HAL_RCC_GPIOA_CLK_ENABLE();
266
 
267
}
268
 
269
/* USER CODE BEGIN 4 */
270
 
271
/* USER CODE END 4 */
272
 
273
/**
274
  * @brief  This function is executed in case of error occurrence.
275
  * @retval None
276
  */
277
void Error_Handler(void)
278
{
279
  /* USER CODE BEGIN Error_Handler_Debug */
280
  /* User can add his own implementation to report the HAL error return state */
281
 
282
  /* USER CODE END Error_Handler_Debug */
283
}
284
 
285
#ifdef  USE_FULL_ASSERT
286
/**
287
  * @brief  Reports the name of the source file and the source line number
288
  *         where the assert_param error has occurred.
289
  * @param  file: pointer to the source file name
290
  * @param  line: assert_param error line source number
291
  * @retval None
292
  */
293
void assert_failed(uint8_t *file, uint32_t line)
294
{
295
  /* USER CODE BEGIN 6 */
296
  /* User can add his own implementation to report the file name and line number,
297
     tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
298
  /* USER CODE END 6 */
299
}
300
#endif /* USE_FULL_ASSERT */
301
 
302
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/