【S32DS RTD实战】-1.4-基于S32K3创建配置FreeRTOS工程-控制GPIO点亮LED

本文主要是介绍【S32DS RTD实战】-1.4-基于S32K3创建配置FreeRTOS工程-控制GPIO点亮LED,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

目录(附DEMO,可下载,讲解过程超详细)

1 下载FREERTOS RTD

1.1 安装FREERTOS RTD

2 确认S32DS已安装的AUTOSAR RTD

3 基于S32K3创建&配置FREERTOS工程

3.1 选择SDKs

3.2 增加FreeRTOS模块

3.3 修改MCU芯片封装

3.4 配置GPIO

3.5 修改HSE CLK时钟

3.5 更新代码

4 main函数解读

5  附:FreeRTOS DEMO

结尾


【S32K3_MCAL从入门到精通】合集:

S32K3_MCAL从入门到精通icon-default.png?t=N7T8https://blog.csdn.net/qfmzhu/category_12519033.html

1 下载FREERTOS RTD

打开链接S32K汽车通用MCU | NXP 半导体,网页往下翻,找到“软件”这一栏中的S32K3 Reference Software,单击其右侧的下载。

图1-1

在弹出的网页中,选择Automotive SW - S32K3 - FreeRTOS;

图1-2

在刷新的网页中,选择SW32K3_FreeRTOS_10.5.1_3.1.0_D2304;

图1-3

在刷新的网页中,单击SW32K3_FreeRTOS_10_5_1_UOS_3_1_0_DS_updatesite_D2304.zip,下载该RTD。

图1-4

1.1 安装FREERTOS RTD

参考博文【S32K3环境搭建】-0.3-S32DS安装实时驱动RTD(Real-Time Driver)icon-default.png?t=N7T8https://blog.csdn.net/qfmzhu/article/details/134843314的第2.2章节,安装FreeRTOS RTD:SW32K3_FreeRTOS_10_5_1_UOS_3_1_0_DS_updatesite_D2304.zip。

FreeRTOS RTD(Real-Time Driver)安装后的效果:在S32DS Extensions and Updates中,你会看到安装好的FreeRTOS RTD。

图1-5

2 确认S32DS已安装的AUTOSAR RTD

S32K3 RTD AUTOSAR R21-11 Version 3.0.0

S32K3xx RTD AUTOSAR R21-11 Version 3.0.0

S32K3xx development package V3.5.8

图2-1

3 基于S32K3创建&配置FREERTOS工程

S32DSProject Explorer中,鼠标右键,在其上下文中依次选择:New -- > S32DS Project from Example

图3-1

在弹出的Create S32DS Project from Example对话框中,根据自己当前使用的MCU芯片型号进行选择,这里以FreeRTOS_Toggle_Led_Example_S32K312为例,单击Finish

图3-2

注意Description中,关于该DEMO的介绍,其中包含了一些重要信息:

  (c) Copyright 2022-2023 NXPNXP Confidential. This software is owned or controlled by NXP and may only be used strictlyin accordance with the applicable license terms.  By expressly acceptingsuch terms or by downloading, installing, activating and/or otherwise usingthe software, you are agreeing that you have read, and that you agree tocomply with and are bound by, such license terms.  If you do not agree tobe bound by the applicable license terms, then you may not retain,install, activate or otherwise use the software.This file contains sample code only. It is not part of the production code deliverables.
========================================================================1. Example DescriptionLed D79-(Motherboard) - toggled using Clock, Siul2_Dio, Siul2_Port drivers and FreeRTOS.1.1 The application software functionalityThe application uses 2 tasks SendTask and ReceiveTask. If ReceiveTask receives exactly Semaphore sent by SendTask, it will change led status.The application uses Siul2_Port_Ip_Init to initialize the pins and Clock_Ip_Init to initialize the clock sources.2. Installation steps2.1 Hardware installation2.1.1 Supported boards- XS32K3X2CVB-Q172 PCB 48307 RevX1 SCH RevA (Daughter card)- X-S32K3XXX-MB PCB 47386 RevA SCH RevA (Motherboard)- S32K312EVB-Q172 50892 PCB RevA SCH RevB (EVB board)2.1.2 ConnectionsA wire connection is required between the following:- pin J290.4  (PTA_1 - gpio LED blink) to pin J290.3 (Led D79)-(Motherboard).- PTA29 is controlling the LED_RED in S32K312EVB-Q172 EVB board - when HIGH LED is ON when LOW LED is OFF.2.1.3 DebuggerThe Pemicro must be connected to J32 10-pin JTAG Cortex Debug connector.2.2 Software installation2.2.1 Importing the S32 Design Studio projectAfter opening S32 Design Studio, go to "File -> New -> S32DS Project From Example" and select this example. Then click on "Finish".The project should now be copied into your current workspace.3. Generating, building and running the example application3.1 Generating the S32 configurationBefore running the example a configuration needs to be generated. First go to Project Explorer View in S32 DS and select the current project.Select the "S32 Configuration Tool" menu then click on the desired configuration tool (Pins, Cocks, Peripherals etc...).Clicking on any one of those will generate all the components. Make the desired changes(if any) then click on the "S32 Configuration Tool->Update Code" button.3.2 Compiling the applicationSelect the configuration to be built: RAM (Debug_RAM), or FLASH (Debug_FLASH) by left clicking on the downward arrow corresponding to the build button in eclipse.Wait for the build action to be completed before continuing to the next step. Check the compiler console for error messages; upon completion, the *.elf binary fileshould be created.3.3 Running the application on the board3.3.1 Running with P&E microGo to Run and select Debug Configurations. There will be a debug configuration for this project:Configuration Name                  Description-------------------------------     -----------------------$(example)_Debug_FLASH_PNE          Debug the FLASH configuration using PEMicro Debugging$(example)_Debug_RAM_PNE            Debug the RAM configuration using PEMicro DebuggingSelect the desired debug configuration and click on Debug. Now the perspective will change to the Debug Perspective.Use the controls to control the program flow.3.3.2 Running with LauterbachTo execute the example application load the executable file to the evaluation board using the Lauterbach debugger and the debug_t32/run.cmm script.Open debug_t32/run.cmm file in text editor if want to change target memory please change the values of &load_to and &elf_file.Run this script using T32 Lauterbach debugger after making the changes.

Project Explorer中显示了S32K312的FREERTOS工程的文件结构,这里显然缺失了很多,下面我们一一配置

图3-3

3.1 选择SDKs

S32DSProject Explorer中,选中工程名称FreeRTOS_Toggle_Led_Example_S32K312,鼠标右键,在其上下文中依次选择Properties

图3-4

在弹出的Properties对话框中,选择SDKs后,选择Restore

图3-5

PlatformSDK_S32K3_2022_03_S32K312_M7对应AUTOSAR版本:S32K3 Real-Time Drivers Version 2.0.3

PlatformSDK_S32K3_S32K312_M7对应AUTOSAR版本:S32K3 RTD AUTOSAR R21-11 Version 3.0.0

加号”所在位置,表示该工程目前使用AUTOSAR RTD。这里我们默认高版本的V3.0.0,单击Apply and Close

图3-6

Project Explorer中,工程FreeRTOS_Toggle_Led_Example_S32K312,多了RTDboardgenerate文件夹。

图3-7

3.2 增加FreeRTOS模块

双击mex文件,或者单击工具栏中的Open S32 Configuration Tools

图3-8

外设中,查看OS层中,是否已经添加了FreeRTOS模块。

图3-9

3.3 修改MCU芯片封装

Pins引脚中,根据实际使用MCU封装情况,切换封装。

图3-10

图3-11

3.4 配置GPIO

在该FreeRTOS工程中,默认将PTA1和PTA29配置成了输出,详见图3-2中的Description。可根据您的PCB/开发板实际情况,在Pins引脚中,进行调整和适配。我们这里将其调整为PTB9和PTB10。

图3-12

3.5 修改HSE CLK时钟

Clocks时钟显示图中,修改HSE CLK的分频器,将其从120MHz修改为60MHz。

图3-12

3.5 更新代码

配置完成后,单击工具栏中更新代码,将配置生成代码。

图3-13

图3-14

配置完成后,在Project Explorer中,显示了FreeRTOS_Toggle_Led_Example_S32K312工程完整的结构。

图3-15

4 main函数解读

main函数中,使用xTaskCreate创建了两个Task: SendTaskReceiveTaskReceiveTask函数中间隔Siul2_Dio_Ip_TogglePins周期拉高拉低PTB9和PTB10。


/* Including necessary configuration files. */
#include "Clock_Ip.h"
#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
#include "Siul2_Port_Ip.h"
#include "Siul2_Dio_Ip.h"#define main_TASK_PRIORITY                ( tskIDLE_PRIORITY + 2 )SemaphoreHandle_t sem_handle;
volatile BaseType_t testResult = 0x33U;/**
* @brief        SendTask is used to give the semaphore
* @details      SendTask give the semaphore every 1 second
*/
void SendTask( void *pvParameters )
{(void)pvParameters;BaseType_t operation_status;for( ;; ){operation_status = xSemaphoreGive(sem_handle);configASSERT(operation_status == pdPASS);/* Not very exciting - just delay... */vTaskDelay(pdMS_TO_TICKS(1000));}
}/**
* @brief        ReceiveTask get the semaphore and toggle pins
* @details      ReceiveTask try to get the semaphore with portMAX_DELAY timeout,
*               After receiving the semaphore successfully, the led will be toggle
*               LED1_PIN <-> PTA1
*               LED2_PIN <-> PTA29
*/
void ReceiveTask( void *pvParameters )
{(void)pvParameters;BaseType_t operation_status;BaseType_t count = 0;for( ;; ){operation_status = xSemaphoreTake(sem_handle, portMAX_DELAY);configASSERT(operation_status == pdPASS);Siul2_Dio_Ip_TogglePins(LED1_PORT, (1 << LED1_PIN));Siul2_Dio_Ip_TogglePins(LED2_PORT, (1 << LED2_PIN));if(count++ > 10){testResult = 0x5AU;}}
}/**
* @brief        Main function of the example
* @details      Initializes the used drivers and uses 1 binary Semaphore and
*               2 tasks to toggle a LED.
*/
int main(void)
{/* Initialize Clock */Clock_Ip_StatusType Status_Init_Clock = CLOCK_IP_ERROR;Status_Init_Clock = Clock_Ip_Init(Clock_Ip_aClockConfig);if (Status_Init_Clock != CLOCK_IP_SUCCESS){while(1); /* Error during initialization. */}/* Initialize all pins using the Port driver */Siul2_Port_Ip_PortStatusType Status_Init_Port = SIUL2_PORT_ERROR;Status_Init_Port = Siul2_Port_Ip_Init(NUM_OF_CONFIGURED_PINS0, g_pin_mux_InitConfigArr0);if(Status_Init_Port != SIUL2_PORT_SUCCESS){while(1); /* Error during initialization. */}vSemaphoreCreateBinary(sem_handle);xTaskCreate( SendTask   , ( const char * const ) "SendTask", configMINIMAL_STACK_SIZE, (void*)0, main_TASK_PRIORITY, NULL );xTaskCreate( ReceiveTask, ( const char * const ) "RecTask" , configMINIMAL_STACK_SIZE, (void*)0, main_TASK_PRIORITY + 1, NULL );vTaskStartScheduler();for( ;; );return 0;
}

5  附:FreeRTOS DEMO

该博文,附上了配置好的FreeRTOS DEMO下载链接。

结尾

获取更多“汽车电子资讯”和“工具链使用”,

请关注CSDN博客“汽车电子助手”,做您的好助手。

这篇关于【S32DS RTD实战】-1.4-基于S32K3创建配置FreeRTOS工程-控制GPIO点亮LED的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/523743

相关文章

Linux线程之线程的创建、属性、回收、退出、取消方式

《Linux线程之线程的创建、属性、回收、退出、取消方式》文章总结了线程管理核心知识:线程号唯一、创建方式、属性设置(如分离状态与栈大小)、回收机制(join/detach)、退出方法(返回/pthr... 目录1. 线程号2. 线程的创建3. 线程属性4. 线程的回收5. 线程的退出6. 线程的取消7.

Linux下进程的CPU配置与线程绑定过程

《Linux下进程的CPU配置与线程绑定过程》本文介绍Linux系统中基于进程和线程的CPU配置方法,通过taskset命令和pthread库调整亲和力,将进程/线程绑定到特定CPU核心以优化资源分配... 目录1 基于进程的CPU配置1.1 对CPU亲和力的配置1.2 绑定进程到指定CPU核上运行2 基于

MySQL 多列 IN 查询之语法、性能与实战技巧(最新整理)

《MySQL多列IN查询之语法、性能与实战技巧(最新整理)》本文详解MySQL多列IN查询,对比传统OR写法,强调其简洁高效,适合批量匹配复合键,通过联合索引、分批次优化提升性能,兼容多种数据库... 目录一、基础语法:多列 IN 的两种写法1. 直接值列表2. 子查询二、对比传统 OR 的写法三、性能分析

Spring Boot spring-boot-maven-plugin 参数配置详解(最新推荐)

《SpringBootspring-boot-maven-plugin参数配置详解(最新推荐)》文章介绍了SpringBootMaven插件的5个核心目标(repackage、run、start... 目录一 spring-boot-maven-plugin 插件的5个Goals二 应用场景1 重新打包应用

Java中读取YAML文件配置信息常见问题及解决方法

《Java中读取YAML文件配置信息常见问题及解决方法》:本文主要介绍Java中读取YAML文件配置信息常见问题及解决方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要... 目录1 使用Spring Boot的@ConfigurationProperties2. 使用@Valu

创建Java keystore文件的完整指南及详细步骤

《创建Javakeystore文件的完整指南及详细步骤》本文详解Java中keystore的创建与配置,涵盖私钥管理、自签名与CA证书生成、SSL/TLS应用,强调安全存储及验证机制,确保通信加密和... 目录1. 秘密键(私钥)的理解与管理私钥的定义与重要性私钥的管理策略私钥的生成与存储2. 证书的创建与

浅析Spring如何控制Bean的加载顺序

《浅析Spring如何控制Bean的加载顺序》在大多数情况下,我们不需要手动控制Bean的加载顺序,因为Spring的IoC容器足够智能,但在某些特殊场景下,这种隐式的依赖关系可能不存在,下面我们就来... 目录核心原则:依赖驱动加载手动控制 Bean 加载顺序的方法方法 1:使用@DependsOn(最直

Python办公自动化实战之打造智能邮件发送工具

《Python办公自动化实战之打造智能邮件发送工具》在数字化办公场景中,邮件自动化是提升工作效率的关键技能,本文将演示如何使用Python的smtplib和email库构建一个支持图文混排,多附件,多... 目录前言一、基础配置:搭建邮件发送框架1.1 邮箱服务准备1.2 核心库导入1.3 基础发送函数二、

Jenkins分布式集群配置方式

《Jenkins分布式集群配置方式》:本文主要介绍Jenkins分布式集群配置方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1.安装jenkins2.配置集群总结Jenkins是一个开源项目,它提供了一个容易使用的持续集成系统,并且提供了大量的plugin满

PowerShell中15个提升运维效率关键命令实战指南

《PowerShell中15个提升运维效率关键命令实战指南》作为网络安全专业人员的必备技能,PowerShell在系统管理、日志分析、威胁检测和自动化响应方面展现出强大能力,下面我们就来看看15个提升... 目录一、PowerShell在网络安全中的战略价值二、网络安全关键场景命令实战1. 系统安全基线核查