S32K312 ITCM代码使用示例

        在上一篇文章中,介绍了S32K312 DTCM在代码中使用示例,具体可以参考配置文件的编辑,本文主要介绍ITCM的代码使用和调试。ITCM是将功能代码放到了高速缓存中,一方面频繁调用的函数可以快速访问,提高效率;另一方面比如操作S32K312的FLASH代码区的时候,可以实现擦除和写入。

        测试代码如下:

/* Including necessary configuration files. */
#include "Mcal.h"

volatile int exit_code = 0;
/* User includes */

void TestDelay(uint32 delay);
void __attribute__ ((section(".itcm0_code"))) Test_function_in_ITCM(void);


void TestDelay(uint32 delay)
{
    static volatile uint32 DelayTimer = 0;
    while(DelayTimer<delay)
    {
        DelayTimer++;
    }
    DelayTimer=0;
}

void __attribute__ ((section(".itcm0_code"))) Test_function_in_ITCM(void)
{
	TestDelay(4800000);
}

uint32_t __attribute__ ((section(".dtcm0_data"))) myDtcm0Data[1024] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
uint32_t __attribute__ ((section(".dtcm0_data"))) myDtcm0Data1[1024] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

void local_func(void)
{
	uint8_t tmp = 0;
	for(tmp = 0; tmp < 10; tmp++)
	{
		(void)tmp;
	}
}

/*!
  \brief The main function for the project.
  \details The startup initialization sequence is the following:
 * - startup asm routine
 * - main()
*/
int main(void)
{
    /* Write your code here */
	uint8 count = 0U;
	for(count = 0; count < 10; count++)
	{
		Test_function_in_ITCM();
		local_func();
		myDtcm0Data[count] = myDtcm0Data1[count] + 10;
	}
    for(;;)
    {
        if(exit_code != 0)
        {
            break;
        }
    }
    return exit_code;
}

        验证Test_function_in_ITCM()这个方法,是运行在ITCM区中,debug查看函数方法的地址,

        方法的地址是0x00,与ITCM的地址范围匹配,

        再查看local_func()函数方法的地址,正常没有指定ITCM区的方法,函数地址应该在FLASH中

        local_func()函数地址在0x40166c的FLASH区中,满足在FLASH区中

        到此,就可以成功使用ITCM的功能了。

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值