Delay function with and without OsIf? How do I enable OsIfSystemTimerClockRef

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Delay function with and without OsIf? How do I enable OsIfSystemTimerClockRef

跳至解决方案
3,541 次查看
pb632146
Contributor V

Hello, all the example codes use for loops for their delay functions and I do not know how reliable these would be.

 

https://community.nxp.com/t5/S32K/Delay-function-using-OSIF/td-p/1946299

However I am unable to actually add a value instead it gives me a blank drop down menu.

pb632146_0-1736819118610.png

If I end up needing to use the simple for loop + counter method, there is a bit of confusion I have there too. 

 

pb632146_1-1736819260628.png

pb632146_2-1736819272824.png

pb632146_3-1736819304470.png

 

The internal clock of the mcu 48MHz or 16MHz? I thought this delay function was supposed to be 1 second flickering but it would be either 0.1 or 0.3 respectively. I want to convert my delay function to miliseconds for usability reasons but I can not really tell what my "base clock" I am working off of even is. 

 

0 项奖励
回复
1 解答
3,257 次查看
RomanVR
NXP Employee
NXP Employee

Hi @pb632146 

Apologies for my typo in the formula. You are correct, it will convert ticks to seconds. Therefore, you can just multiply by 1,000,000 or divide the ticks by 160 just as you mention.

To update to RTD 5.0.0, you must first uninstall the RTD 3.0.0 and then download the updatesite of version 5.0.0. Below is a step-by-step guide to assist you:

Uninstalling RTD 3.0.0:

  1. In the "S32DS Extensions and Updates" menu, locate and select every package related to RTD 3.0.0.
  2. Click the uninstall button to remove them.
  3. To confirm the uninstallation, check that the packages no longer appear in the Installation Details menu, located above the Cancel button.

 RomanVR_0-1737480282480.png

Downloading and Installing RTD 5.0.0:

  1. Go to "Automotive SW - S32K3/S32M27x - Real-Time Drivers for Cortex-M".
  2. Select "S32K3_S32M27x Real-Time Drivers ASR R21-11 Version 5.0.0" and download the zip file named: "SW32K3_S32M27x_RTD_R21-11_5.0.0_D2410_DesignStudio_updatesite".
  3. Open your S32DS Extensions and Updates Menu and click on "Add Update Sites".
  4. Once added, the update site will be available for installation under the list of available packages.

 

Code Update:

Please replace the following line of code with:

"Clock_Ip_Init(&Mcu_aClockConfigPB_BOARD_InitPeripherals[0]);"

This how the clock configuration structure is defined in your project.

Let me know if this helps and if you have more doubts.

- RomanVR.

 

Best Regards!

在原帖中查看解决方案

11 回复数
3,525 次查看
pb632146
Contributor V

Actually how do I track non blocking how many miliseconds or seconds the current program has been running, or barring that just time/date stamps.

0 项奖励
回复
3,489 次查看
RomanVR
NXP Employee
NXP Employee

Hi @pb632146.

The test delays used in examples are primarily for demonstration purposes and but are not recommended for final implementations as they are blocking, and their theoretical delay value are only rough estimates.

As mentioned in the community post, to add the Osif System Timer Clock Reference,  you need to include the Mcu module in the MCAL. Alternatively, instead of adding a System Timer Clock Reference, you can directly use the Timer Clock Frequency, which is by default of 48MHz on the S32K344 device. Additionally, I suggest to refer to the S32K3xx Reference Manual available at S32K3 Microcontrollers for Automotive General Purpose to check  the default system clock frequency and the available clock sources for each S32K3 device.

Regarding the delay you mentioned, a delay with a value of 4,800,000 with the 48MHz internal clock would theoretically result in a delay > 0.1 seconds. However, this value will be always bigger since instructions take more than one clock cycle to execute. For better accuracy, I suggest to use the Osif functions available by including Osif.h library to your project once configured as seen on the community post you shared, where you can find a blocking delay function with a better precision.

If you are interested in measuring your program’s runtime more accurately, you can configure a timer with a known value, increment a counter on each interrupt, and use this to estimate the runtime. Alternatively, you can toggle a GPIO pin at the start and end of the section you wish to measure and then observe the duration of the signal with an oscilloscope.

Please let me know if you have more doubts.

- RomanVR.

Best Regards!
0 项奖励
回复
3,464 次查看
pb632146
Contributor V
I did add the MCU unit just to test the clock but running the sample code with 1000ms delay it toggles the led every 3 seconds instead of 1. What could be causing this?
0 项奖励
回复
3,462 次查看
pb632146
Contributor V

pb632146_0-1736982082585.pngpb632146_1-1736982094158.pngpb632146_2-1736982110710.pngpb632146_3-1736982118160.pngpb632146_4-1736982124020.png

 

0 项奖励
回复
3,437 次查看
pb632146
Contributor V

While the code offer microseconds to ticks, to get the other way around I would want to convert the 160MHz to 1MHz so just divide by 160 correct?

 

pb632146_0-1737012358162.png

 

0 项奖励
回复
3,469 次查看
pb632146
Contributor V
I am realizing that I was supposed to add the instance of "OsIfTimerClockFreq" if I did not want to add the MCU layer, but where do I enable that? I do not see it as an available dropdown. Or is that something not available anymore?
0 项奖励
回复
3,386 次查看
RomanVR
NXP Employee
NXP Employee

Hi @pb632146 

Due to the fact that your MCU is configured with the PLL Clock (160MHz), I recommend adding the following line to your code:
Clock_Ip_Init(&Mcu_aClockConfigPB[0]);
Additionally, ensure you include "Clock_Ip.h" library. this will update the clock reference for all the MCU modules and registers.

Regarding your question: "While the code offer microseconds to ticks, to get the other way around I would want to convert the 160MHz to 1MHz so just divide by 160 correct?" 

  • If you want to convert ticks to microseconds, you can do this by the following equation: 

    RomanVR_3-1737138100366.png considering a clock frequency of 160MHz.
  • If you want to change your clock frequency to 1MHz you need to adjust the clock  dividers as shown in the image below:
    RomanVR_4-1737138177959.png

    However, I recommend not to do this if you need the MCU for high speed applications. Also you can refer to the Chapter 24 of the S32K3XX Reference Manual to check the maximum clock ratings of each S32K3 device.

To enable the OsIf System Timer Clock Frequency to avoid adding the MCU driver, you can find it under the OsIfSystemTimerClockFreq if in Design Studio 3.5 with RTD 5.0.0

RomanVR_5-1737138248033.png

Please also share with us your development environment (Design Studio, RTD, etc.) to assist you further. Sometimes the location of certain fields may change depending on the RTD and/or the Design Studio version.

Please let me know if this helps and if you have more doubts.

- RomanVR.

Best Regards!
0 项奖励
回复
3,365 次查看
pb632146
Contributor V

I only want to convert ticks to micro/mili/seconds not change the clock frequency so the formula confirmation is appreciated, but wouldn't that formula  convert ticks to seconds not microseconds since MHz is cycles per second. 

Basically if I have 160Mhz then : 160 ticks = 1us, 160 * 1000 = 1ms, and 160 * 1000 * 1000 = 1 second correct? 

 

I am on S32DS 3.5 but my rtd only appears to be version 3.0.0? I do not see any way to update to 5.0.0

pb632146_0-1737165648100.png

Also Clock_Ip_Init(&Mcu_aClockConfigPB[0]); previously worked but now does not as it sees mcu_aclockconfigpb as undeclared and I do not know what changed

 

pb632146_1-1737165868439.png

I have attached my project folder though I do not know how to export my entire  development environment settings to help further.

 

 

 

0 项奖励
回复
3,258 次查看
RomanVR
NXP Employee
NXP Employee

Hi @pb632146 

Apologies for my typo in the formula. You are correct, it will convert ticks to seconds. Therefore, you can just multiply by 1,000,000 or divide the ticks by 160 just as you mention.

To update to RTD 5.0.0, you must first uninstall the RTD 3.0.0 and then download the updatesite of version 5.0.0. Below is a step-by-step guide to assist you:

Uninstalling RTD 3.0.0:

  1. In the "S32DS Extensions and Updates" menu, locate and select every package related to RTD 3.0.0.
  2. Click the uninstall button to remove them.
  3. To confirm the uninstallation, check that the packages no longer appear in the Installation Details menu, located above the Cancel button.

 RomanVR_0-1737480282480.png

Downloading and Installing RTD 5.0.0:

  1. Go to "Automotive SW - S32K3/S32M27x - Real-Time Drivers for Cortex-M".
  2. Select "S32K3_S32M27x Real-Time Drivers ASR R21-11 Version 5.0.0" and download the zip file named: "SW32K3_S32M27x_RTD_R21-11_5.0.0_D2410_DesignStudio_updatesite".
  3. Open your S32DS Extensions and Updates Menu and click on "Add Update Sites".
  4. Once added, the update site will be available for installation under the list of available packages.

 

Code Update:

Please replace the following line of code with:

"Clock_Ip_Init(&Mcu_aClockConfigPB_BOARD_InitPeripherals[0]);"

This how the clock configuration structure is defined in your project.

Let me know if this helps and if you have more doubts.

- RomanVR.

 

Best Regards!
3,245 次查看
pb632146
Contributor V
The clock works correctly now thank you!

Are there any issues that I might run into by uninstalling RTD and replacing it in my current environment?
0 项奖励
回复
3,228 次查看
RomanVR
NXP Employee
NXP Employee

Hi @pb632146 

I'm glad that the information helped.

By updating the RTD version, I strongly suggest to check your applications configurations, since the location of certain configuration fields and/or definitions may change and the code will not compile.

- RomanVR.

Best Regards!
0 项奖励
回复