Subversion Repositories LedShow

Rev

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