TL-LED 发表于 2023-10-22 22:01

【STM32F723 Discovery Kit】移植FreeRTOS系统

<div class='showpostmsg'> 本帖最后由 TL-LED 于 2023-10-22 22:00 编辑

<p><span style="font-size:16px;">这篇来学习下在STM32F723开发板上移植FreeRTOS系统。</span></p>

<p>&nbsp;</p>

<p><span style="font-size:16px;"><strong>一、下载FreeRTOS源码</strong></span></p>

<p>&nbsp;</p>

<p><span style="font-size:16px;">下载地址:<a href="https://www.freertos.org/zh-cn-cmn-s/a00104.html" target="_blank">https://www.freertos.org/zh-cn-cmn-s/a00104.html</a></span></p>

<p>&nbsp;</p>

<p><span style="font-size:16px;"><strong>二、复制文件</strong></span></p>

<p>&nbsp;</p>

<p><span style="font-size:16px;">2.1、复制下载的freertos源文件添加到工程中</span></p>

<p><span style="font-size:16px;"></span></p>

<p>&nbsp;</p>

<p><span style="font-size:16px;">在demo中找一个M7开发板的例程,复制FreeRTOSConfig.h</span></p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p><span style="font-size:16px;">2.2、添加文件到工程</span></p>

<p><span style="font-size:16px;"></span></p>

<p>&nbsp;</p>

<p><span style="font-size:16px;">2.3、添加头文件</span></p>

<p><span style="font-size:16px;"></span></p>

<p>&nbsp;</p>

<p><span style="font-size:16px;">添加完成后,编译项目根据编译提示错误修改FreeRTOSConfig.h文件的配置。</span></p>

<p>&nbsp;</p>

<p><span style="font-size:16px;"><strong>三、测试源码</strong></span></p>

<p>&nbsp;</p>

<p><span style="font-size:16px;">main.c</span></p>

<pre>
<code>#include "main.h"
#include "led/led.h"
#include "delay/delay.h"
#include "key/key.h"
#include "usart/usart.h"
#include "sram/sram.h"
#include "STM32F723E-Discovery/stm32f723e_discovery_lcd.h"
#include "STM32F723E-Discovery/stm32f723e_discovery_qspi.h"
#include "FreeRTOS.h"
#include "task.h"

#define TASK1_PRIO      2                  
#define TASK1_STK_SIZE128               
static TaskHandle_t            Task1Task_Handler = NULL;
         
#define TASK2_PRIO      3                  
#define TASK2_STK_SIZE128               
static TaskHandle_t            Task2Task_Handler = NULL;

void start_task(void *pvParameters);
void task1(void *pvParameters);
void task2(void *pvParameters);

static void MPU_Config(void);
static void SystemClock_Config(void);
static void CPU_CACHE_Enable(void);

int main(void)
{
        uint16_t i=0;
        uint8_t txbuf;
        uint8_t rxbuf;
       
MPU_Config();                                        /* Configure the MPU attributes */
CPU_CACHE_Enable();                /* Enable the CPU Cache */
HAL_Init();
SystemClock_Config();        /* Configure the system clock to 216 MHz */
        //task1
        xTaskCreate((TaskFunction_t )task1,                  
                                                        (const char*    )"task1",               
                                                        (uint16_t       )TASK1_STK_SIZE,         
                                                        (void*          )NULL,                  
                                                        (UBaseType_t    )TASK1_PRIO,            
                                                        (TaskHandle_t*)&amp;Task1Task_Handler);   
        //task2
        xTaskCreate((TaskFunction_t )task2,                  
                                                        (const char*    )"task2",               
                                                        (uint16_t       )TASK2_STK_SIZE,      
                                                        (void*          )NULL,                  
                                                        (UBaseType_t    )TASK2_PRIO,            
                                                        (TaskHandle_t*)&amp;Task2Task_Handler);        
       
        vTaskStartScheduler();               
while (1);
}

//task1
void task1(void *pvParameters)
{
    while (1)
    {
      printf("task1 run ...\r\n");
      LED5_TOGGLE();
      vTaskDelay(500);
    }
}

//task2
void task2(void *pvParameters)
{
    while (1)
    {       
                               
      printf("task2 run ...\r\n");
      vTaskDelay(100);
    }
}

/**
* @briefSystem Clock Configuration
*         The system Clock is configured as follow :
*            System Clock source            = PLL (HSE)
*            SYSCLK(Hz)                     = 216000000
*            HCLK(Hz)                     = 216000000
*            AHB Prescaler                  = 1
*            APB1 Prescaler               = 4
*            APB2 Prescaler               = 2
*            HSE Frequency(Hz)            = 25000000
*            PLL_M                        = 25
*            PLL_N                        = 432
*            PLL_P                        = 2
*            PLL_Q                        = 9
*            VDD(V)                         = 3.3
*            Main regulator output voltage= Scale1 mode
*            Flash Latency(WS)            = 7
* @paramNone
* @retval None
*/
void SystemClock_Config(void)
{
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitTypeDef RCC_OscInitStruct;

/* Enable HSE Oscillator and activate PLL with HSE as source */
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 = 25;
RCC_OscInitStruct.PLL.PLLN = 432;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 9;
if(HAL_RCC_OscConfig(&amp;RCC_OscInitStruct) != HAL_OK)
{
    while(1) {};
}

/* Activate the OverDrive to reach the 216 Mhz Frequency */
if(HAL_PWREx_EnableOverDrive() != HAL_OK)
{
    while(1) {};
}


/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
   clocks dividers */
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
if(HAL_RCC_ClockConfig(&amp;RCC_ClkInitStruct, FLASH_LATENCY_7) != HAL_OK)
{
    while(1) {};
}
}

/**
* @briefCPU L1-Cache enable.
* @paramNone
* @retval None
*/
static void CPU_CACHE_Enable(void)
{
/* Enable I-Cache */
SCB_EnableICache();

/* Enable D-Cache */
SCB_EnableDCache();
}


/**
* @briefConfigure the MPU attributes
* @paramNone
* @retval None
*/
static void MPU_Config(void)
{
MPU_Region_InitTypeDef MPU_InitStruct;

/* Disable the MPU */
HAL_MPU_Disable();

/* Configure the MPU as Strongly ordered for not defined regions */
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
MPU_InitStruct.BaseAddress = 0x00;
MPU_InitStruct.Size = MPU_REGION_SIZE_4GB;
MPU_InitStruct.AccessPermission = MPU_REGION_NO_ACCESS;
MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
MPU_InitStruct.Number = MPU_REGION_NUMBER0;
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
MPU_InitStruct.SubRegionDisable = 0x87;
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_DISABLE;

HAL_MPU_ConfigRegion(&amp;MPU_InitStruct);
       
        /* Configure the MPU attributes for TFT-LCD with recomended configurations:
   Normal memory, Shareable, write-back */
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
MPU_InitStruct.BaseAddress = 0x64000000;
MPU_InitStruct.Size = MPU_REGION_SIZE_512KB;
MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
MPU_InitStruct.IsBufferable = MPU_ACCESS_BUFFERABLE;
MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE;
MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
MPU_InitStruct.Number = MPU_REGION_NUMBER1;
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
MPU_InitStruct.SubRegionDisable = 0x00;
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;

HAL_MPU_ConfigRegion(&amp;MPU_InitStruct);

/* Configure the MPU attributes as WT for SRAM */
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
MPU_InitStruct.BaseAddress = SRAM_BANK_ADDR;
MPU_InitStruct.Size = MPU_REGION_SIZE_1MB;
MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE;
MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
MPU_InitStruct.Number = MPU_REGION_NUMBER2;
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL1;
MPU_InitStruct.SubRegionDisable = 0x00;
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;

HAL_MPU_ConfigRegion(&amp;MPU_InitStruct);
       
        /* Configure the MPU QSPI flash */
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
MPU_InitStruct.BaseAddress = 0x90000000;
MPU_InitStruct.Size = MPU_REGION_SIZE_64MB;
MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE;
MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
MPU_InitStruct.Number = MPU_REGION_NUMBER3;
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
MPU_InitStruct.SubRegionDisable = 0x0;
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;

HAL_MPU_ConfigRegion(&amp;MPU_InitStruct);

/* Configure the MPU attributes FMC control registers */
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
MPU_InitStruct.BaseAddress = 0xA0000000;
MPU_InitStruct.Size = MPU_REGION_SIZE_8KB;
MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
MPU_InitStruct.IsBufferable = MPU_ACCESS_BUFFERABLE;
MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
MPU_InitStruct.Number = MPU_REGION_NUMBER4;
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
MPU_InitStruct.SubRegionDisable = 0x0;
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_DISABLE;

HAL_MPU_ConfigRegion(&amp;MPU_InitStruct);

/* Enable the MPU */
HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
}

#ifdefUSE_FULL_ASSERT

/**
* @briefReports the name of the source file and the source line number
*         where the assert_param error has occurred.
* @paramfile: pointer to the source file name
* @paramline: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* 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) */

/* Infinite loop */
while (1)
{
}
}
#endif

/**
* @}
*/

/**
* @}
*/</code></pre>

<p>&nbsp;</p>

<p><strong><span style="font-size:16px;">四、程序运行</span></strong></p>

<p>&nbsp;</p>

<p><span style="font-size: 16px;">烧写程序运行后,串口输出</span></p>

<p></p>

<p>&nbsp;</p>

<p>&nbsp;</p>
</div><script>                                        var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;"   style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
                                       
                                        if(parseInt(discuz_uid)==0){
                                                                                                (function($){
                                                        var postHeight = getTextHeight(400);
                                                        $(".showpostmsg").html($(".showpostmsg").html());
                                                        $(".showpostmsg").after(loginstr);
                                                        $(".showpostmsg").css({height:postHeight,overflow:"hidden"});
                                                })(jQuery);
                                        }                </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script>

lugl4313820 发表于 2023-10-23 16:20

<p>66666,大佬是做评测,还是比赛的项目呀?</p>

TL-LED 发表于 2023-10-23 16:46

lugl4313820 发表于 2023-10-23 16:20
66666,大佬是做评测,还是比赛的项目呀?

<p>这是测评帖</p>

freebsder 发表于 2023-10-23 17:41

<p>cubemx应该可以直接生成吧?</p>
页: [1]
查看完整版本: 【STM32F723 Discovery Kit】移植FreeRTOS系统