<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:wfw="http://wellformedweb.org/CommentAPI/">
<channel>
<title>JRNitre&#039;s Blog - CubeMX</title>
<link>https://blog.atoery.cn/index.php/tag/cubemx/</link>
<atom:link href="https://blog.atoery.cn/index.php/feed/tag/cubemx/" rel="self" type="application/rss+xml" />
<language>zh-CN</language>
<description></description>
<lastBuildDate>Wed, 16 Apr 2025 21:41:29 +0800</lastBuildDate>
<pubDate>Wed, 16 Apr 2025 21:41:29 +0800</pubDate>
<item>
<title>[FreeRTOS] 堆和栈的基本概念&amp;amp;在FreeRTOS中的使用</title>
<link>https://blog.atoery.cn/index.php/2025/04/16/92.html</link>
<guid>https://blog.atoery.cn/index.php/2025/04/16/92.html</guid>
<pubDate>Wed, 16 Apr 2025 21:41:29 +0800</pubDate>
<dc:creator>JRNitre</dc:creator>
<description><![CDATA[1.0 堆1.1 基本概念堆的本质是在 RAM 中的一段连续的内存区域，开发者可以主动申请一些内存块，其中与栈不同的是，堆的声明周期是完全由程序员进行控制的。1.2 堆的管理机制动态性碎片化风险...]]></description>
<content:encoded xml:lang="zh-CN"><![CDATA[
<h1>1.0 堆</h1><h1>1.1 基本概念</h1><p>堆的本质是在 RAM 中的一段连续的内存区域，开发者可以主动申请一些内存块，其中与栈不同的是，堆的声明周期是完全由程序员进行控制的。</p><h1>1.2 堆的管理机制</h1><ul><li>动态性</li><li>碎片化风险</li><li>手动管理</li></ul><h1>1.3 例子</h1><p>在 C/C++ 中，定义一个变量时，其存储位置取决于其定义位置上下文：</p><ul><li>如果在函数内定义，则其存储在栈中。</li><li>若在全局或静态作用域定义，则存储在静态存储区。</li></ul><p>真正的堆内存必须通过动态分配函数进行显示申请。</p><pre><code>char heap_buf[1024];    // 若在函数内进行申请，则存储在栈中，函数结束后自动释放</code></pre><p>-</p><pre><code>char* heap_buf = (char*)malloc(1024);   // 显式申请堆内存
</code></pre><h1>2.0 栈</h1><h2>2.1 基本概念</h2><p>栈是一种先进后出的数据结构，其基本操作通常包括：压栈和弹栈。</p><h2>2.2 栈的特点</h2><ul><li>后进先出 (LIFO)</li><li>高效性</li><li>有限容量 (固定大小栈)</li><li>自动管理：在嵌入式系统中，函数调用时使用的栈由编译器和处理器自动管理，无需程序员手动干预。</li></ul><h1>3.0 RTOS 如何使用栈</h1><h1>END 参考 & 声明</h1><p><strong>[参考]</strong></p><ul><li>FreeRTOS入门与工程实践 --由浅入深带你学习FreeRTOS（FreeRTOS教程 基于STM32，以实际项目为导向） -&gt; <em>BV1Jw411i7Fz</em></li></ul><blockquote>本文部分内容由 Ai 辅助生成</blockquote>
]]></content:encoded>
<slash:comments>0</slash:comments>
<comments>https://blog.atoery.cn/index.php/2025/04/16/92.html#comments</comments>
<wfw:commentRss>https://blog.atoery.cn/index.php/feed/tag/cubemx/</wfw:commentRss>
</item>
<item>
<title>[FreeRTOS] 学习记录 - 创建一个多任务程序</title>
<link>https://blog.atoery.cn/index.php/2025/04/14/90.html</link>
<guid>https://blog.atoery.cn/index.php/2025/04/14/90.html</guid>
<pubDate>Mon, 14 Apr 2025 22:44:58 +0800</pubDate>
<dc:creator>JRNitre</dc:creator>
<description><![CDATA[HAL 库版本在使用 CubeMX 初始化的 FreeRTOS 工程后，可以选择默认创建一个线程（名称可配置），位于 freertos.c 中：/* creation of mainTask *...]]></description>
<content:encoded xml:lang="zh-CN"><![CDATA[
<h1>HAL 库版本</h1><p>在使用 CubeMX 初始化的 FreeRTOS 工程后，可以选择默认创建一个线程（名称可配置），位于 <code>freertos.c</code> 中：</p><pre><code>/* creation of mainTask */
mainTaskHandle = osThreadNew(StartDefaultTask, NULL, &amp;mainTask_attributes);
/* USER CODE BEGIN RTOS_THREADS */</code></pre><p>创建一个新的任务，则需要使用 <code>xTaskCreate</code> 函数，这个函数的声明如下：</p><pre><code>BaseType_t xTaskCreate( TaskFunction_t pxTaskCode,
                        const char * const pcName,
                        const configSTACK_DEPTH_TYPE usStackDepth,
                        void * const pvParameters,
                        UBaseType_t uxPrioity,
                        TaskHandle_t * const pxCreateTask );</code></pre><ul><li><code>TaskFunction_t pxTaskCode</code>：指定的运行函数</li><li><code>const char * const pcName</code>：名字</li><li><code>const configSTACK_DEPTH_TYPE usStackDepth</code>：栈的深度</li><li><code>void * const pvParameters</code>：参数</li><li><code>UBaseType_t uxPrioity</code>：优先级</li><li><code>TaskHandle_t * const pxCreateTask</code>：句柄</li></ul><p>创建一个任务用于串口发送数据：</p><pre><code>xTaskCreate(usartTask, &quot;usartTask&quot;, 128, NULL, osPriorityNormal, NULL);</code></pre><pre><code>void usartTask(void *argument){
        while(1){
            printf(&quot;usart task is run!\n&quot;);
            HAL_Delay(500);
    }
}</code></pre><h1>标准库版本</h1>
]]></content:encoded>
<slash:comments>0</slash:comments>
<comments>https://blog.atoery.cn/index.php/2025/04/14/90.html#comments</comments>
<wfw:commentRss>https://blog.atoery.cn/index.php/feed/tag/cubemx/</wfw:commentRss>
</item>
</channel>
</rss>