|
@@ -170,69 +170,69 @@ extern "C" {
|
170
|
170
|
#endif
|
171
|
171
|
|
172
|
172
|
uint32_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
|
174
|
174
|
{
|
175
|
175
|
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) {
|
186
|
186
|
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();
|
189
|
189
|
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--;
|
193
|
193
|
}
|
194
|
194
|
}
|
195
|
195
|
|
196
|
196
|
HAL_StatusTypeDef SDMMC_IsProgramming(SDIO_TypeDef *SDIOx,uint32_t RCA)
|
197
|
197
|
{
|
198
|
198
|
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;
|
201
|
201
|
do {
|
202
|
202
|
sdmmc_cmdinit.Argument = RCA << 16;
|
203
|
203
|
sdmmc_cmdinit.CmdIndex = SDMMC_CMD_SEND_STATUS;
|
204
|
204
|
sdmmc_cmdinit.Response = SDIO_RESPONSE_SHORT;
|
205
|
205
|
sdmmc_cmdinit.WaitForInterrupt = SDIO_WAIT_NO;
|
206
|
206
|
sdmmc_cmdinit.CPSM = SDIO_CPSM_ENABLE;
|
207
|
|
- SDIO_SendCommand(SDIOx,&sdmmc_cmdinit);//发送CMD13
|
|
207
|
+ SDIO_SendCommand(SDIOx,&sdmmc_cmdinit); // send CMD13
|
208
|
208
|
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
|
213
|
212
|
return HAL_ERROR;
|
214
|
213
|
}
|
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
|
218
|
216
|
return HAL_ERROR;
|
219
|
217
|
}
|
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
|
222
|
220
|
respR1 = SDIOx->RESP1;
|
223
|
221
|
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));
|
225
|
223
|
return HAL_OK;
|
226
|
224
|
}
|
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
|
+ }
|
232
|
231
|
}
|
|
232
|
+
|
233
|
233
|
/**
|
234
|
234
|
* @brief System Clock Configuration
|
235
|
|
- * The system Clock is configured as follow :
|
|
235
|
+ * The system Clock is configured as follows:
|
236
|
236
|
* System Clock source = PLL (HSE)
|
237
|
237
|
* SYSCLK(Hz) = 168000000/120000000/180000000
|
238
|
238
|
* HCLK(Hz) = 168000000/120000000/180000000
|
|
@@ -265,8 +265,8 @@ WEAK void SystemClock_Config(void)
|
265
|
265
|
/* Enable Power Control clock */
|
266
|
266
|
__HAL_RCC_PWR_CLK_ENABLE();
|
267
|
267
|
|
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
|
270
|
270
|
regarding system frequency refer to product datasheet. */
|
271
|
271
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
|
272
|
272
|
|
|
@@ -281,42 +281,40 @@ WEAK void SystemClock_Config(void)
|
281
|
281
|
RCC_OscInitStruct.PLL.PLLQ = 7;
|
282
|
282
|
RCC_OscInitStruct.PLL.PLLR = 2;
|
283
|
283
|
ret = HAL_RCC_OscConfig(&RCC_OscInitStruct);
|
284
|
|
-
|
285
|
|
- if(ret != HAL_OK)myshow(10,-1);
|
|
284
|
+
|
|
285
|
+ if (ret != HAL_OK) myshow(10,-1);
|
286
|
286
|
HAL_PWREx_EnableOverDrive();
|
287
|
|
-
|
|
287
|
+
|
288
|
288
|
/* Select PLLSAI output as USB clock source */
|
289
|
289
|
PeriphClkInitStruct.PLLSAI.PLLSAIM = 8;
|
290
|
290
|
PeriphClkInitStruct.PLLSAI.PLLSAIN = 192;
|
291
|
291
|
PeriphClkInitStruct.PLLSAI.PLLSAIP = RCC_PLLSAIP_DIV4;
|
292
|
292
|
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_CLK48 | RCC_PERIPHCLK_SDIO;
|
293
|
293
|
PeriphClkInitStruct.Clk48ClockSelection = RCC_CK48CLKSOURCE_PLLSAIP;
|
294
|
|
- PeriphClkInitStruct.SdioClockSelection = RCC_SDIOCLKSOURCE_CLK48;//SDIO Clock Mux
|
|
294
|
+ PeriphClkInitStruct.SdioClockSelection = RCC_SDIOCLKSOURCE_CLK48; // SDIO Clock Mux
|
295
|
295
|
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
|
296
|
296
|
|
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 */
|
299
|
298
|
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
|
300
|
299
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
301
|
300
|
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;
|
304
|
303
|
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);
|
306
|
305
|
|
307
|
|
- SystemCoreClockUpdate();//更新系统时钟SystemCoreClock
|
308
|
|
- /**Configure the Systick interrupt time
|
309
|
|
- */
|
|
306
|
+ SystemCoreClockUpdate();
|
|
307
|
+ /* Configure the Systick interrupt time */
|
310
|
308
|
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000);
|
311
|
309
|
|
312
|
|
- /**Configure the Systick
|
313
|
|
- */
|
|
310
|
+ /* Configure the Systick */
|
314
|
311
|
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
|
315
|
312
|
|
316
|
313
|
/* SysTick_IRQn interrupt configuration */
|
317
|
314
|
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
|
319
|
316
|
}
|
|
317
|
+
|
320
|
318
|
#ifdef __cplusplus
|
321
|
319
|
}
|
322
|
320
|
#endif
|