当前位置:   article > 正文

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

sw32k3_freertos

目录(附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的介绍,其中包含了一些重要信息:

  1. (c) Copyright 2022-2023 NXP
  2. NXP Confidential. This software is owned or controlled by NXP and may only be used strictly
  3. in accordance with the applicable license terms. By expressly accepting
  4. such terms or by downloading, installing, activating and/or otherwise using
  5. the software, you are agreeing that you have read, and that you agree to
  6. comply with and are bound by, such license terms. If you do not agree to
  7. be bound by the applicable license terms, then you may not retain,
  8. install, activate or otherwise use the software.
  9. This file contains sample code only. It is not part of the production code deliverables.
  10. ========================================================================
  11. 1. Example Description
  12. Led D79-(Motherboard) - toggled using Clock, Siul2_Dio, Siul2_Port drivers and FreeRTOS.
  13. 1.1 The application software functionality
  14. The application uses 2 tasks SendTask and ReceiveTask. If ReceiveTask receives exactly Semaphore sent by SendTask, it will change led status.
  15. The application uses Siul2_Port_Ip_Init to initialize the pins and Clock_Ip_Init to initialize the clock sources.
  16. 2. Installation steps
  17. 2.1 Hardware installation
  18. 2.1.1 Supported boards
  19. - XS32K3X2CVB-Q172 PCB 48307 RevX1 SCH RevA (Daughter card)
  20. - X-S32K3XXX-MB PCB 47386 RevA SCH RevA (Motherboard)
  21. - S32K312EVB-Q172 50892 PCB RevA SCH RevB (EVB board)
  22. 2.1.2 Connections
  23. A wire connection is required between the following:
  24. - pin J290.4 (PTA_1 - gpio LED blink) to pin J290.3 (Led D79)-(Motherboard).
  25. - PTA29 is controlling the LED_RED in S32K312EVB-Q172 EVB board - when HIGH LED is ON when LOW LED is OFF.
  26. 2.1.3 Debugger
  27. The Pemicro must be connected to J32 10-pin JTAG Cortex Debug connector.
  28. 2.2 Software installation
  29. 2.2.1 Importing the S32 Design Studio project
  30. After opening S32 Design Studio, go to "File -> New -> S32DS Project From Example" and select this example. Then click on "Finish".
  31. The project should now be copied into your current workspace.
  32. 3. Generating, building and running the example application
  33. 3.1 Generating the S32 configuration
  34. Before running the example a configuration needs to be generated. First go to Project Explorer View in S32 DS and select the current project.
  35. Select the "S32 Configuration Tool" menu then click on the desired configuration tool (Pins, Cocks, Peripherals etc...).
  36. 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.
  37. 3.2 Compiling the application
  38. Select 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.
  39. 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 file
  40. should be created.
  41. 3.3 Running the application on the board
  42. 3.3.1 Running with P&E micro
  43. Go to Run and select Debug Configurations. There will be a debug configuration for this project:
  44. Configuration Name Description
  45. ------------------------------- -----------------------
  46. $(example)_Debug_FLASH_PNE Debug the FLASH configuration using PEMicro Debugging
  47. $(example)_Debug_RAM_PNE Debug the RAM configuration using PEMicro Debugging
  48. Select the desired debug configuration and click on Debug. Now the perspective will change to the Debug Perspective.
  49. Use the controls to control the program flow.
  50. 3.3.2 Running with Lauterbach
  51. To execute the example application load the executable file to the evaluation board using the Lauterbach debugger and the debug_t32/run.cmm script.
  52. 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.
  53. 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。

  1. /* Including necessary configuration files. */
  2. #include "Clock_Ip.h"
  3. #include "FreeRTOS.h"
  4. #include "task.h"
  5. #include "semphr.h"
  6. #include "Siul2_Port_Ip.h"
  7. #include "Siul2_Dio_Ip.h"
  8. #define main_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
  9. SemaphoreHandle_t sem_handle;
  10. volatile BaseType_t testResult = 0x33U;
  11. /**
  12. * @brief SendTask is used to give the semaphore
  13. * @details SendTask give the semaphore every 1 second
  14. */
  15. void SendTask( void *pvParameters )
  16. {
  17. (void)pvParameters;
  18. BaseType_t operation_status;
  19. for( ;; )
  20. {
  21. operation_status = xSemaphoreGive(sem_handle);
  22. configASSERT(operation_status == pdPASS);
  23. /* Not very exciting - just delay... */
  24. vTaskDelay(pdMS_TO_TICKS(1000));
  25. }
  26. }
  27. /**
  28. * @brief ReceiveTask get the semaphore and toggle pins
  29. * @details ReceiveTask try to get the semaphore with portMAX_DELAY timeout,
  30. * After receiving the semaphore successfully, the led will be toggle
  31. * LED1_PIN <-> PTA1
  32. * LED2_PIN <-> PTA29
  33. */
  34. void ReceiveTask( void *pvParameters )
  35. {
  36. (void)pvParameters;
  37. BaseType_t operation_status;
  38. BaseType_t count = 0;
  39. for( ;; )
  40. {
  41. operation_status = xSemaphoreTake(sem_handle, portMAX_DELAY);
  42. configASSERT(operation_status == pdPASS);
  43. Siul2_Dio_Ip_TogglePins(LED1_PORT, (1 << LED1_PIN));
  44. Siul2_Dio_Ip_TogglePins(LED2_PORT, (1 << LED2_PIN));
  45. if(count++ > 10)
  46. {
  47. testResult = 0x5AU;
  48. }
  49. }
  50. }
  51. /**
  52. * @brief Main function of the example
  53. * @details Initializes the used drivers and uses 1 binary Semaphore and
  54. * 2 tasks to toggle a LED.
  55. */
  56. int main(void)
  57. {
  58. /* Initialize Clock */
  59. Clock_Ip_StatusType Status_Init_Clock = CLOCK_IP_ERROR;
  60. Status_Init_Clock = Clock_Ip_Init(Clock_Ip_aClockConfig);
  61. if (Status_Init_Clock != CLOCK_IP_SUCCESS)
  62. {
  63. while(1); /* Error during initialization. */
  64. }
  65. /* Initialize all pins using the Port driver */
  66. Siul2_Port_Ip_PortStatusType Status_Init_Port = SIUL2_PORT_ERROR;
  67. Status_Init_Port = Siul2_Port_Ip_Init(NUM_OF_CONFIGURED_PINS0, g_pin_mux_InitConfigArr0);
  68. if(Status_Init_Port != SIUL2_PORT_SUCCESS)
  69. {
  70. while(1); /* Error during initialization. */
  71. }
  72. vSemaphoreCreateBinary(sem_handle);
  73. xTaskCreate( SendTask , ( const char * const ) "SendTask", configMINIMAL_STACK_SIZE, (void*)0, main_TASK_PRIORITY, NULL );
  74. xTaskCreate( ReceiveTask, ( const char * const ) "RecTask" , configMINIMAL_STACK_SIZE, (void*)0, main_TASK_PRIORITY + 1, NULL );
  75. vTaskStartScheduler();
  76. for( ;; );
  77. return 0;
  78. }

5  附:FreeRTOS DEMO

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

结尾

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

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/144488
推荐阅读
相关标签
  

闽ICP备14008679号