[应用相关] STM32H750移植FreeRTOS

[复制链接]
3172|65
 楼主| 自动化陈稳 发表于 2022-2-27 22:54 | 显示全部楼层
看错误信息很好理解,因为我们使用的H7系列,所以需要改成 #include "stm32h7xx_hal.h"

        此处我们这样修改,将下图中的黄色框内的删除掉,在文件的头部添加#include "stm32h7xx_hal.h"
 楼主| 自动化陈稳 发表于 2022-2-27 22:55 | 显示全部楼层
 楼主| 自动化陈稳 发表于 2022-2-27 23:05 | 显示全部楼层
然后我们再次编译,输出如下错误
97716621b934c79357.png
 楼主| 自动化陈稳 发表于 2022-2-27 23:06 | 显示全部楼层
上面的错误是说有三个函数重复定义了,这个是因为FreeRTOS依赖这三个函数执行系统调度,但是我们使用STM32CubeMX生成的工程中也有这样的函数实现,那就需要我们进行简单修改:

        我们注释掉FreeRTOSConfig.h中这一行#define xPortSysTickHandler SysTick_Handler
62218621b936228b02.png

  修改stm32h7xx_it.c文件,注释掉PendSV_Handler、SVC_Handler函数,并在Systick_Handler中添加截图中的代码
16049621b937266503.png
 楼主| 自动化陈稳 发表于 2022-2-27 23:07 | 显示全部楼层
然后我们再次编译,然后我们再次如下错误
7698621b939534dee.png

vApplicationStackOverflowHook、 vApplicationTickHook、  vApplicationMallocFailedHook这个函数分别是指栈溢出、Tick中断、内存分配失败时的钩子函数,我们暂时先禁用这些功能,只需要按照下图操作即可
 楼主| 自动化陈稳 发表于 2022-2-27 23:08 | 显示全部楼层
 楼主| 自动化陈稳 发表于 2022-2-27 23:09 | 显示全部楼层
完整的文件如下
  1. /*
  2. * FreeRTOS V202107.00
  3. * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  6. * this software and associated documentation files (the "Software"), to deal in
  7. * the Software without restriction, including without limitation the rights to
  8. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  9. * the Software, and to permit persons to whom the Software is furnished to do so,
  10. * subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in all
  13. * copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  17. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  18. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  19. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  20. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * http://www.FreeRTOS.org
  23. * http://aws.amazon.com/freertos
  24. *
  25. * 1 tab == 4 spaces!
  26. */


  27. #ifndef FREERTOS_CONFIG_H
  28. #define FREERTOS_CONFIG_H

  29. /*-----------------------------------------------------------
  30. * Application specific definitions.
  31. *
  32. * These definitions should be adjusted for your particular hardware and
  33. * application requirements.
  34. *
  35. * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
  36. * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
  37. *
  38. * See http://www.freertos.org/a00110.html
  39. *----------------------------------------------------------*/

  40. #include "stm32h7xx_hal.h"

  41. #define configUSE_PREEMPTION                                        1
  42. #define configUSE_PORT_OPTIMISED_TASK_SELECTION        1
  43. #define configUSE_QUEUE_SETS                                        1
  44. #define configUSE_IDLE_HOOK                                                0
  45. #define configUSE_TICK_HOOK                                                0
  46. #define configCPU_CLOCK_HZ                                                ( SystemCoreClock )
  47. #define configTICK_RATE_HZ                                                ( 1000 )
  48. #define configMAX_PRIORITIES                                        ( 5 )
  49. #define configMINIMAL_STACK_SIZE                                ( ( unsigned short ) 130 )
  50. #define configTOTAL_HEAP_SIZE                                        ( ( size_t ) ( 46 * 1024 ) )
  51. #define configMAX_TASK_NAME_LEN                                        ( 10 )
  52. #define configUSE_TRACE_FACILITY                                1
  53. #define configUSE_16_BIT_TICKS                                        0
  54. #define configIDLE_SHOULD_YIELD                                        1
  55. #define configUSE_MUTEXES                                                1
  56. #define configQUEUE_REGISTRY_SIZE                                8
  57. #define configCHECK_FOR_STACK_OVERFLOW                        0
  58. #define configUSE_RECURSIVE_MUTEXES                                1
  59. #define configUSE_MALLOC_FAILED_HOOK                        0
  60. #define configUSE_APPLICATION_TASK_TAG                        0
  61. #define configUSE_COUNTING_SEMAPHORES                        1

  62. /* The full demo always has tasks to run so the tick will never be turned off.
  63. The blinky demo will use the default tickless idle implementation to turn the
  64. tick off. */
  65. #define configUSE_TICKLESS_IDLE                                        0

  66. /* Run time stats gathering definitions. */
  67. #define configGENERATE_RUN_TIME_STATS        0

  68. /* This demo makes use of one or more example stats formatting functions.  These
  69. format the raw data provided by the uxTaskGetSystemState() function in to human
  70. readable ASCII form.  See the notes in the implementation of vTaskList() within
  71. FreeRTOS/Source/tasks.c for limitations. */
  72. #define configUSE_STATS_FORMATTING_FUNCTIONS        1

  73. /* Co-routine definitions. */
  74. #define configUSE_CO_ROUTINES                         0
  75. #define configMAX_CO_ROUTINE_PRIORITIES ( 2 )

  76. /* Software timer definitions. */
  77. #define configUSE_TIMERS                                1
  78. #define configTIMER_TASK_PRIORITY                ( configMAX_PRIORITIES - 1 )
  79. #define configTIMER_QUEUE_LENGTH                5
  80. #define configTIMER_TASK_STACK_DEPTH        ( configMINIMAL_STACK_SIZE * 2 )

  81. /* Set the following definitions to 1 to include the API function, or zero
  82. to exclude the API function. */
  83. #define INCLUDE_vTaskPrioritySet                1
  84. #define INCLUDE_uxTaskPriorityGet                1
  85. #define INCLUDE_vTaskDelete                                1
  86. #define INCLUDE_vTaskCleanUpResources        1
  87. #define INCLUDE_vTaskSuspend                        1
  88. #define INCLUDE_vTaskDelayUntil                        1
  89. #define INCLUDE_vTaskDelay                                1
  90. #define INCLUDE_eTaskGetState                        1
  91. #define INCLUDE_xTimerPendFunctionCall        1

  92. /* Cortex-M specific definitions. */
  93. #ifdef __NVIC_PRIO_BITS
  94.         /* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */
  95.         #define configPRIO_BITS                       __NVIC_PRIO_BITS
  96. #else
  97.         #define configPRIO_BITS                       4        /* 15 priority levels */
  98. #endif

  99. /* The lowest interrupt priority that can be used in a call to a "set priority"
  100. function. */
  101. #define configLIBRARY_LOWEST_INTERRUPT_PRIORITY                        15

  102. /* The highest interrupt priority that can be used by any interrupt service
  103. routine that makes calls to interrupt safe FreeRTOS API functions.  DO NOT CALL
  104. INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER
  105. PRIORITY THAN THIS! (higher priorities are lower numeric values. */
  106. #define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY        4

  107. /* Interrupt priorities used by the kernel port layer itself.  These are generic
  108. to all Cortex-M ports, and do not rely on any particular library functions. */
  109. #define configKERNEL_INTERRUPT_PRIORITY                 ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
  110. /* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
  111. See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
  112. #define configMAX_SYSCALL_INTERRUPT_PRIORITY         ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )

  113. /* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
  114. standard names. */
  115. #define xPortPendSVHandler PendSV_Handler
  116. #define vPortSVCHandler SVC_Handler
  117. //#define xPortSysTickHandler SysTick_Handler


  118. #endif /* FREERTOS_CONFIG_H */
 楼主| 自动化陈稳 发表于 2022-2-27 23:10 | 显示全部楼层
    再次编译 后,我们发现没有错误。

        接下来,我们在main.c里面添加业务代码以及运行FreeRTOS调度器。
 楼主| 自动化陈稳 发表于 2022-2-27 23:11 | 显示全部楼层
 楼主| 自动化陈稳 发表于 2022-2-27 23:11 | 显示全部楼层
 楼主| 自动化陈稳 发表于 2022-2-27 23:29 | 显示全部楼层
上面代码的意思是,创建两个LED任务,任务优先级为2,一个任务一秒闪烁一次,另外一个0.5秒闪烁一次。
 楼主| 自动化陈稳 发表于 2022-2-27 23:31 | 显示全部楼层
  完整代码如下
  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.   * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
  10.   * All rights reserved.</center></h2>
  11.   *
  12.   * This software component is licensed by ST under BSD 3-Clause license,
  13.   * the "License"; You may not use this file except in compliance with the
  14.   * License. You may obtain a copy of the License at:
  15.   *                        opensource.org/licenses/BSD-3-Clause
  16.   *
  17.   ******************************************************************************
  18.   */
  19. /* USER CODE END Header */
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "main.h"

  22. /* Private includes ----------------------------------------------------------*/
  23. /* USER CODE BEGIN Includes */
  24. #include "freertos.h"
  25. #include "task.h"
  26. /* USER CODE END Includes */

  27. /* Private typedef -----------------------------------------------------------*/
  28. /* USER CODE BEGIN PTD */

  29. /* USER CODE END PTD */

  30. /* Private define ------------------------------------------------------------*/
  31. /* USER CODE BEGIN PD */
  32. /* USER CODE END PD */

  33. /* Private macro -------------------------------------------------------------*/
  34. /* USER CODE BEGIN PM */

  35. /* USER CODE END PM */

  36. /* Private variables ---------------------------------------------------------*/

  37. /* USER CODE BEGIN PV */

  38. /* USER CODE END PV */

  39. /* Private function prototypes -----------------------------------------------*/
  40. void SystemClock_Config(void);
  41. static void MX_GPIO_Init(void);
  42. /* USER CODE BEGIN PFP */

  43. /* USER CODE END PFP */

  44. /* Private user code ---------------------------------------------------------*/
  45. /* USER CODE BEGIN 0 */
  46. static void led1_task(void *args) {
  47.   while (1)
  48.   {
  49.    
  50.         HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_15);
  51.         vTaskDelay(1000);
  52.   }
  53.   //vTaskDelete(NULL);
  54. }

  55. static void led2_task(void *args) {
  56.   while (1)
  57.   {
  58.       HAL_GPIO_TogglePin(GPIOI, GPIO_PIN_8);
  59.         vTaskDelay(500);
  60.   }
  61.   //vTaskDelete(NULL);
  62. }
  63. /* USER CODE END 0 */

  64. /**
  65.   * @brief  The application entry point.
  66.   * @retval int
  67.   */
  68. int main(void)
  69. {
  70.   /* USER CODE BEGIN 1 */

  71.   /* USER CODE END 1 */

  72.   /* MCU Configuration--------------------------------------------------------*/

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

  75.   /* USER CODE BEGIN Init */

  76.   /* USER CODE END Init */

  77.   /* Configure the system clock */
  78.   SystemClock_Config();

  79.   /* USER CODE BEGIN SysInit */

  80.   /* USER CODE END SysInit */

  81.   /* Initialize all configured peripherals */
  82.   MX_GPIO_Init();
  83.   /* USER CODE BEGIN 2 */
  84.   HAL_GPIO_WritePin(GPIOC, GPIO_PIN_15, GPIO_PIN_SET);
  85.   HAL_GPIO_WritePin(GPIOI, GPIO_PIN_8, GPIO_PIN_SET);
  86.   SystemClock_Config();
  87.   xTaskCreate(led1_task, "led", configMINIMAL_STACK_SIZE, NULL, 2, NULL );
  88.   xTaskCreate(led2_task, "led", configMINIMAL_STACK_SIZE, NULL, 2, NULL );
  89.   vTaskStartScheduler();

  90.   /* USER CODE END 2 */

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

  96.     /* USER CODE BEGIN 3 */
  97.   }
  98.   /* USER CODE END 3 */
  99. }

  100. /**
  101.   * @brief System Clock Configuration
  102.   * @retval None
  103.   */
  104. void SystemClock_Config(void)
  105. {
  106.   RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  107.   RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  108.   /** Supply configuration update enable
  109.   */
  110.   HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);
  111.   /** Configure the main internal regulator output voltage
  112.   */
  113.   __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE0);

  114.   while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
  115.   /** Initializes the RCC Oscillators according to the specified parameters
  116.   * in the RCC_OscInitTypeDef structure.
  117.   */
  118.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  119.   RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  120.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  121.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  122.   RCC_OscInitStruct.PLL.PLLM = 5;
  123.   RCC_OscInitStruct.PLL.PLLN = 192;
  124.   RCC_OscInitStruct.PLL.PLLP = 2;
  125.   RCC_OscInitStruct.PLL.PLLQ = 2;
  126.   RCC_OscInitStruct.PLL.PLLR = 2;
  127.   RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_2;
  128.   RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
  129.   RCC_OscInitStruct.PLL.PLLFRACN = 0;
  130.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  131.   {
  132.     Error_Handler();
  133.   }
  134.   /** Initializes the CPU, AHB and APB buses clocks
  135.   */
  136.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  137.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
  138.                               |RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;
  139.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  140.   RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
  141.   RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV2;
  142.   RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV2;
  143.   RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV2;
  144.   RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2;
  145.   RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV2;

  146.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
  147.   {
  148.     Error_Handler();
  149.   }
  150. }

  151. /**
  152.   * @brief GPIO Initialization Function
  153.   * @param None
  154.   * @retval None
  155.   */
  156. static void MX_GPIO_Init(void)
  157. {
  158.   GPIO_InitTypeDef GPIO_InitStruct = {0};

  159.   /* GPIO Ports Clock Enable */
  160.   __HAL_RCC_GPIOC_CLK_ENABLE();
  161.   __HAL_RCC_GPIOI_CLK_ENABLE();
  162.   __HAL_RCC_GPIOH_CLK_ENABLE();

  163.   /*Configure GPIO pin Output Level */
  164.   HAL_GPIO_WritePin(GPIOC, GPIO_PIN_15, GPIO_PIN_RESET);

  165.   /*Configure GPIO pin Output Level */
  166.   HAL_GPIO_WritePin(GPIOI, GPIO_PIN_8, GPIO_PIN_RESET);

  167.   /*Configure GPIO pin : PC15 */
  168.   GPIO_InitStruct.Pin = GPIO_PIN_15;
  169.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  170.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  171.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  172.   HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

  173.   /*Configure GPIO pin : PI8 */
  174.   GPIO_InitStruct.Pin = GPIO_PIN_8;
  175.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  176.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  177.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  178.   HAL_GPIO_Init(GPIOI, &GPIO_InitStruct);

  179. }

  180. /* USER CODE BEGIN 4 */

  181. /* USER CODE END 4 */

  182. /**
  183.   * @brief  This function is executed in case of error occurrence.
  184.   * @retval None
  185.   */
  186. void Error_Handler(void)
  187. {
  188.   /* USER CODE BEGIN Error_Handler_Debug */
  189.   /* User can add his own implementation to report the HAL error return state */
  190.   __disable_irq();
  191.   while (1)
  192.   {
  193.   }
  194.   /* USER CODE END Error_Handler_Debug */
  195. }

  196. #ifdef  USE_FULL_ASSERT
  197. /**
  198.   * @brief  Reports the name of the source file and the source line number
  199.   *         where the assert_param error has occurred.
  200.   * @param  file: pointer to the source file name
  201.   * @param  line: assert_param error line source number
  202.   * @retval None
  203.   */
  204. void assert_failed(uint8_t *file, uint32_t line)
  205. {
  206.   /* USER CODE BEGIN 6 */
  207.   /* User can add his own implementation to report the file name and line number,
  208.      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  209.   /* USER CODE END 6 */
  210. }
  211. #endif /* USE_FULL_ASSERT */

  212. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
 楼主| 自动化陈稳 发表于 2022-2-27 23:33 | 显示全部楼层
编译后下载,我们可以看到板载LED按照我们代码的逻辑进行闪烁,至此我们就完成了FreeRTOS的基本移植。

        关于FreeRTOS的知识,后面我会出FreeRTOS系列**帮助大家进行学习掌握。

完整工程下载地址

链接:https://pan.baidu.com/s/1OuXvAUmIxGLkTd6HT6tfmA
提取码:xdgq
Pulitzer 发表于 2022-10-27 07:05 | 显示全部楼层

CPLD解密,DSP解密都习惯称为单片机解密
公羊子丹 发表于 2022-10-27 09:01 | 显示全部楼层

具存储功能的存储器芯片也能加密
Wordsworth 发表于 2022-10-27 10:04 | 显示全部楼层

紫外光复位保护电路是不行的
Clyde011 发表于 2022-10-27 11:07 | 显示全部楼层

如果在编程时加密锁定位被使能/锁定,就无法用普通编程器直接读取单片机内的程序
万图 发表于 2022-10-27 13:03 | 显示全部楼层

微探针技术都属于侵入型攻击
Uriah 发表于 2022-10-27 14:06 | 显示全部楼层

大部分单片机都带有加密锁定位或者加密字节
帛灿灿 发表于 2022-10-27 16:02 | 显示全部楼层

编程器定位插字节
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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