Subversion Repositories LedShow

Rev

Rev 2 | Rev 8 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  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.  
  55. /* USER CODE BEGIN PV */
  56.  
  57. /* USER CODE END PV */
  58.  
  59. /* Private function prototypes -----------------------------------------------*/
  60. void SystemClock_Config(void);
  61. static void MX_GPIO_Init(void);
  62. static void MX_DMA_Init(void);
  63. static void MX_SPI1_Init(void);
  64. static void MX_USART1_UART_Init(void);
  65. /* USER CODE BEGIN PFP */
  66.  
  67. /* USER CODE END PFP */
  68.  
  69. /* Private user code ---------------------------------------------------------*/
  70. /* USER CODE BEGIN 0 */
  71.  
  72. /* USER CODE END 0 */
  73.  
  74. /**
  75.   * @brief  The application entry point.
  76.   * @retval int
  77.   */
  78. int main(void)
  79. {
  80.   /* USER CODE BEGIN 1 */
  81.  
  82.   /* USER CODE END 1 */
  83.  
  84.  
  85.   /* MCU Configuration--------------------------------------------------------*/
  86.  
  87.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  88.   HAL_Init();
  89.  
  90.   /* USER CODE BEGIN Init */
  91.  
  92.   /* USER CODE END Init */
  93.  
  94.   /* Configure the system clock */
  95.   SystemClock_Config();
  96.  
  97.   /* USER CODE BEGIN SysInit */
  98.  
  99.   /* USER CODE END SysInit */
  100.  
  101.   /* Initialize all configured peripherals */
  102.   MX_GPIO_Init();
  103.   MX_DMA_Init();
  104.   MX_SPI1_Init();
  105.   MX_USART1_UART_Init();
  106.   MX_USB_DEVICE_Init();
  107.   /* USER CODE BEGIN 2 */
  108.  
  109.   /* USER CODE END 2 */
  110.  
  111.   /* Infinite loop */
  112.   /* USER CODE BEGIN WHILE */
  113.   while (1)
  114.   {
  115.     /* USER CODE END WHILE */
  116.  
  117.     /* USER CODE BEGIN 3 */
  118.  
  119.           if(DMX_State == DMX_BREAK)
  120.           {
  121.                   CDC_Transmit_FS("CDC\r\n",5);
  122.                   DMX_State = DMX_IDLE;
  123.           }
  124.     CDC_Transmit_FS("boop\r\n",6);
  125.  
  126.  
  127.  
  128.     sendLeds();
  129.     HAL_Delay(100);
  130.  
  131.   }
  132.   /* USER CODE END 3 */
  133. }
  134.  
  135. /**
  136.   * @brief System Clock Configuration
  137.   * @retval None
  138.   */
  139. void SystemClock_Config(void)
  140. {
  141.   RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  142.   RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  143.   RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
  144.  
  145.   /** Initializes the CPU, AHB and APB busses clocks
  146.   */
  147.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  148.   RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  149.   RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
  150.   RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  151.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  152.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  153.   RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
  154.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  155.   {
  156.     Error_Handler();
  157.   }
  158.   /** Initializes the CPU, AHB and APB busses clocks
  159.   */
  160.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  161.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  162.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  163.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  164.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  165.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  166.  
  167.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  168.   {
  169.     Error_Handler();
  170.   }
  171.   PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB;
  172.   PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLL_DIV1_5;
  173.   if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  174.   {
  175.     Error_Handler();
  176.   }
  177. }
  178.  
  179. /**
  180.   * @brief SPI1 Initialization Function
  181.   * @param None
  182.   * @retval None
  183.   */
  184. static void MX_SPI1_Init(void)
  185. {
  186.  
  187.   /* USER CODE BEGIN SPI1_Init 0 */
  188.  
  189.   /* USER CODE END SPI1_Init 0 */
  190.  
  191.   /* USER CODE BEGIN SPI1_Init 1 */
  192.  
  193.   /* USER CODE END SPI1_Init 1 */
  194.   /* SPI1 parameter configuration*/
  195.   hspi1.Instance = SPI1;
  196.   hspi1.Init.Mode = SPI_MODE_MASTER;
  197.   hspi1.Init.Direction = SPI_DIRECTION_2LINES;
  198.   hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
  199.   hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
  200.   hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
  201.   hspi1.Init.NSS = SPI_NSS_SOFT;
  202.   hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
  203.   hspi1.Init.FirstBit = SPI_FIRSTBIT_LSB;
  204.   hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
  205.   hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  206.   hspi1.Init.CRCPolynomial = 10;
  207.   if (HAL_SPI_Init(&hspi1) != HAL_OK)
  208.   {
  209.     Error_Handler();
  210.   }
  211.   /* USER CODE BEGIN SPI1_Init 2 */
  212.  
  213.   /* USER CODE END SPI1_Init 2 */
  214.  
  215. }
  216.  
  217. /**
  218.   * @brief USART1 Initialization Function
  219.   * @param None
  220.   * @retval None
  221.   */
  222. static void MX_USART1_UART_Init(void)
  223. {
  224.  
  225.   /* USER CODE BEGIN USART1_Init 0 */
  226.  
  227.   /* USER CODE END USART1_Init 0 */
  228.  
  229.   /* USER CODE BEGIN USART1_Init 1 */
  230.  
  231.   /* USER CODE END USART1_Init 1 */
  232.   huart1.Instance = USART1;
  233.   huart1.Init.BaudRate = 115200;
  234.   huart1.Init.WordLength = UART_WORDLENGTH_8B;
  235.   huart1.Init.StopBits = UART_STOPBITS_1;
  236.   huart1.Init.Parity = UART_PARITY_NONE;
  237.   huart1.Init.Mode = UART_MODE_TX_RX;
  238.   huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  239.   huart1.Init.OverSampling = UART_OVERSAMPLING_16;
  240.   if (HAL_UART_Init(&huart1) != HAL_OK)
  241.   {
  242.     Error_Handler();
  243.   }
  244.   /* USER CODE BEGIN USART1_Init 2 */
  245.  
  246.   /* USER CODE END USART1_Init 2 */
  247.  
  248. }
  249.  
  250. /**
  251.   * Enable DMA controller clock
  252.   */
  253. static void MX_DMA_Init(void)
  254. {
  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)
  304. {
  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****/
  313.