打印
[应用相关]

STM32H750移植FreeRTOS

[复制链接]
楼主: 自动化陈稳
手机看帖
扫描二维码
随时随地手机跟帖
21
自动化陈稳|  楼主 | 2022-2-27 22:54 | 只看该作者 |只看大图 回帖奖励 |倒序浏览
看错误信息很好理解,因为我们使用的H7系列,所以需要改成 #include "stm32h7xx_hal.h"

        此处我们这样修改,将下图中的黄色框内的删除掉,在文件的头部添加#include "stm32h7xx_hal.h"

使用特权

评论回复
22
自动化陈稳|  楼主 | 2022-2-27 22:55 | 只看该作者

使用特权

评论回复
23
自动化陈稳|  楼主 | 2022-2-27 23:05 | 只看该作者
然后我们再次编译,输出如下错误

使用特权

评论回复
24
自动化陈稳|  楼主 | 2022-2-27 23:06 | 只看该作者
上面的错误是说有三个函数重复定义了,这个是因为FreeRTOS依赖这三个函数执行系统调度,但是我们使用STM32CubeMX生成的工程中也有这样的函数实现,那就需要我们进行简单修改:

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


  修改stm32h7xx_it.c文件,注释掉PendSV_Handler、SVC_Handler函数,并在Systick_Handler中添加截图中的代码

使用特权

评论回复
25
自动化陈稳|  楼主 | 2022-2-27 23:07 | 只看该作者
然后我们再次编译,然后我们再次如下错误


vApplicationStackOverflowHook、 vApplicationTickHook、  vApplicationMallocFailedHook这个函数分别是指栈溢出、Tick中断、内存分配失败时的钩子函数,我们暂时先禁用这些功能,只需要按照下图操作即可

使用特权

评论回复
26
自动化陈稳|  楼主 | 2022-2-27 23:08 | 只看该作者

使用特权

评论回复
27
自动化陈稳|  楼主 | 2022-2-27 23:09 | 只看该作者
完整的文件如下
/*
* FreeRTOS V202107.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://www.FreeRTOS.org
* http://aws.amazon.com/freertos
*
* 1 tab == 4 spaces!
*/


#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H

/*-----------------------------------------------------------
* Application specific definitions.
*
* These definitions should be adjusted for your particular hardware and
* application requirements.
*
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
*
* See http://www.freertos.org/a00110.html
*----------------------------------------------------------*/

#include "stm32h7xx_hal.h"

#define configUSE_PREEMPTION                                        1
#define configUSE_PORT_OPTIMISED_TASK_SELECTION        1
#define configUSE_QUEUE_SETS                                        1
#define configUSE_IDLE_HOOK                                                0
#define configUSE_TICK_HOOK                                                0
#define configCPU_CLOCK_HZ                                                ( SystemCoreClock )
#define configTICK_RATE_HZ                                                ( 1000 )
#define configMAX_PRIORITIES                                        ( 5 )
#define configMINIMAL_STACK_SIZE                                ( ( unsigned short ) 130 )
#define configTOTAL_HEAP_SIZE                                        ( ( size_t ) ( 46 * 1024 ) )
#define configMAX_TASK_NAME_LEN                                        ( 10 )
#define configUSE_TRACE_FACILITY                                1
#define configUSE_16_BIT_TICKS                                        0
#define configIDLE_SHOULD_YIELD                                        1
#define configUSE_MUTEXES                                                1
#define configQUEUE_REGISTRY_SIZE                                8
#define configCHECK_FOR_STACK_OVERFLOW                        0
#define configUSE_RECURSIVE_MUTEXES                                1
#define configUSE_MALLOC_FAILED_HOOK                        0
#define configUSE_APPLICATION_TASK_TAG                        0
#define configUSE_COUNTING_SEMAPHORES                        1

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

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

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

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

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

/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
#define INCLUDE_vTaskPrioritySet                1
#define INCLUDE_uxTaskPriorityGet                1
#define INCLUDE_vTaskDelete                                1
#define INCLUDE_vTaskCleanUpResources        1
#define INCLUDE_vTaskSuspend                        1
#define INCLUDE_vTaskDelayUntil                        1
#define INCLUDE_vTaskDelay                                1
#define INCLUDE_eTaskGetState                        1
#define INCLUDE_xTimerPendFunctionCall        1

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

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

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

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

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


#endif /* FREERTOS_CONFIG_H */

使用特权

评论回复
28
自动化陈稳|  楼主 | 2022-2-27 23:10 | 只看该作者
    再次编译 后,我们发现没有错误。

        接下来,我们在main.c里面添加业务代码以及运行FreeRTOS调度器。

使用特权

评论回复
29
自动化陈稳|  楼主 | 2022-2-27 23:11 | 只看该作者

使用特权

评论回复
30
自动化陈稳|  楼主 | 2022-2-27 23:11 | 只看该作者

使用特权

评论回复
31
自动化陈稳|  楼主 | 2022-2-27 23:29 | 只看该作者
上面代码的意思是,创建两个LED任务,任务优先级为2,一个任务一秒闪烁一次,另外一个0.5秒闪烁一次。

使用特权

评论回复
32
自动化陈稳|  楼主 | 2022-2-27 23:31 | 只看该作者
  完整代码如下
/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * [url=home.php?mod=space&uid=288409]@file[/url]           : main.c
  * [url=home.php?mod=space&uid=247401]@brief[/url]          : Main program body
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under BSD 3-Clause license,
  * the "License"; You may not use this file except in compliance with the
  * License. You may obtain a copy of the License at:
  *                        opensource.org/licenses/BSD-3-Clause
  *
  ******************************************************************************
  */
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "freertos.h"
#include "task.h"
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/

/* USER CODE BEGIN PV */

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
static void led1_task(void *args) {
  while (1)
  {
   
        HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_15);
        vTaskDelay(1000);
  }
  //vTaskDelete(NULL);
}

static void led2_task(void *args) {
  while (1)
  {
      HAL_GPIO_TogglePin(GPIOI, GPIO_PIN_8);
        vTaskDelay(500);
  }
  //vTaskDelete(NULL);
}
/* USER CODE END 0 */

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{
  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

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

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  /* USER CODE BEGIN 2 */
  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_15, GPIO_PIN_SET);
  HAL_GPIO_WritePin(GPIOI, GPIO_PIN_8, GPIO_PIN_SET);
  SystemClock_Config();
  xTaskCreate(led1_task, "led", configMINIMAL_STACK_SIZE, NULL, 2, NULL );
  xTaskCreate(led2_task, "led", configMINIMAL_STACK_SIZE, NULL, 2, NULL );
  vTaskStartScheduler();

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

/**
  * @brief System Clock Configuration
  * @retval None
  */
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  /** Supply configuration update enable
  */
  HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);
  /** Configure the main internal regulator output voltage
  */
  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE0);

  while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
  /** Initializes the RCC Oscillators according to the specified parameters
  * in the RCC_OscInitTypeDef structure.
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLM = 5;
  RCC_OscInitStruct.PLL.PLLN = 192;
  RCC_OscInitStruct.PLL.PLLP = 2;
  RCC_OscInitStruct.PLL.PLLQ = 2;
  RCC_OscInitStruct.PLL.PLLR = 2;
  RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_2;
  RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
  RCC_OscInitStruct.PLL.PLLFRACN = 0;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }
  /** Initializes the CPU, AHB and APB buses clocks
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
                              |RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV2;
  RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV2;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV2;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2;
  RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV2;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
  {
    Error_Handler();
  }
}

/**
  * @brief GPIO Initialization Function
  * @param None
  * @retval None
  */
static void MX_GPIO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};

  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOC_CLK_ENABLE();
  __HAL_RCC_GPIOI_CLK_ENABLE();
  __HAL_RCC_GPIOH_CLK_ENABLE();

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

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

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

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

}

/* USER CODE BEGIN 4 */

/* USER CODE END 4 */

/**
  * @brief  This function is executed in case of error occurrence.
  * @retval None
  */
void Error_Handler(void)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  /* User can add his own implementation to report the HAL error return state */
  __disable_irq();
  while (1)
  {
  }
  /* USER CODE END Error_Handler_Debug */
}

#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{
  /* USER CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

使用特权

评论回复
33
自动化陈稳|  楼主 | 2022-2-27 23:33 | 只看该作者
编译后下载,我们可以看到板载LED按照我们代码的逻辑进行闪烁,至此我们就完成了FreeRTOS的基本移植。

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

完整工程下载地址

链接:https://pan.baidu.com/s/1OuXvAUmIxGLkTd6HT6tfmA
提取码:xdgq

使用特权

评论回复
34
Pulitzer| | 2022-10-27 07:05 | 只看该作者

CPLD解密,DSP解密都习惯称为单片机解密

使用特权

评论回复
35
公羊子丹| | 2022-10-27 09:01 | 只看该作者

具存储功能的存储器芯片也能加密

使用特权

评论回复
36
Wordsworth| | 2022-10-27 10:04 | 只看该作者

紫外光复位保护电路是不行的

使用特权

评论回复
37
Clyde011| | 2022-10-27 11:07 | 只看该作者

如果在编程时加密锁定位被使能/锁定,就无法用普通编程器直接读取单片机内的程序

使用特权

评论回复
38
万图| | 2022-10-27 13:03 | 只看该作者

微探针技术都属于侵入型攻击

使用特权

评论回复
39
Uriah| | 2022-10-27 14:06 | 只看该作者

大部分单片机都带有加密锁定位或者加密字节

使用特权

评论回复
40
帛灿灿| | 2022-10-27 16:02 | 只看该作者

编程器定位插字节

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则