[APM32F1] APM32F103CCT6仿真或者KEIL选择RESET AND RUN 下载程序都可以正常工作,但是断了仿真器自启动...

[复制链接]
1146|2
 楼主| cornrn 发表于 2023-8-25 21:11 | 显示全部楼层 |阅读模式
本帖最后由 cornrn 于 2023-8-25 21:16 编辑

APM32F103CCT6仿真或者KEIL选择RESET AND RUN 下载程序都可以正常工作,但是断了仿真器无法启动。供电都正常BOOT0 BOOT1设置GND GND正常,不断开关板子电源键偶尔能启动成功驱动LCD.

这里使用的STM32CUBEMX HAL库
  1. /* USER CODE BEGIN Header */
  2. /**
  3.   ******************************************************************************
  4.   * [url=home.php?mod=space&uid=288409]@file[/url]           : main.c
  5.   * [url=home.php?mod=space&uid=247401]@brief[/url]          : Main program body
  6.   ******************************************************************************
  7.   * @attention
  8.   *
  9.   * Copyright (c) 2023 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. #include "adc.h"
  22. #include "dma.h"
  23. #include "spi.h"
  24. #include "tim.h"
  25. #include "usart.h"
  26. #include "gpio.h"

  27. /* Private includes ----------------------------------------------------------*/
  28. /* USER CODE BEGIN Includes */
  29. #include "lcd_init.h"
  30. #include "lcd.h"
  31. #include "pic.h"
  32. /* USER CODE END Includes */

  33. /* Private typedef -----------------------------------------------------------*/
  34. /* USER CODE BEGIN PTD */

  35. /* USER CODE END PTD */

  36. /* Private define ------------------------------------------------------------*/
  37. /* USER CODE BEGIN PD */

  38. /* USER CODE END PD */

  39. /* Private macro -------------------------------------------------------------*/
  40. /* USER CODE BEGIN PM */

  41. /* USER CODE END PM */

  42. /* Private variables ---------------------------------------------------------*/

  43. /* USER CODE BEGIN PV */

  44. /* USER CODE END PV */

  45. /* Private function prototypes -----------------------------------------------*/
  46. void SystemClock_Config(void);
  47. /* USER CODE BEGIN PFP */

  48. /* USER CODE END PFP */

  49. /* Private user code ---------------------------------------------------------*/
  50. /* USER CODE BEGIN 0 */

  51. /* USER CODE END 0 */

  52. /**
  53.   * [url=home.php?mod=space&uid=247401]@brief[/url]  The application entry point.
  54.   * @retval int
  55.   */
  56. int main(void)
  57. {
  58.   /* USER CODE BEGIN 1 */

  59.   /* USER CODE END 1 */

  60.   /* MCU Configuration--------------------------------------------------------*/

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

  63.   /* USER CODE BEGIN Init */

  64.   /* USER CODE END Init */

  65.   /* Configure the system clock */
  66.   SystemClock_Config();

  67.   /* USER CODE BEGIN SysInit */
  68.   HAL_Delay(100);
  69.   /* USER CODE END SysInit */

  70.   /* Initialize all configured peripherals */
  71.   MX_GPIO_Init();
  72.   MX_DMA_Init();
  73.   MX_ADC1_Init();
  74.   MX_SPI2_Init();
  75.   MX_TIM1_Init();
  76.   MX_TIM2_Init();
  77.   MX_TIM3_Init();
  78.   MX_TIM4_Init();
  79.   MX_USART2_UART_Init();
  80.   MX_USART3_UART_Init();
  81.   /* USER CODE BEGIN 2 */
  82.     LCD_Init();//LCD初始化
  83.         HAL_Delay(100);
  84.     LCD_Fill(0,0,LCD_W,LCD_H,WHITE);

  85.     LCD_ShowChinese(0,80,"编号",BRRED,WHITE,32,0);
  86.     LCD_ShowChinese(80,80,"混响",GREEN,WHITE,32,0);
  87.     LCD_ShowChinese(160,80,"音量",DARKBLUE,WHITE,32,0);
  88.     LCD_ShowChinese(50,0,"科技",GRAYBLUE,WHITE,32,0);
  89.   /* USER CODE END 2 */

  90.   /* Infinite loop */
  91.   /* USER CODE BEGIN WHILE */
  92.     while (1)
  93.     {
  94.     /* USER CODE END WHILE */

  95.     /* USER CODE BEGIN 3 */
  96. //        LCD_Fill(0,0,LCD_W,LCD_H,RED);

  97. //        LCD_Fill(0,0,LCD_W,LCD_H,BLUE);

  98. //        LCD_Fill(0,0,LCD_W,LCD_H,YELLOW);

  99.         //LCD_Fill(0,0,LCD_W,LCD_H,WHITE);
  100.         HAL_GPIO_TogglePin(LD1_GPIO_Port, LD1_Pin);
  101.         HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);
  102.         HAL_GPIO_TogglePin(LD3_GPIO_Port, LD3_Pin);
  103.         HAL_GPIO_TogglePin(LD4_GPIO_Port, LD4_Pin);
  104.         HAL_GPIO_TogglePin(LD5_GPIO_Port, LD5_Pin);
  105.         HAL_GPIO_TogglePin(LD6_GPIO_Port, LD6_Pin);

  106.         HAL_Delay(1000);

  107.     }
  108.   /* USER CODE END 3 */
  109. }

  110. /**
  111.   * @brief System Clock Configuration
  112.   * @retval None
  113.   */
  114. void SystemClock_Config(void)
  115. {
  116.   RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  117.   RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  118.   RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};

  119.   /** Initializes the RCC Oscillators according to the specified parameters
  120.   * in the RCC_OscInitTypeDef structure.
  121.   */
  122.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  123.   RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  124.   RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  125.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  126.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2;
  127.   RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL16;
  128.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  129.   {
  130.     Error_Handler();
  131.   }

  132.   /** Initializes the CPU, AHB and APB buses clocks
  133.   */
  134.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  135.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  136.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  137.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  138.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  139.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  140.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  141.   {
  142.     Error_Handler();
  143.   }
  144.   PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC;
  145.   PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6;
  146.   if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  147.   {
  148.     Error_Handler();
  149.   }
  150. }

  151. /* USER CODE BEGIN 4 */

  152. /* USER CODE END 4 */

  153. /**
  154.   * @brief  This function is executed in case of error occurrence.
  155.   * @retval None
  156.   */
  157. void Error_Handler(void)
  158. {
  159.   /* USER CODE BEGIN Error_Handler_Debug */
  160.     /* User can add his own implementation to report the HAL error return state */
  161.     __disable_irq();
  162.     while (1)
  163.     {
  164.     }
  165.   /* USER CODE END Error_Handler_Debug */
  166. }

  167. #ifdef  USE_FULL_ASSERT
  168. /**
  169.   * @brief  Reports the name of the source file and the source line number
  170.   *         where the assert_param error has occurred.
  171.   * @param  file: pointer to the source file name
  172.   * @param  line: assert_param error line source number
  173.   * @retval None
  174.   */
  175. void assert_failed(uint8_t *file, uint32_t line)
  176. {
  177.   /* USER CODE BEGIN 6 */
  178.     /* User can add his own implementation to report the file name and line number,
  179.        ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  180.   /* USER CODE END 6 */
  181. }
  182. #endif /* USE_FULL_ASSERT */


  
 楼主| cornrn 发表于 2023-8-25 21:24 | 显示全部楼层
APM32F1-3C---KEIL配置注意项目.png 自问自答,这2个选项选上就行
您需要登录后才可以回帖 登录 | 注册

本版积分规则

189

主题

897

帖子

12

粉丝
快速回复 在线客服 返回列表 返回顶部