├── README.md ├── .gitignore └── sandi_git ├── Inc └── main.h └── Src └── main.c /README.md: -------------------------------------------------------------------------------- 1 | # Github Seminar using STM32F4 2 | 3 | ## 1. Development project setup 4 | * Step 1. Share a CubeMX file 5 | (Download: https://drive.google.com/open?id=1SiMX7OJ5JyCRi0CArCQ2zocnx4352J5t) 6 | * Step 2. Create "Sandi semina" folder 7 | * Step 3. Execute the shared CubeMX file 8 | * Step 4. Save as CubeMX project (Project name: sandi_git) in "Sandi semina" folder (! folders need to be in order of this, 9 | 1. Sandi semina -> 2. sandi_git -> 3. generated codes) 10 | * Step 5. Click "Generate code" button 11 | * Step 6. Delete main.h file in "sandi_git/Inc/" and main.c file "sandi_git/Src/" 12 | * Step 7. Create/init local git repository in "Sandi semina" folder 13 | * Step 8. Set git origin "https://github.com/icns-distributed-cloud/LECTURE-selfdriving.git" 14 | * Step 9. Git pull origin master 15 | 16 | ## 2. Project development 17 | * Step 1. Rasie an issue and create a branch 18 | * Step 2. Pull the branch to local repository 19 | * Step 3. Checkout the branch 20 | * Step 4. Develop functions, modules, or etc. 21 | * Step 5. Git commit 22 | * Step 6. Push the branch 23 | * Step 7. Make "Pull request" 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled source # 2 | ################### 3 | *.com 4 | *.class 5 | *.dll 6 | *.exe 7 | *.o 8 | *.so 9 | *.pyc 10 | 11 | # Packages # 12 | ############ 13 | # it's better to unpack these files and commit the raw source 14 | # git has its own built in compression methods 15 | *.7z 16 | *.dmg 17 | *.gz 18 | *.iso 19 | *.rar 20 | #*.tar 21 | *.zip 22 | 23 | # Logs and databases # 24 | ###################### 25 | *.log 26 | *.sqlite 27 | *.xml 28 | _windows/ 29 | 30 | # OS generated files # 31 | ###################### 32 | .DS_Store 33 | ehthumbs.db 34 | Icon 35 | Thumbs.db 36 | .tmtags 37 | .idea/ 38 | mydjangosite/.idea/ 39 | tags 40 | vendor.tags 41 | tmtagsHistory 42 | *.sublime-project 43 | *.sublime-workspace 44 | .bundle 45 | 46 | # AVR studio files # 47 | #################### 48 | default/ 49 | *.aps 50 | *.aws 51 | 52 | # TrueSTUDIO files # 53 | #################### 54 | .metadata/* 55 | sandi_git/*.* 56 | sandi_git/.setting/* 57 | sandi_git/Drivers/* 58 | sandi_git/Debug/* 59 | sandi_git/Middlewares/* 60 | sandi_git/startup/* 61 | sandi_git/Inc/* 62 | !sandi_git/Inc/main.h 63 | sandi_git/Src/* 64 | !sandi_git/Src/main.c 65 | -------------------------------------------------------------------------------- /sandi_git/Inc/main.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file : main.h 4 | * @brief : Header for main.c file. 5 | * This file contains the common defines of the application. 6 | ****************************************************************************** 7 | * This notice applies to any and all portions of this file 8 | * that are not between comment pairs USER CODE BEGIN and 9 | * USER CODE END. Other portions of this file, whether 10 | * inserted by the user or by software development tools 11 | * are owned by their respective copyright owners. 12 | * 13 | * Copyright (c) 2019 STMicroelectronics International N.V. 14 | * All rights reserved. 15 | * 16 | * Redistribution and use in source and binary forms, with or without 17 | * modification, are permitted, provided that the following conditions are met: 18 | * 19 | * 1. Redistribution of source code must retain the above copyright notice, 20 | * this list of conditions and the following disclaimer. 21 | * 2. Redistributions in binary form must reproduce the above copyright notice, 22 | * this list of conditions and the following disclaimer in the documentation 23 | * and/or other materials provided with the distribution. 24 | * 3. Neither the name of STMicroelectronics nor the names of other 25 | * contributors to this software may be used to endorse or promote products 26 | * derived from this software without specific written permission. 27 | * 4. This software, including modifications and/or derivative works of this 28 | * software, must execute solely and exclusively on microcontroller or 29 | * microprocessor devices manufactured by or for STMicroelectronics. 30 | * 5. Redistribution and use of this software other than as permitted under 31 | * this license is void and will automatically terminate your rights under 32 | * this license. 33 | * 34 | * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" 35 | * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT 36 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 37 | * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY 38 | * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT 39 | * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 40 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 42 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 43 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 44 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 45 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 46 | * 47 | ****************************************************************************** 48 | */ 49 | 50 | /* Define to prevent recursive inclusion -------------------------------------*/ 51 | #ifndef __MAIN_H__ 52 | #define __MAIN_H__ 53 | 54 | /* Includes ------------------------------------------------------------------*/ 55 | #include "stm32f4xx_hal.h" 56 | 57 | /* USER CODE BEGIN Includes */ 58 | 59 | /* USER CODE END Includes */ 60 | 61 | /* Private define ------------------------------------------------------------*/ 62 | 63 | #define CS_I2C_SPI_Pin GPIO_PIN_3 64 | #define CS_I2C_SPI_GPIO_Port GPIOE 65 | #define PC14_OSC32_IN_Pin GPIO_PIN_14 66 | #define PC14_OSC32_IN_GPIO_Port GPIOC 67 | #define PC15_OSC32_OUT_Pin GPIO_PIN_15 68 | #define PC15_OSC32_OUT_GPIO_Port GPIOC 69 | #define PH0_OSC_IN_Pin GPIO_PIN_0 70 | #define PH0_OSC_IN_GPIO_Port GPIOH 71 | #define PH1_OSC_OUT_Pin GPIO_PIN_1 72 | #define PH1_OSC_OUT_GPIO_Port GPIOH 73 | #define OTG_FS_PowerSwitchOn_Pin GPIO_PIN_0 74 | #define OTG_FS_PowerSwitchOn_GPIO_Port GPIOC 75 | #define PDM_OUT_Pin GPIO_PIN_3 76 | #define PDM_OUT_GPIO_Port GPIOC 77 | #define B1_Pin GPIO_PIN_0 78 | #define B1_GPIO_Port GPIOA 79 | #define I2S3_WS_Pin GPIO_PIN_4 80 | #define I2S3_WS_GPIO_Port GPIOA 81 | #define SPI1_SCK_Pin GPIO_PIN_5 82 | #define SPI1_SCK_GPIO_Port GPIOA 83 | #define SPI1_MISO_Pin GPIO_PIN_6 84 | #define SPI1_MISO_GPIO_Port GPIOA 85 | #define SPI1_MOSI_Pin GPIO_PIN_7 86 | #define SPI1_MOSI_GPIO_Port GPIOA 87 | #define BOOT1_Pin GPIO_PIN_2 88 | #define BOOT1_GPIO_Port GPIOB 89 | #define CLK_IN_Pin GPIO_PIN_10 90 | #define CLK_IN_GPIO_Port GPIOB 91 | #define I2S3_MCK_Pin GPIO_PIN_7 92 | #define I2S3_MCK_GPIO_Port GPIOC 93 | #define VBUS_FS_Pin GPIO_PIN_9 94 | #define VBUS_FS_GPIO_Port GPIOA 95 | #define OTG_FS_ID_Pin GPIO_PIN_10 96 | #define OTG_FS_ID_GPIO_Port GPIOA 97 | #define OTG_FS_DM_Pin GPIO_PIN_11 98 | #define OTG_FS_DM_GPIO_Port GPIOA 99 | #define OTG_FS_DP_Pin GPIO_PIN_12 100 | #define OTG_FS_DP_GPIO_Port GPIOA 101 | #define SWDIO_Pin GPIO_PIN_13 102 | #define SWDIO_GPIO_Port GPIOA 103 | #define SWCLK_Pin GPIO_PIN_14 104 | #define SWCLK_GPIO_Port GPIOA 105 | #define I2S3_SCK_Pin GPIO_PIN_10 106 | #define I2S3_SCK_GPIO_Port GPIOC 107 | #define I2S3_SD_Pin GPIO_PIN_12 108 | #define I2S3_SD_GPIO_Port GPIOC 109 | #define Audio_RST_Pin GPIO_PIN_4 110 | #define Audio_RST_GPIO_Port GPIOD 111 | #define OTG_FS_OverCurrent_Pin GPIO_PIN_5 112 | #define OTG_FS_OverCurrent_GPIO_Port GPIOD 113 | #define SWO_Pin GPIO_PIN_3 114 | #define SWO_GPIO_Port GPIOB 115 | #define Audio_SCL_Pin GPIO_PIN_6 116 | #define Audio_SCL_GPIO_Port GPIOB 117 | #define Audio_SDA_Pin GPIO_PIN_9 118 | #define Audio_SDA_GPIO_Port GPIOB 119 | #define MEMS_INT2_Pin GPIO_PIN_1 120 | #define MEMS_INT2_GPIO_Port GPIOE 121 | 122 | /* ########################## Assert Selection ############################## */ 123 | /** 124 | * @brief Uncomment the line below to expanse the "assert_param" macro in the 125 | * HAL drivers code 126 | */ 127 | /* #define USE_FULL_ASSERT 1U */ 128 | 129 | /* USER CODE BEGIN Private defines */ 130 | 131 | /* USER CODE END Private defines */ 132 | 133 | #ifdef __cplusplus 134 | extern "C" { 135 | #endif 136 | void _Error_Handler(char *, int); 137 | 138 | #define Error_Handler() _Error_Handler(__FILE__, __LINE__) 139 | #ifdef __cplusplus 140 | } 141 | #endif 142 | 143 | #endif /* __MAIN_H__ */ 144 | 145 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 146 | -------------------------------------------------------------------------------- /sandi_git/Src/main.c: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | ****************************************************************************** 4 | * @file : main.c 5 | * @brief : Main program body 6 | ****************************************************************************** 7 | * This notice applies to any and all portions of this file 8 | * that are not between comment pairs USER CODE BEGIN and 9 | * USER CODE END. Other portions of this file, whether 10 | * inserted by the user or by software development tools 11 | * are owned by their respective copyright owners. 12 | * 13 | * Copyright (c) 2019 STMicroelectronics International N.V. 14 | * All rights reserved. 15 | * 16 | * Redistribution and use in source and binary forms, with or without 17 | * modification, are permitted, provided that the following conditions are met: 18 | * 19 | * 1. Redistribution of source code must retain the above copyright notice, 20 | * this list of conditions and the following disclaimer. 21 | * 2. Redistributions in binary form must reproduce the above copyright notice, 22 | * this list of conditions and the following disclaimer in the documentation 23 | * and/or other materials provided with the distribution. 24 | * 3. Neither the name of STMicroelectronics nor the names of other 25 | * contributors to this software may be used to endorse or promote products 26 | * derived from this software without specific written permission. 27 | * 4. This software, including modifications and/or derivative works of this 28 | * software, must execute solely and exclusively on microcontroller or 29 | * microprocessor devices manufactured by or for STMicroelectronics. 30 | * 5. Redistribution and use of this software other than as permitted under 31 | * this license is void and will automatically terminate your rights under 32 | * this license. 33 | * 34 | * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" 35 | * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT 36 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 37 | * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY 38 | * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT 39 | * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 40 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 42 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 43 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 44 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 45 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 46 | * 47 | ****************************************************************************** 48 | */ 49 | /* Includes ------------------------------------------------------------------*/ 50 | #include "main.h" 51 | #include "stm32f4xx_hal.h" 52 | #include "adc.h" 53 | #include "dma.h" 54 | #include "i2c.h" 55 | #include "i2s.h" 56 | #include "spi.h" 57 | #include "tim.h" 58 | #include "usart.h" 59 | #include "usb_host.h" 60 | #include "gpio.h" 61 | 62 | /* USER CODE BEGIN Includes */ 63 | #include 64 | #include 65 | #include 66 | #include "stm32f4xx_it.h" 67 | /* USER CODE END Includes */ 68 | 69 | /* Private variables ---------------------------------------------------------*/ 70 | 71 | /* USER CODE BEGIN PV */ 72 | /* Private variables ---------------------------------------------------------*/ 73 | char Buf1[4]; 74 | char Buf2[4]; 75 | int cntLast; 76 | char rx; 77 | char enter1=13; 78 | char enter2=10; 79 | char space=32; 80 | 81 | /********VELOCITY NORMALIZATION********/ 82 | int W1_MIN = 600; // Left_Motor Initial Velocity 83 | int W2_MIN = 600; // Right_Motor Initial Velocity 84 | #define RANGE_MAX 60 85 | int n_v1, n_v2; // Normalized Velocity Value 86 | int norm1,norm2; 87 | int diff1,diff2; // For Normalization 88 | int diff_w1, diff_w2; 89 | int diff; 90 | //volatile int canRun = 0; 91 | /***************PSD Normalization********************/ 92 | #define PSD_MIN 0 93 | #define PSD_MAX 900 94 | #define Default_Speed 600 95 | uint16_t PSDL[1]; 96 | uint16_t PSDR[1]; 97 | uint16_t SideLPSD = 0; 98 | uint16_t SideRPSD = 0; 99 | int PSDdiff1; 100 | int PSDdiff2; 101 | uint16_t adcval[2]; 102 | 103 | /***********FOR DELAY_US FUNC**********/ 104 | #define Delay_ms HAL_Delay 105 | #define millis() HAL_GetTick() 106 | #define SYS_CLOCK 168 107 | #define SYSTICK_LOAD 167999 108 | __IO uint32_t uwTick=0; 109 | extern __IO uint32_t uwTick; 110 | 111 | /**********filter var*****************/ 112 | 113 | int temp_psd1[3] = {0}; 114 | int temp_psd2[3] = {0}; 115 | 116 | int result_psd1 = 0; 117 | int result_psd2 = 0; 118 | 119 | unsigned int pc = 0; 120 | 121 | 122 | /* USER CODE END PV */ 123 | 124 | /* Private function prototypes -----------------------------------------------*/ 125 | void SystemClock_Config(void); 126 | void MX_USB_HOST_Process(void); 127 | 128 | /* USER CODE BEGIN PFP */ 129 | /* Private function prototypes -----------------------------------------------*/ 130 | 131 | /* USER CODE END PFP */ 132 | 133 | /* USER CODE BEGIN 0 */ 134 | uint32_t micros() { 135 | return (uwTick&0x3FFFFF)*1000 + (SYSTICK_LOAD-SysTick->VAL)/SYS_CLOCK; 136 | } 137 | 138 | void Delay_us(uint32_t us) { 139 | uint32_t temp = micros(); 140 | uint32_t comp = temp + us; 141 | uint8_t flag = 0; 142 | while(comp > temp){ 143 | if(((uwTick&0x3FFFFF)==0)&&(flag==0)){ 144 | flag = 1; 145 | } 146 | if(flag) temp = micros() + 0x400000UL * 1000; 147 | else temp = micros(); 148 | } 149 | } 150 | void SCI_OutString(char *pt) 151 | { 152 | char letter; 153 | while((letter = *pt++)){ 154 | HAL_UART_Transmit(&huart3,&letter, 1,10); 155 | //SCI_OutChar(letter); 156 | } 157 | } 158 | void SCI_OutChar(char letter) 159 | { 160 | HAL_UART_Transmit(&huart3,&letter, 1,10); 161 | } 162 | void PSD(){ 163 | 164 | // Read PSD left and right 165 | PSDL[0] = adcval[0]; 166 | PSDR[0] = adcval[1]; 167 | 168 | // Threshold mix and max 169 | if(PSDL[0] > PSD_MAX) 170 | PSDL[0] = PSD_MAX; 171 | if(PSDR[0] > PSD_MAX) 172 | PSDR[0] = PSD_MAX; 173 | 174 | // Filtering 175 | psd_mean_filter1(); 176 | 177 | // Calc difference 178 | //if(canRun){ 179 | diff = 5 * (result_psd1 - result_psd2); 180 | 181 | // Driving 182 | PSDdiff1 = 550 + diff; 183 | PSDdiff2 = 550 - diff; 184 | 185 | // Threshold motor input 186 | if(PSDdiff1>1000) PSDdiff1 = 1000; 187 | else if(PSDdiff1<500) PSDdiff1 = 500; 188 | 189 | if(PSDdiff2>1000) PSDdiff2 = 1000; 190 | else if(PSDdiff2<500) PSDdiff2 = 500; 191 | 192 | // Input PWM 193 | TIM3->CCR1 = PSDdiff1; 194 | TIM3->CCR2 = PSDdiff2; 195 | 196 | //} 197 | } 198 | 199 | /* USER CODE END 0 */ 200 | 201 | /** 202 | * @brief The application entry point. 203 | * 204 | * @retval None 205 | */ 206 | 207 | void psd_mean_filter1() 208 | { 209 | 210 | temp_psd1[pc] = PSDL[0]; 211 | temp_psd2[pc] = PSDR[0]; 212 | 213 | //if(temp_psd1[0] && temp_psd1[1] && temp_psd1[2]) 214 | //{ 215 | result_psd1 = (temp_psd1[0] + temp_psd1[1] + temp_psd1[2])/3; 216 | result_psd2 = (temp_psd2[0] + temp_psd2[1] + temp_psd2[2])/3; 217 | // canRun = 1; 218 | //} 219 | 220 | pc=(pc++)%3; 221 | 222 | 223 | } 224 | 225 | int main(void) 226 | { 227 | /* USER CODE BEGIN 1 */ 228 | 229 | /* USER CODE END 1 */ 230 | 231 | /* MCU Configuration----------------------------------------------------------*/ 232 | 233 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ 234 | HAL_Init(); 235 | 236 | /* USER CODE BEGIN Init */ 237 | 238 | /* USER CODE END Init */ 239 | 240 | /* Configure the system clock */ 241 | SystemClock_Config(); 242 | 243 | /* USER CODE BEGIN SysInit */ 244 | 245 | /* USER CODE END SysInit */ 246 | 247 | /* Initialize all configured peripherals */ 248 | MX_GPIO_Init(); 249 | MX_DMA_Init(); 250 | MX_I2C1_Init(); 251 | MX_I2S3_Init(); 252 | MX_SPI1_Init(); 253 | MX_USB_HOST_Init(); 254 | MX_TIM3_Init(); 255 | MX_USART3_UART_Init(); 256 | MX_ADC1_Init(); 257 | diff=0; 258 | /* USER CODE BEGIN 2 */ 259 | 260 | //Initialize for PSD 261 | 262 | HAL_ADC_Start_DMA(&hadc1,&adcval[0],2); 263 | 264 | //Initialize for motor PWN 265 | HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1); 266 | HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2); 267 | 268 | //Initialize for motor direction 269 | HAL_GPIO_WritePin(GPIOD, GPIO_PIN_10, SET); 270 | HAL_GPIO_WritePin(GPIOD, GPIO_PIN_11, RESET); 271 | HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12, SET); 272 | HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, RESET); 273 | 274 | 275 | /* USER CODE END 2 */ 276 | 277 | /* Infinite loop */ 278 | /* USER CODE BEGIN WHILE */ 279 | while (1) 280 | { 281 | 282 | /* USER CODE END WHILE */ 283 | MX_USB_HOST_Process(); 284 | PSD(); 285 | 286 | /* USER CODE BEGIN 3 */ 287 | 288 | } 289 | /* USER CODE END 3 */ 290 | 291 | } 292 | 293 | /** 294 | * @brief System Clock Configuration 295 | * @retval None 296 | */ 297 | void SystemClock_Config(void) 298 | { 299 | 300 | RCC_OscInitTypeDef RCC_OscInitStruct; 301 | RCC_ClkInitTypeDef RCC_ClkInitStruct; 302 | RCC_PeriphCLKInitTypeDef PeriphClkInitStruct; 303 | 304 | /**Configure the main internal regulator output voltage 305 | */ 306 | __HAL_RCC_PWR_CLK_ENABLE(); 307 | 308 | __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); 309 | 310 | /**Initializes the CPU, AHB and APB busses clocks 311 | */ 312 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; 313 | RCC_OscInitStruct.HSEState = RCC_HSE_ON; 314 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; 315 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; 316 | RCC_OscInitStruct.PLL.PLLM = 8; 317 | RCC_OscInitStruct.PLL.PLLN = 336; 318 | RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; 319 | RCC_OscInitStruct.PLL.PLLQ = 7; 320 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) 321 | { 322 | _Error_Handler(__FILE__, __LINE__); 323 | } 324 | 325 | /**Initializes the CPU, AHB and APB busses clocks 326 | */ 327 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK 328 | |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; 329 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; 330 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; 331 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; 332 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; 333 | 334 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK) 335 | { 336 | _Error_Handler(__FILE__, __LINE__); 337 | } 338 | 339 | PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_I2S; 340 | PeriphClkInitStruct.PLLI2S.PLLI2SN = 192; 341 | PeriphClkInitStruct.PLLI2S.PLLI2SR = 2; 342 | if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) 343 | { 344 | _Error_Handler(__FILE__, __LINE__); 345 | } 346 | 347 | /**Configure the Systick interrupt time 348 | */ 349 | HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); 350 | 351 | /**Configure the Systick 352 | */ 353 | HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); 354 | 355 | /* SysTick_IRQn interrupt configuration */ 356 | HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); 357 | } 358 | 359 | /* USER CODE BEGIN 4 */ 360 | 361 | /* USER CODE END 4 */ 362 | 363 | /** 364 | * @brief This function is executed in case of error occurrence. 365 | * @param file: The file name as string. 366 | * @param line: The line in file as a number. 367 | * @retval None 368 | */ 369 | void _Error_Handler(char *file, int line) 370 | { 371 | /* USER CODE BEGIN Error_Handler_Debug */ 372 | /* User can add his own implementation to report the HAL error return state */ 373 | while(1) 374 | { 375 | } 376 | /* USER CODE END Error_Handler_Debug */ 377 | } 378 | 379 | #ifdef USE_FULL_ASSERT 380 | /** 381 | * @brief Reports the name of the source file and the source line number 382 | * where the assert_param error has occurred. 383 | * @param file: pointer to the source file name 384 | * @param line: assert_param error line source number 385 | * @retval None 386 | */ 387 | void assert_failed(uint8_t* file, uint32_t line) 388 | { 389 | /* USER CODE BEGIN 6 */ 390 | /* User can add his own implementation to report the file name and line number, 391 | tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 392 | /* USER CODE END 6 */ 393 | } 394 | #endif /* USE_FULL_ASSERT */ 395 | 396 | /** 397 | * @} 398 | */ 399 | 400 | /** 401 | * @} 402 | */ 403 | 404 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 405 | --------------------------------------------------------------------------------