Subversion Repositories LedShow

Rev

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