当前位置: 首页 > news >正文

MSPM0 环境搭建

下载资源清单

资源描述
mspm0_sdk_2_09_00_01MSPM0 Software Development Kit. The MSPM0 SDK provides the ultimate collection of software, tools and documentation to accelerate the development of applications for the MSPM0 MCU platform under a single software package.Download
CCSTUDIOCode Composer Studio™ integrated development environment (IDE)Download
SEGGER J-LinksSEGGER J-Links are the most widely used line of debug probes available todayDownload

第一个项目

导入项目

  1. 点击下图Import Projects
  2. 选定项目目录
  3. 根据开发板修改Blink LED

配置

  1. 打开项目properties
  2. 配置SEGGER JLINK
  3. 配置ARM HEX Utility

    3.1 General Options

    3.2 Output format Options

Build & Flash Project

代码解析

main.c

intmain(void){/* Prepare the hardware to run this demo. */prvSetupHardware();main_blinky();return0;}
  • prvSetupHardware():执行硬件相关初始化(在本文件中最终调用了 SYSCFG_DL_init()),准备外设/时钟等以供后续任务使用。
  • main_blinky():启动 blinky 示例程序,通常会在该函数中创建 FreeRTOS 任务并启动调度器(例如调用 vTaskStartScheduler),因此正常情况下该函数不会返回。

main_blinky.c

/* Kernel includes. */#include"FreeRTOS.h"#include"semphr.h"#include"task.h"/* TI includes. */#include"ti_msp_dl_config.h"/* Priorities at which the tasks are created. */#definemainQUEUE_RECEIVE_TASK_PRIORITY(tskIDLE_PRIORITY+2)#definemainQUEUE_SEND_TASK_PRIORITY(tskIDLE_PRIORITY+1)/* * The rate at which data is sent to the queue. The 1s (1000ms) value is * converted to ticks using the pdMS_TO_TICKS constant. */#definemainQUEUE_SEND_FREQUENCY_MS(pdMS_TO_TICKS(1000UL))/* * The number of items the queue can hold. This is 1 as the receive task * will remove items as they are added, meaning the send task should always * find the queue empty. */#definemainQUEUE_LENGTH(1)/* * Values passed to the two tasks just to check the task parameter * functionality. */#definemainQUEUE_SEND_PARAMETER(0x1111UL)#definemainQUEUE_RECEIVE_PARAMETER(0x22UL)/*-----------------------------------------------------------*//* The tasks as described in the comments at the top of this file. */staticvoidprvQueueReceiveTask(void*pvParameters);staticvoidprvQueueSendTask(void*pvParameters);/* Called by main() to create the simply blinky style application */voidmain_blinky(void);/*-----------------------------------------------------------*//* The queue used by both tasks. */staticQueueHandle_t xQueue=NULL;/*-----------------------------------------------------------*/voidmain_blinky(void){/* Create the queue. */xQueue=xQueueCreate(mainQUEUE_LENGTH,sizeof(uint32_t));if(xQueue!=NULL){/* * Start the two tasks as described in the comments at the top of this * file. */xTaskCreate(prvQueueReceiveTask,/* The function that implements the task. */"Rx",/* The text name assigned to the task - for debug only as it is not used by the kernel. */configMINIMAL_STACK_SIZE,/* The size of the stack to allocate to the task. */(void*)mainQUEUE_RECEIVE_PARAMETER,/* The parameter passed to the task - just to check the functionality. */mainQUEUE_RECEIVE_TASK_PRIORITY,/* The priority assigned to the task. */NULL);/* The task handle is not required, so NULL is passed. */xTaskCreate(prvQueueSendTask,"TX",configMINIMAL_STACK_SIZE,(void*)mainQUEUE_SEND_PARAMETER,mainQUEUE_SEND_TASK_PRIORITY,NULL);/* Start the tasks. */vTaskStartScheduler();}/* * If all is well, the scheduler will now be running, and the following * line will never be reached. If the following line does execute, then * there was insufficient FreeRTOS heap memory available for the idle * and/or timer tasks to be created. See the memory management section on * the FreeRTOS web site for more details. */for(;;);}/*-----------------------------------------------------------*/staticvoidprvQueueSendTask(void*pvParameters){TickType_t xNextWakeTime;constunsignedlongulValueToSend=100UL;/* Check the task parameter is as expected. */configASSERT(((unsignedlong)pvParameters)==mainQUEUE_SEND_PARAMETER);/* Initialize xNextWakeTime - this only needs to be done once. */xNextWakeTime=xTaskGetTickCount();for(;;){/* * Place this task in the blocked state until it is time to run again. * The block time is specified in ticks, the constant used converts * ticks to ms. While in the Blocked state this task will not consume * any CPU time. */vTaskDelayUntil(&xNextWakeTime,mainQUEUE_SEND_FREQUENCY_MS);/* * Send to the queue - causing the queue receive task to unblock and * toggle the LED. 0 is used as the block time so the sending operation * will not block - it shouldn't need to block as the queue should always * be empty at this point in the code. */xQueueSend(xQueue,&ulValueToSend,0U);}}/*-----------------------------------------------------------*/staticvoidprvQueueReceiveTask(void*pvParameters){unsignedlongulReceivedValue;staticconstTickType_t xShortBlock=pdMS_TO_TICKS(50);/* Check the task parameter is as expected. */configASSERT(((unsignedlong)pvParameters)==mainQUEUE_RECEIVE_PARAMETER);for(;;){/* * Wait until something arrives in the queue - this task will block * indefinitely provided INCLUDE_vTaskSuspend is set to 1 in * FreeRTOSConfig.h. */xQueueReceive(xQueue,&ulReceivedValue,portMAX_DELAY);/* * To get here something must have been received from the queue, but * is it the expected value? If it is, toggle the LED. */if(ulReceivedValue==100UL){/* * Blip the LED for a short while so as not to use too much * power. */DL_GPIO_togglePins(GPIO_LEDS_PORT,GPIO_LEDS_USER_LED_1_PIN);vTaskDelay(xShortBlock);DL_GPIO_togglePins(GPIO_LEDS_PORT,GPIO_LEDS_USER_LED_1_PIN);ulReceivedValue=0U;}}}

用任务与队列实现一个“1 秒闪烁一次 LED”的简单应用。程序创建一个长度为 1 的队列和两个任务:发送任务每秒向队列发送一个固定值,接收任务从队列读取值并在值匹配时短暂点亮(翻转)LED。

关键宏与全局

  • mainQUEUE_SEND_FREQUENCY_MS:发送周期,pdMS_TO_TICKS(1000) → 1 秒。
  • mainQUEUE_LENGTH:队列长度为 1。
  • mainQUEUE_SEND_PARAMETER / mainQUEUE_RECEIVE_PARAMETER:传递给任务的参数,用于 configASSERT 校验。
  • xQueue:静态声明的队列句柄(QueueHandle_t)。

main_blinky()(程序入口逻辑)

  1. 调用 xQueueCreate 创建队列(项大小为 uint32_t)。
  2. 若队列创建成功:
  • 创建接收任务 prvQueueReceiveTask(优先级较高)。
  • 创建发送任务 prvQueueSendTask(优先级较低)。
  • 调用 vTaskStartScheduler 启动调度器(通常不会返回)。
  1. 若调度器无法启动则进入无限空循环(表明堆内存不足以创建空闲或定时器任务)。

发送任务:prvQueueSendTask

  • 使用 xTaskGetTickCount 和 vTaskDelayUntil 实现周期调度(节省漂移)。
  • 每次唤醒后通过 xQueueSend 将常量 100UL 发送到队列(阻塞时间 0,期望队列为空)。

接收任务:prvQueueReceiveTask

  • 使用 xQueueReceive(…, portMAX_DELAY) 永久阻塞等待队列数据。
  • 收到数据后,如果值为 100UL,调用 DL_GPIO_togglePins 翻转用户 LED,引入短延时(vTaskDelay)以“眨一下”LED,然后再翻转回去。
http://www.cnnetsun.cn/news/174326.html

相关文章:

  • Android ---【经验篇】项目上线前工序:部署 SpringBoot 项目(二)
  • 还在盲目集成测试工具?Open-AutoGLM与SOAtest的6个致命区别你必须知道
  • 基于springboot+vue的Web的出租车拼车系统(源码+lw+部署文档+讲解等)
  • 基于springboot+vue的Vue和SpringBoot的城市环保行政执法系统(源码+lw+部署文档+讲解等)
  • 基于VUE的教师培训在线管理平台[VUE]-计算机毕业设计源码+LW文档
  • 【自动化测试平台选型避坑指南】:从Open-AutoGLM到Tosca的7项适配指标实测对比
  • Open-AutoGLM vs JMeter:性能测试如何选择?3大维度全面解析
  • Open-AutoGLM 与 BrowserStack 兼容性对比(稀缺内部数据首次公开)
  • Open-AutoGLM与Sauce Labs兼容性深度剖析:90%团队忽略的4个核心参数
  • 【前端自动化测试避坑指南】:Open-AutoGLM与Cypress在移动端的真实表现对比
  • 【AI测试工具新标杆】:Open-AutoGLM如何以0.1ms响应精度碾压Ranorex?
  • Open-AutoGLM 与 Playwright 到底怎么选?:3大核心维度全面测评,90%的人都忽略了这一点
  • 【顶级测试架构师亲授】:Open-AutoGLM对接Sauce Labs的7步完美适配法
  • 大数据时代MongoDB的性能瓶颈与解决办法
  • 【Open-AutoGLM vs Applitools】:谁才是视觉测试的终极王者?
  • 【专家亲测】Open-AutoGLM与UiPath操作复杂度全面拆解(含学习曲线数据)
  • Open-AutoGLM vs WinAutomation:高并发场景下谁更稳定?(实测结果曝光)
  • 为什么你的自动化项目失败了?Open-AutoGLM与Power Automate适配性全剖析
  • Thinkphp和Laravel框架社区物业车位缴费房屋充电桩管理系统 论文
  • 你真的了解Open-AutoGLM与Katalon Studio的适配边界吗?
  • 【测试工程师必看】Open-AutoGLM与Katalon Studio适配差异的5大关键点
  • 【自动化平台选型避坑指南】:Open-AutoGLM与Power Automate 6大场景实测对比
  • Vue3+TypeScript+Element-Plus确认对话框ElMessageBox.confirm
  • 企业流程自动化怎么选,Open-AutoGLM和Power Automate到底差在哪?
  • 为什么99%的人没发挥Open-AutoGLM全部潜力?,解锁隐藏的动态权重调优功能
  • 批量打印神器,太流批了
  • 【Java毕设全套源码+文档】基于springboot的大学生兼职平台设计与实现(丰富项目+远程调试+讲解+定制)
  • 从零开始学昇腾Ascend C算子开发-第四篇:常用算子实现
  • 学术迷航中的“智能罗盘”:书匠策AI如何重塑本科硕士论文写作新范式
  • 为什么90%的企业都在用Open-AutoGLM做客户信息归档?真相曝光