如何从.s启动文件跳转到main

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

如何从.s启动文件跳转到main

1,987 Views
bingyin
Contributor I

在startup_MK60F12.s中,

    .

    .

    .

    LDR     R0, =__main

    BX      R0

在最后一语句跑飞,到Hard_Fault_Handler

怎么能跳转到main?

Labels (1)
0 Kudos
9 Replies

1,435 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Bing Yin,

我想确认一下你跑的是官方例程呢,还是自己创建的,你使用IDE是什么,这样我可以发你官方的start_xx_.s文件?

Ping
Have a great day,
Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,435 Views
bingyin
Contributor I

Hi Ping,

感谢你的答复!我用的IDE是uVision V4.50.0.0. Toolchain:MDK-ARM Standard. 跑的是官方例程,在C:\Keil450\ARM\Startup\Freescale\Kinetis\ 下的startup_MK60F12.s和system_MK60F12.c 文件。

Thank you again!

Bing

0 Kudos

1,435 Views
jeremyzhou
NXP Employee
NXP Employee

Hi,

一般在跳转main之前,需要配置时钟模式,你检查一下例程与你所使用的板子是否匹配,还有你可以根据此贴去查找到hardfault的原因。

【经验分享】CW10.x编译环境查找HardFault异常原因 - 恩智浦FAE线上技术支持 - 恩智浦技术社区 - 手机版 - Powered by Discuz!

Hope it hleps.
Have a great day,
Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,435 Views
bingyin
Contributor I

Hi

我看过startup_MK60F12.s和system_MK60F12.c,在执行

LDR R0, =__main

BX R0

之前,已经配置了系统时钟。但是没有把中断向量表、已初始化的数据从ROM复制到RAM,也没有将 .bss段清零。所以__main可能不是用户的应用程序main,而是需完成上述任务的系统程序;跑飞的原因是找不到__main。

请你们看看是否是这样的情形,以及能否提供那一段系统程序(至少包含上述未完成的任务)?

Thank you!

Bing

0 Kudos

1,435 Views
jeremyzhou
NXP Employee
NXP Employee

Hi,

你说的init_data_bss(void)不是关键,没有它也是工程也是可以运行的,我认为既然你使用的是例程,肯定代码本身是没问题的,而代码工程与板子不对应才是关键。

我上传了最新的启动文件,头文件,你可以参考一下。


Have a great day,
Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,435 Views
bingyin
Contributor I

Hi

我比较了一下你上传的4个文件,除了MK61F12.H文件,其它3个文件system_MK60F12.H、startup_MK60F12.s、system_MK60F12.c与我工程中的文件完全一样。也许这个文件MK61F12.H传错了,应该是MK60F12.H?

如果我将startup_MK60F12.s文件中的__main改为main,即将(LDR R0, =__main)改为(LDR R0, =main)等等,那么是可以跳转到我的应用程序main()中运行的。

这样改是否正确?是否只改这一点就可以了?

Thank you!

Bing

0 Kudos

1,435 Views
jeremyzhou
NXP Employee
NXP Employee

Hi,
那么你改了以后,代码可以正常运行吗?

因为这启动代码是MDK ARM提供的,应该不会有什么错误的,建议你上传一下工程,我这边跑一下试试。
Have a good weekend,
Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,435 Views
bingyin
Contributor I

Hi,

我前几天出差去了,所以现在才给你回邮件。

附件是调试ADC的工程文件,__main已经改为main, 在我的板子运行正常,能得到正确的AD值。我想在你的板子上也能正常运行。因为程序简单。

如果带上RTOS或者要用DSP功能,就不知能否正常运行了?

Have a good weekend,

Bing

0 Kudos

1,435 Views
jeremyzhou
NXP Employee
NXP Employee

Hi,

挺奇怪的,我用Keil 自带的TWR-K60D100M例程,未对main做任何修改就是OK的。

我再check一下,如果发现问题再知晓你。
Have a great day,
Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos