找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1621|回复: 1
收起左侧

STM32F429_USB项目源程序 hal库

[复制链接]
ID:884218 发表于 2021-2-14 20:01 | 显示全部楼层 |阅读模式
stm32429——usb项目demo,作主机读写U盘,亲测成功,可生成写入的txt文件。

单片机源程序如下:

  1. /* USER CODE END Header */

  2. /* Includes ------------------------------------------------------------------*/
  3. #include "main.h"
  4. #include "dma.h"
  5. #include "spi.h"
  6. #include "usart.h"
  7. #include "gpio.h"

  8. /* Private includes ----------------------------------------------------------*/
  9. /* USER CODE BEGIN Includes */

  10. /* USER CODE END Includes */

  11. /* Private typedef -----------------------------------------------------------*/
  12. /* USER CODE BEGIN PTD */

  13. /* USER CODE END PTD */

  14. /* Private define ------------------------------------------------------------*/
  15. /* USER CODE BEGIN PD */

  16. /* USER CODE END PD */

  17. /* Private macro -------------------------------------------------------------*/
  18. /* USER CODE BEGIN PM */

  19. /* USER CODE END PM */

  20. /* Private variables ---------------------------------------------------------*/

  21. /* USER CODE BEGIN PV */

  22. /* USER CODE END PV */

  23. /* Private function prototypes -----------------------------------------------*/
  24. void SystemClock_Config(void);
  25. /* USER CODE BEGIN PFP */

  26. /* USER CODE END PFP */

  27. /* Private user code ---------------------------------------------------------*/
  28. /* USER CODE BEGIN 0 */

  29. /* USER CODE END 0 */

  30. /**
  31.   * @brief  The application entry point.
  32.   * @retval int
  33.   */
  34. int main(void)
  35. {
  36.   /* USER CODE BEGIN 1 */

  37.   /* USER CODE END 1 */
  38.   

  39.   /* MCU Configuration--------------------------------------------------------*/

  40.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  41.   HAL_Init();

  42.   /* USER CODE BEGIN Init */

  43.   /* USER CODE END Init */

  44.   /* Configure the system clock */
  45.   SystemClock_Config();

  46.   /* USER CODE BEGIN SysInit */

  47.   /* USER CODE END SysInit */

  48.   /* Initialize all configured peripherals */
  49.   MX_GPIO_Init();
  50.   MX_DMA_Init();
  51.   MX_SPI1_Init();
  52.   MX_USART1_UART_Init();
  53.   /* USER CODE BEGIN 2 */

  54.   /* USER CODE END 2 */

  55.   /* Infinite loop */
  56.   /* USER CODE BEGIN WHILE */
  57.   while (1)
  58.   {
  59.     /* USER CODE END WHILE */

  60.     /* USER CODE BEGIN 3 */
  61.   }
  62.   /* USER CODE END 3 */
  63. }

  64. /**
  65.   * @brief System Clock Configuration
  66.   * @retval None
  67.   */
  68. void SystemClock_Config(void)
  69. {
  70.   RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  71.   RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  72.   /** Initializes the CPU, AHB and APB busses clocks
  73.   */
  74.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  75.   RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  76.   RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
  77.   RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  78.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  79.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  80.   RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
  81.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  82.   {
  83.     Error_Handler();
  84.   }
  85.   /** Initializes the CPU, AHB and APB busses clocks
  86.   */
  87.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  88.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  89.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  90.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  91.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  92.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  93.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  94.   {
  95.     Error_Handler();
  96.   }
  97. }

  98. /* USER CODE BEGIN 4 */

  99. /* USER CODE END 4 */

  100. /**
  101.   * @brief  This function is executed in case of error occurrence.
  102.   * @retval None
  103.   */
  104. void Error_Handler(void)
  105. {
  106.   /* USER CODE BEGIN Error_Handler_Debug */
  107.   /* User can add his own implementation to report the HAL error return state */

  108.   /* USER CODE END Error_Handler_Debug */
  109. }

  110. #ifdef  USE_FULL_ASSERT
  111. /**
  112.   * @brief  Reports the name of the source file and the source line number
  113.   *         where the assert_param error has occurred.
  114.   * @param  file: pointer to the source file name
  115.   * @param  line: assert_param error line source number
  116.   * @retval None
  117.   */
  118. void assert_failed(uint8_t *file, uint32_t line)
  119. {
  120.   /* USER CODE BEGIN 6 */
  121.   /* User can add his own implementation to report the file name and line number,
  122.      tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  123.   /* USER CODE END 6 */
  124. }
  125. #endif /* USE_FULL_ASSERT */

  126. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
复制代码

所有资料51hei提供下载:
F429_DEMO.7z (2.92 MB, 下载次数: 19)
回复

使用道具 举报

ID:83553 发表于 2021-2-15 10:14 | 显示全部楼层
楼主是不是传错文件了?不是429,也不是读写U盘
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表