@@ -170,69 +170,69 @@ extern "C" {
170170#endif
171171
172172uint32_t myvar[] = {1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 };
173- void myshow (int fre,int times)// YSZ-WORK
173+ void myshow (int fre, int times) // YSZ-WORK
174174{
175175 uint32_t index = 10 ;
176- RCC->AHB1ENR |= 1 << 6 ;// 端口G时钟
177- GPIOG->MODER &= ~(3UL << 2 * index);// 清除旧模式
178- GPIOG->MODER |= 1 << 2 * index;// 模式为输出
179- GPIOG->OSPEEDR &= ~(3UL << 2 * index); // 清除旧输出速度
180- GPIOG->OSPEEDR |= 2 << 2 * index;// 设置输出速度
181- GPIOG->OTYPER &= ~(1UL << index); // 清除旧输出方式
182- GPIOG->OTYPER |= 0 << index;// 设置输出方式为推挽
183- GPIOG->PUPDR &= ~(3 << 2 * index); // 先清除原来的设置
184- GPIOG->PUPDR |= 1 << 2 * index;// 设置新的上下拉
185- while (times != 0 ) {
176+ RCC->AHB1ENR |= 1 << 6 ; // port G clock
177+ GPIOG->MODER &= ~(3UL << 2 * index); // clear old mode
178+ GPIOG->MODER |= 1 << 2 * index; // mode is output
179+ GPIOG->OSPEEDR &= ~(3UL << 2 * index) // Clear old output speed
180+ GPIOG->OSPEEDR |= 2 << 2 * index; // Set output speed
181+ GPIOG->OTYPER &= ~(1UL << index) // clear old output
182+ GPIOG->OTYPER |= 0 << index; // Set the output mode to push-pull
183+ GPIOG->PUPDR &= ~(3 << 2 * index) // Clear the original settings first
184+ GPIOG->PUPDR |= 1 << 2 * index; // Set new up and down
185+ while (times != 0 ) {
186186 GPIOG->BSRR = 1UL << index;
187- for (int i = 0 ;i < fre; i++)
188- for (int j = 0 ; j < 1000000 ; j++)__NOP ();
187+ for (int i = 0 ; i < fre; i++)
188+ for (int j = 0 ; j < 1000000 ; j++) __NOP ();
189189 GPIOG->BSRR = 1UL << (index + 16 );
190- for (int i = 0 ;i < fre; i++)
191- for (int j = 0 ; j < 1000000 ; j++)__NOP ();
192- if (times > 0 )times--;
190+ for (int i = 0 ; i < fre; i++)
191+ for (int j = 0 ; j < 1000000 ; j++) __NOP ();
192+ if (times > 0 ) times--;
193193 }
194194}
195195
196196HAL_StatusTypeDef SDMMC_IsProgramming (SDIO_TypeDef *SDIOx,uint32_t RCA)
197197{
198198 HAL_SD_CardStateTypeDef CardState;
199- volatile uint32_t respR1 = 0 , status = 0 ;
200- SDIO_CmdInitTypeDef sdmmc_cmdinit;
199+ volatile uint32_t respR1 = 0 , status = 0 ;
200+ SDIO_CmdInitTypeDef sdmmc_cmdinit;
201201 do {
202202 sdmmc_cmdinit.Argument = RCA << 16 ;
203203 sdmmc_cmdinit.CmdIndex = SDMMC_CMD_SEND_STATUS;
204204 sdmmc_cmdinit.Response = SDIO_RESPONSE_SHORT;
205205 sdmmc_cmdinit.WaitForInterrupt = SDIO_WAIT_NO;
206206 sdmmc_cmdinit.CPSM = SDIO_CPSM_ENABLE;
207- SDIO_SendCommand (SDIOx,&sdmmc_cmdinit);// 发送CMD13
207+ SDIO_SendCommand (SDIOx,&sdmmc_cmdinit); // send CMD13
208208 do status = SDIOx->STA ;
209- while (!(status & ((1 << 0 ) | (1 << 6 ) | (1 << 2 ))));// 等待操作完成
210- if (status & (1 << 0 )) // CRC检测失败
211- {
212- SDIOx->ICR |= 1 << 0 ; // 清除错误标记
209+ while (!(status & ((1 << 0 ) | (1 << 6 ) | (1 << 2 )))); // wait for the operation to complete
210+ if (status & (1 << 0 )) { // CRC check failed
211+ SDIOx->ICR |= 1 << 0 ; // clear error flag
213212 return HAL_ERROR;
214213 }
215- if (status & (1 << 2 )) // 命令超时
216- {
217- SDIOx->ICR |= 1 << 2 ; // 清除错误标记
214+ if (status & (1 << 2 )) { // command timed out
215+ SDIOx->ICR |= 1 << 2 ; // clear error flag
218216 return HAL_ERROR;
219217 }
220- if (SDIOx->RESPCMD != SDMMC_CMD_SEND_STATUS)return HAL_ERROR;
221- SDIOx->ICR = 0X5FF ; // 清除所有标记
218+ if (SDIOx->RESPCMD != SDMMC_CMD_SEND_STATUS) return HAL_ERROR;
219+ SDIOx->ICR = 0X5FF ; // clear all tags
222220 respR1 = SDIOx->RESP1 ;
223221 CardState = (respR1 >> 9 ) & 0x0000000F ;
224- }while ((CardState == HAL_SD_CARD_RECEIVING) || (CardState == HAL_SD_CARD_SENDING) || (CardState == HAL_SD_CARD_PROGRAMMING));
222+ } while ((CardState == HAL_SD_CARD_RECEIVING) || (CardState == HAL_SD_CARD_SENDING) || (CardState == HAL_SD_CARD_PROGRAMMING));
225223 return HAL_OK;
226224}
227- void debugStr (const char *str) {
228- while (*str) {
229- while ((USART1->SR & 0x40 ) == 0 );
230- USART1->DR = *str++;
231- }
225+
226+ void debugStr (const char *str) {
227+ while (*str) {
228+ while ((USART1->SR & 0x40 ) == 0 );
229+ USART1->DR = *str++;
230+ }
232231}
232+
233233/* *
234234 * @brief System Clock Configuration
235- * The system Clock is configured as follow :
235+ * The system Clock is configured as follows :
236236 * System Clock source = PLL (HSE)
237237 * SYSCLK(Hz) = 168000000/120000000/180000000
238238 * HCLK(Hz) = 168000000/120000000/180000000
@@ -265,8 +265,8 @@ WEAK void SystemClock_Config(void)
265265 /* Enable Power Control clock */
266266 __HAL_RCC_PWR_CLK_ENABLE ();
267267
268- /* The voltage scaling allows optimizing the power consumption when the device is
269- clocked below the maximum system frequency, to update the voltage scaling value
268+ /* The voltage scaling allows optimizing the power consumption when the device is
269+ clocked below the maximum system frequency, to update the voltage scaling value
270270 regarding system frequency refer to product datasheet. */
271271 __HAL_PWR_VOLTAGESCALING_CONFIG (PWR_REGULATOR_VOLTAGE_SCALE1);
272272
@@ -281,42 +281,40 @@ WEAK void SystemClock_Config(void)
281281 RCC_OscInitStruct.PLL .PLLQ = 7 ;
282282 RCC_OscInitStruct.PLL .PLLR = 2 ;
283283 ret = HAL_RCC_OscConfig (&RCC_OscInitStruct);
284-
285- if (ret != HAL_OK)myshow (10 ,-1 );
284+
285+ if (ret != HAL_OK) myshow (10 ,-1 );
286286 HAL_PWREx_EnableOverDrive ();
287-
287+
288288 /* Select PLLSAI output as USB clock source */
289289 PeriphClkInitStruct.PLLSAI .PLLSAIM = 8 ;
290290 PeriphClkInitStruct.PLLSAI .PLLSAIN = 192 ;
291291 PeriphClkInitStruct.PLLSAI .PLLSAIP = RCC_PLLSAIP_DIV4;
292292 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_CLK48 | RCC_PERIPHCLK_SDIO;
293293 PeriphClkInitStruct.Clk48ClockSelection = RCC_CK48CLKSOURCE_PLLSAIP;
294- PeriphClkInitStruct.SdioClockSelection = RCC_SDIOCLKSOURCE_CLK48;// SDIO Clock Mux
294+ PeriphClkInitStruct.SdioClockSelection = RCC_SDIOCLKSOURCE_CLK48; // SDIO Clock Mux
295295 HAL_RCCEx_PeriphCLKConfig (&PeriphClkInitStruct);
296296
297- /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
298- clocks dividers */
297+ /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */
299298 RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
300299 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
301300 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
302- RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
303- RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
301+ RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
302+ RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
304303 ret = HAL_RCC_ClockConfig (&RCC_ClkInitStruct, FLASH_LATENCY_5);
305- if (ret != HAL_OK)myshow (10 ,-1 );
304+ if (ret != HAL_OK) myshow (10 ,-1 );
306305
307- SystemCoreClockUpdate ();// 更新系统时钟SystemCoreClock
308- /* *Configure the Systick interrupt time
309- */
306+ SystemCoreClockUpdate ();
307+ /* Configure the Systick interrupt time */
310308 HAL_SYSTICK_Config (HAL_RCC_GetHCLKFreq () / 1000 );
311309
312- /* *Configure the Systick
313- */
310+ /* Configure the Systick */
314311 HAL_SYSTICK_CLKSourceConfig (SYSTICK_CLKSOURCE_HCLK);
315312
316313 /* SysTick_IRQn interrupt configuration */
317314 HAL_NVIC_SetPriority (SysTick_IRQn, 0 , 0 );
318- __enable_irq ();// 打开中断,因为在bootloader中关闭了,所以这里要打开
315+ __enable_irq (); // Turn on the interrupt here because it is turned off in the bootloader
319316}
317+
320318#ifdef __cplusplus
321319}
322320#endif
0 commit comments