Rev 4 | 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 | * 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 "display.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 | SPI_HandleTypeDef hspi1; |
||
| 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_SPI1_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_SPI1_Init(); |
||
| 90 | /* USER CODE BEGIN 2 */ |
||
| 91 | cc_init(); |
||
| 92 | /* USER CODE END 2 */ |
||
| 93 | |||
| 94 | /* Infinite loop */ |
||
| 95 | /* USER CODE BEGIN WHILE */ |
||
| 96 | while (1) |
||
| 97 | { |
||
| 98 | cc_display(0); |
||
| 99 | /* USER CODE END WHILE */ |
||
| 100 | |||
| 101 | /* USER CODE BEGIN 3 */ |
||
| 102 | |||
| 103 | } |
||
| 104 | /* USER CODE END 3 */ |
||
| 105 | } |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @brief System Clock Configuration |
||
| 109 | * @retval None |
||
| 110 | */ |
||
| 111 | void SystemClock_Config(void) |
||
| 112 | { |
||
| 113 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; |
||
| 114 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; |
||
| 115 | |||
| 116 | /** Initializes the RCC Oscillators according to the specified parameters |
||
| 117 | * in the RCC_OscInitTypeDef structure. |
||
| 118 | */ |
||
| 119 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; |
||
| 120 | RCC_OscInitStruct.HSEState = RCC_HSE_ON; |
||
| 121 | RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; |
||
| 122 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; |
||
| 123 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
||
| 124 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; |
||
| 125 | RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; |
||
| 126 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
||
| 127 | { |
||
| 128 | Error_Handler(); |
||
| 129 | } |
||
| 130 | |||
| 131 | /** Initializes the CPU, AHB and APB buses clocks |
||
| 132 | */ |
||
| 133 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |
||
| 134 | |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; |
||
| 135 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
||
| 136 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
||
| 137 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; |
||
| 138 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; |
||
| 139 | |||
| 140 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) |
||
| 141 | { |
||
| 142 | Error_Handler(); |
||
| 143 | } |
||
| 144 | } |
||
| 145 | |||
| 146 | /** |
||
| 147 | * @brief SPI1 Initialization Function |
||
| 148 | * @param None |
||
| 149 | * @retval None |
||
| 150 | */ |
||
| 151 | static void MX_SPI1_Init(void) |
||
| 152 | { |
||
| 153 | |||
| 154 | /* USER CODE BEGIN SPI1_Init 0 */ |
||
| 155 | |||
| 156 | /* USER CODE END SPI1_Init 0 */ |
||
| 157 | |||
| 158 | /* USER CODE BEGIN SPI1_Init 1 */ |
||
| 159 | |||
| 160 | /* USER CODE END SPI1_Init 1 */ |
||
| 161 | /* SPI1 parameter configuration*/ |
||
| 162 | hspi1.Instance = SPI1; |
||
| 163 | hspi1.Init.Mode = SPI_MODE_MASTER; |
||
| 164 | hspi1.Init.Direction = SPI_DIRECTION_2LINES; |
||
| 165 | hspi1.Init.DataSize = SPI_DATASIZE_8BIT; |
||
| 166 | hspi1.Init.CLKPolarity = SPI_POLARITY_LOW; |
||
| 167 | hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; |
||
| 168 | hspi1.Init.NSS = SPI_NSS_SOFT; |
||
| 169 | hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64; |
||
| 170 | hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; |
||
| 171 | hspi1.Init.TIMode = SPI_TIMODE_DISABLE; |
||
| 172 | hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; |
||
| 173 | hspi1.Init.CRCPolynomial = 10; |
||
| 174 | if (HAL_SPI_Init(&hspi1) != HAL_OK) |
||
| 175 | { |
||
| 176 | Error_Handler(); |
||
| 177 | } |
||
| 178 | /* USER CODE BEGIN SPI1_Init 2 */ |
||
| 179 | |||
| 180 | /* USER CODE END SPI1_Init 2 */ |
||
| 181 | |||
| 182 | } |
||
| 183 | |||
| 184 | /** |
||
| 185 | * @brief GPIO Initialization Function |
||
| 186 | * @param None |
||
| 187 | * @retval None |
||
| 188 | */ |
||
| 189 | static void MX_GPIO_Init(void) |
||
| 190 | { |
||
| 191 | GPIO_InitTypeDef GPIO_InitStruct = {0}; |
||
| 192 | |||
| 193 | /* GPIO Ports Clock Enable */ |
||
| 194 | __HAL_RCC_GPIOD_CLK_ENABLE(); |
||
| 195 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
||
| 196 | __HAL_RCC_GPIOB_CLK_ENABLE(); |
||
| 197 | |||
| 198 | /*Configure GPIO pin Output Level */ |
||
| 199 | HAL_GPIO_WritePin(GPIOA, SPI_NSS1_Pin|SPI_RESET_Pin, GPIO_PIN_RESET); |
||
| 200 | |||
| 201 | /*Configure GPIO pin Output Level */ |
||
| 202 | HAL_GPIO_WritePin(SPI_CD_GPIO_Port, SPI_CD_Pin, GPIO_PIN_RESET); |
||
| 203 | |||
| 204 | /*Configure GPIO pins : SPI_NSS1_Pin SPI_RESET_Pin */ |
||
| 205 | GPIO_InitStruct.Pin = SPI_NSS1_Pin|SPI_RESET_Pin; |
||
| 206 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
||
| 207 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
||
| 208 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
||
| 209 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
||
| 210 | |||
| 211 | /*Configure GPIO pin : SPI_CD_Pin */ |
||
| 212 | GPIO_InitStruct.Pin = SPI_CD_Pin; |
||
| 213 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
||
| 214 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
||
| 215 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
||
| 216 | HAL_GPIO_Init(SPI_CD_GPIO_Port, &GPIO_InitStruct); |
||
| 217 | |||
| 218 | } |
||
| 219 | |||
| 220 | /* USER CODE BEGIN 4 */ |
||
| 221 | |||
| 222 | /* USER CODE END 4 */ |
||
| 223 | |||
| 224 | /** |
||
| 225 | * @brief This function is executed in case of error occurrence. |
||
| 226 | * @retval None |
||
| 227 | */ |
||
| 228 | void Error_Handler(void) |
||
| 229 | { |
||
| 230 | /* USER CODE BEGIN Error_Handler_Debug */ |
||
| 231 | /* User can add his own implementation to report the HAL error return state */ |
||
| 232 | __disable_irq(); |
||
| 233 | while (1) |
||
| 234 | { |
||
| 235 | } |
||
| 236 | /* USER CODE END Error_Handler_Debug */ |
||
| 237 | } |
||
| 238 | |||
| 239 | #ifdef USE_FULL_ASSERT |
||
| 240 | /** |
||
| 241 | * @brief Reports the name of the source file and the source line number |
||
| 242 | * where the assert_param error has occurred. |
||
| 243 | * @param file: pointer to the source file name |
||
| 244 | * @param line: assert_param error line source number |
||
| 245 | * @retval None |
||
| 246 | */ |
||
| 247 | void assert_failed(uint8_t *file, uint32_t line) |
||
| 248 | { |
||
| 249 | /* USER CODE BEGIN 6 */ |
||
| 250 | /* User can add his own implementation to report the file name and line number, |
||
| 251 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
||
| 252 | /* USER CODE END 6 */ |
||
| 253 | } |
||
| 254 | #endif /* USE_FULL_ASSERT */ |