cruelfox 发表于 2020-4-19 00:26

STM32MP157A-DK1测评 (3) Cortex-A7点个灯

<div class='showpostmsg'> 本帖最后由 cruelfox 于 2020-4-19 08:46 编辑

<p>  虽然我已可以使用板载的ST-Link通过SWD口对 STM32MP157 进行调试,但却在实验中遇到意外情况,总之OpenOCD中调试操作并不像对STM32系列MCU那样顺利。我对 OpenOCD 背后的调试原理不熟悉,又是头一次对付 Cortex-A7 核,所以在这里遇到些障碍。</p>

<p>  比如,用 halt 命令停止 CPU 的执行时,可能明显出现等待,然后OpenOCD报个错<br />
<span style="font-family:Courier;"><span style="background-color:#ecf0f1;">&gt; <strong>halt</strong></span><br />
<span style="background-color:#ecf0f1;">stm32mp15x.cpu0 rev 5, partnum c07, arch f, variant 0, implementor 41</span><br />
<span style="background-color:#ecf0f1;">stm32mp15x.cpu0 cluster 0 core 0 multi core</span><br />
<span style="color:#e74c3c;"><span style="background-color:#ecf0f1;">Timeout waiting for halt</span></span></span></p>

<p>  比如遇到 step 命令不能单步执行(PC寄存器无变化)的状态。</p>

<p>  更要命的是,在以前对 Cortex-M 进行复位初始化我用的 reset init 命令不能正常用了。<br />
<span style="font-family:Courier;"><span style="background-color:#ecf0f1;">&gt; <strong>reset init</strong></span><br />
<span style="background-color:#ecf0f1;">ap 0 selected, csw 0x10006000</span><br />
<span style="background-color:#ecf0f1;">mem2array: Read @ 0x50001000, w=4, cnt=1, failed</span><br />
<span style="background-color:#ecf0f1;">mem2array: Read @ 0x50000208, w=4, cnt=1, failed</span><br />
<span style="background-color:#ecf0f1;">SRST line asserted</span><br />
<span style="background-color:#ecf0f1;">SRST line released</span><br />
<span style="background-color:#ecf0f1;">stlink_connect(connect)</span><br />
<span style="background-color:#ecf0f1;">SWD DPIDR 0x6ba02477</span><br />
<span style="color:#e74c3c;"><span style="background-color:#ecf0f1;">timed out while waiting for target halted</span></span><br />
<span style="background-color:#ecf0f1;">stm32mp15x.cpu0 rev 5, partnum c07, arch f, variant 0, implementor 41</span><br />
<span style="background-color:#ecf0f1;">target halted in Thumb state due to debug-request, current mode: Supervisor</span><br />
<span style="background-color:#ecf0f1;">cpsr: 0x800001f3 pc: 0x00010b6a</span><br />
<span style="background-color:#ecf0f1;">MMU: enabled, D-Cache: disabled, I-Cache: enabled</span><br />
<span style="background-color:#ecf0f1;">ap 0 selected, csw 0x10006000</span><br />
<span style="background-color:#ecf0f1;">pc (/32): 0x00010B6A</span><br />
<span style="background-color:#ecf0f1;">stm32mp15x.cpu1: ran after reset and before halt ...</span><br />
<span style="color:#e74c3c;"><span style="background-color:#ecf0f1;">Timeout waiting for halt</span></span><br />
<span style="background-color:#ecf0f1;">embedded:startup.tcl:24: <span style="color:#e74c3c;">Error</span>:</span><br />
<span style="background-color:#ecf0f1;">in procedure &#39;ocd_process_reset&#39;</span><br />
<span style="background-color:#ecf0f1;">in procedure &#39;ocd_process_reset_inner&#39; called at file &quot;embedded:startup.tcl&quot;, line 261</span><br />
<span style="background-color:#ecf0f1;">in procedure &#39;arp_reset_default_handler&#39;</span><br />
<span style="background-color:#ecf0f1;">in procedure &#39;arp_reset_plan_srst_dbg_gated&#39; called at file &quot;embedded:startup.tcl&quot;, line 387</span><br />
<span style="background-color:#ecf0f1;">in procedure &#39;stm32mp15x.cpu1&#39; called at file &quot;embedded:startup.tcl&quot;, line 339</span><br />
<span style="background-color:#ecf0f1;">in procedure &#39;ocd_bouncer&#39;</span><br />
<span style="background-color:#ecf0f1;">at file &quot;embedded:startup.tcl&quot;, line 24</span></span></p>

<p><span style="font-family:Courier;"><span style="background-color:#ecf0f1;">Deferring arp_examine of stm32mp15x.cpu2</span><br />
<span style="background-color:#ecf0f1;">Use arp_examine command to examine it manually!</span><br />
<span style="background-color:#ecf0f1;">Deferring arp_examine of stm32mp15x.ap2</span><br />
<span style="background-color:#ecf0f1;">Use arp_examine command to examine it manually!</span><br />
<span style="color:#e74c3c;"><span style="background-color:#ecf0f1;">timed out while waiting for target halted</span></span><br />
<span style="background-color:#ecf0f1;">TARGET: stm32mp15x.cpu1 - <span style="color:#e74c3c;">Not halted</span></span></span><br />
&nbsp;</p>

<p>  假如 reset init 命令能让CPU复位成执行第一条指令之前的状态,那就能定位到程序入口开始跟踪执行过程。对付 Cortex-m 系列我经常这么干的。现在这一招失效,于是一连上调试器并不知道执行的是什么程序。如果是 Linux 运行状态下可能是某个程序或者内核中,如果是 u-boot 期间那多半是 u-boot 的代码。如果TF卡不插入上电的话,那应该就是 ROM bootloader 中的程序,这些是可以推断的。</p>

<p>  但是 halt 超时等现象就不知道是什么梗了。</p>

<p>&nbsp;</p>

<p>  根据手册中的内存映射表,可以知道4G空间的最低地址 0x0 是 ROM bootloader 所在的地方,然后 0x10000000 开始有几块 SRAM, 而对 A7 核最重要的 SYSRAM 在 0x2FFC0000 处。0x40000000 开始有硬件设备的寄存器,和 STM32 MCU 相似。<br />
</p>

<p>  然而,在ROM程序阶段介入调试,用 OpenOCD 内存查看命令竟然出错:</p>

<p><span style="font-family:Courier;"><span style="background-color:#ecf0f1;">&gt; <strong>mdb 0 16</strong></span><br />
<span style="background-color:#ecf0f1;">data abort at 0x00000000, dfsr = 0x00000008</span></span></p>

<p><span style="font-family:Courier;"><span style="background-color:#ecf0f1;">&gt; <strong>mdb 0x10000000 16</strong></span><br />
<span style="background-color:#ecf0f1;">data abort at 0x10000000, dfsr = 0x00000005</span></span></p>

<p><span style="font-family:Courier;"><span style="background-color:#ecf0f1;">&gt; <strong>mdb 0x2ffc0000 16</strong></span><br />
<span style="background-color:#ecf0f1;">data abort at 0x2ffc0000, dfsr = 0x00000008</span></span></p>

<p><span style="font-family:Courier;"><span style="background-color:#ecf0f1;">&gt; <strong>mdb 0x30000000 16</strong></span><br />
<span style="background-color:#ecf0f1;">0x30000000: 08 00 00 30 68 02 00 30 00 00 00 00 00 00 00 00</span></span></p>

<p><span style="font-family:Courier;"><span style="background-color:#ecf0f1;">&gt; <strong>mdw 0x40000000 16</strong></span><br />
<span style="background-color:#ecf0f1;">data abort at 0x40000000, dfsr = 0x00000007</span></span></p>

<p>  试了几处地址,除了 RAM alias 区域开头可以读访问之外,其它几个地方竟然不能读?这就费解了,程序在 ROM 中运行,又如何不能读ROM? 查看 PC 寄存器,执行的地址是 ROM 区没错:</p>

<p><span style="font-family:Courier;"><span style="background-color:#ecf0f1;">&gt; <strong>reg pc</strong></span><br />
<span style="background-color:#ecf0f1;">pc (/32): 0x0000A396</span></span><br />
那么就看这个地址,是可以读取的<br />
&gt; <strong>mdb 0xA396 16</strong><br />
0x0000a396: f8 49 c0 1b 88 42 07 d9 07 f0 c9 fb 26 ea 05 05<br />
&gt; <strong>arm disassemble 0xA396 4 thumb</strong><br />
0x0000a396 &nbsp;0x49f8 &nbsp; &nbsp; &nbsp;LDR &nbsp; &nbsp; r1, &nbsp; &nbsp; &nbsp; &nbsp;; 0x0000a778<br />
0x0000a398 &nbsp;0x1bc0 &nbsp; &nbsp; &nbsp;SUBS &nbsp; &nbsp;r0, r0, r7<br />
0x0000a39a &nbsp;0x4288 &nbsp; &nbsp; &nbsp;CMP &nbsp; &nbsp; r0, r1<br />
0x0000a39c &nbsp;0xd907 &nbsp; &nbsp; &nbsp;BLS &nbsp; &nbsp; 0x0000a3ae<br />
  看来&nbsp;ROM 的部分地址被屏蔽了,这可能是启用了保护机制,可能是 MMU (内存管理单元) 控制了的原因。由于不能用 reset init 停在复位之后的状态调试,现在经过 ROM 程序的初始化之后,现场是什么样我不知晓。</p>

<p>  从 SP 寄存器看来,的确 SYSRAM 还能部分访问的。</p>

<p><span style="font-family:Courier;"><span style="background-color:#ecf0f1;">&gt; <strong>reg sp</strong></span><br />
<span style="background-color:#ecf0f1;">sp (/32): 0x2FFC1BE0</span><br />
<span style="background-color:#ecf0f1;">&gt; <strong>mdw 0x2ffc1000 4</strong></span><br />
<span style="background-color:#ecf0f1;">0x2ffc1000: 260148df 0640bac1 077ff997 4e5e4a05</span></span><br />
  再找个设备的寄存器呢,看看 GPIOA (从手册可以查到地址范围 0x50002000 ~ 0x500023FF)<br />
<span style="font-family:Courier;"><span style="background-color:#ecf0f1;">&gt; <strong>mdw 0x50002000 4</strong></span><br />
<span style="background-color:#ecf0f1;">0x50002000: f7ffffbf 00002000 0c0000c0 00000000</span></span></p>

<p>  说明 GPIOA 可以访问。那么我可以动动手脚,先写段 LED 点灯的程序跑下试试。</p>

<p>&nbsp;</p>

<p>  在官方的 STM32Cube_FW_MP1_V1.2.0 这个软件包里,我像往常对待 STM32 MCU 那样找出了 stm32mp157axx_ca7.h 这个寄存器定义文件,一看内容和 STM32 MCU 很像嘛!<br />
  这样就可以通过寄存器操作开始玩它了。先点灯,只需要操作 GPIO. (因为 ROM 程序已经把一些初始化工作做了)</p>

<p>  根据电路图,有两个用户 LED 就在 PA13, PA14 上,同时还连着按钮。<br />
  那么点灯程序这样写:</p>

<pre>
<code class="language-cpp">#include "stm32mp157axx_ca7.h"

void _start(void)
{
        int i;
        GPIOA-&gt;MODER = 1&lt;&lt;13*2|1&lt;&lt;14*2|~(3&lt;&lt;13*2|3&lt;&lt;14*2);
        for(;;)
        {
                if(GPIOA-&gt;ODR &amp; 1&lt;&lt;14)
                        GPIOA-&gt;BRR = 1&lt;&lt;14;
                else
                        GPIOA-&gt;BSRR = 1&lt;&lt;14;
                for(i=0;i&lt;10000;i++)
                {
                        int n;
                        if(GPIOA-&gt;ODR &amp; 1&lt;&lt;13)
                                GPIOA-&gt;BRR = 1&lt;&lt;13;
                        else
                                GPIOA-&gt;BSRR = 1&lt;&lt;13;
                        for(n=0;n&lt;100;n++)
                        {
                                __NOP();
               /////总共100条 NOP 指令,这里为了页面空间省略了
                                __NOP();
                        }
                }
        }
}</code></pre>

<p>  因为这里我只是写了一个程序片段,没有初始化代码(不需要,没有全局变量),不用到标准库,都不用写 main()</p>

<p>  然后先试试编译,用以前开发 STM32 那个 GCC 行不行呢?</p>

<p><span style="color:#16a085;"><strong><span style="font-family:Arial;"><span style="font-size:16px;">E:\stm32mp157\a7&gt;arm-none-eabi-gcc -mcpu=cortex-a7 -Os test.c -c -std=gnu99</span></span></strong></span></p>

<p>  这样可以编译的(加 -std=gnu99 是因为使用的头文件需要)。那就看下编译后的代码:</p>

<p><span style="color:#16a085;"><strong><span style="font-size:16px;"><span style="font-family:Arial;">E:\stm32mp157\a7&gt;arm-none-eabi-objdump -d test.o</span></span></strong></span></p>

<p><span style="font-family:Courier;">test.o: &nbsp; &nbsp; file format elf32-littlearm</span></p>

<p><span style="font-family:Courier;">Disassembly of section .text:</span></p>

<p><span style="font-family:Courier;">00000000 &lt;_start&gt;:<br />
&nbsp; &nbsp;0: &nbsp; e59f31e0 &nbsp; &nbsp; &nbsp; &nbsp;ldr &nbsp; &nbsp; r3, &nbsp;; 1e8 &lt;_start+0x1e8&gt;<br />
&nbsp; &nbsp;4: &nbsp; e3e0230a &nbsp; &nbsp; &nbsp; &nbsp;mvn &nbsp; &nbsp; r2, #671088640 &nbsp;; 0x28000000<br />
&nbsp; &nbsp;8: &nbsp; e5832000 &nbsp; &nbsp; &nbsp; &nbsp;str &nbsp; &nbsp; r2, <br />
&nbsp; &nbsp;c: &nbsp; e59f31d4 &nbsp; &nbsp; &nbsp; &nbsp;ldr &nbsp; &nbsp; r3, &nbsp;; 1e8 &lt;_start+0x1e8&gt;<br />
&nbsp; 10: &nbsp; e5932014 &nbsp; &nbsp; &nbsp; &nbsp;ldr &nbsp; &nbsp; r2, <br />
&nbsp; 14: &nbsp; e3120901 &nbsp; &nbsp; &nbsp; &nbsp;tst &nbsp; &nbsp; r2, #16384 &nbsp; &nbsp; &nbsp;; 0x4000<br />
&nbsp; 18: &nbsp; e3a02901 &nbsp; &nbsp; &nbsp; &nbsp;mov &nbsp; &nbsp; r2, #16384 &nbsp; &nbsp; &nbsp;; 0x4000<br />
&nbsp; 1c: &nbsp; 15832028 &nbsp; &nbsp; &nbsp; &nbsp;strne &nbsp; r2, &nbsp; ; 0x28<br />
&nbsp; 20: &nbsp; 05832018 &nbsp; &nbsp; &nbsp; &nbsp;streq &nbsp; r2, <br />
&nbsp; 24: &nbsp; e3023710 &nbsp; &nbsp; &nbsp; &nbsp;movw &nbsp; &nbsp;r3, #10000 &nbsp; &nbsp; &nbsp;; 0x2710<br />
&nbsp; 28: &nbsp; e59f21b8 &nbsp; &nbsp; &nbsp; &nbsp;ldr &nbsp; &nbsp; r2, &nbsp;; 1e8 &lt;_start+0x1e8&gt;<br />
&nbsp; 2c: &nbsp; e5921014 &nbsp; &nbsp; &nbsp; &nbsp;ldr &nbsp; &nbsp; r1, <br />
&nbsp; 30: &nbsp; e3110a02 &nbsp; &nbsp; &nbsp; &nbsp;tst &nbsp; &nbsp; r1, #8192 &nbsp; &nbsp; &nbsp; ; 0x2000<br />
&nbsp; 34: &nbsp; e3a01a02 &nbsp; &nbsp; &nbsp; &nbsp;mov &nbsp; &nbsp; r1, #8192 &nbsp; &nbsp; &nbsp; ; 0x2000<br />
&nbsp; 38: &nbsp; 15821028 &nbsp; &nbsp; &nbsp; &nbsp;strne &nbsp; r1, &nbsp; ; 0x28<br />
&nbsp; 3c: &nbsp; 05821018 &nbsp; &nbsp; &nbsp; &nbsp;streq &nbsp; r1, <br />
&nbsp; 40: &nbsp; e3a02064 &nbsp; &nbsp; &nbsp; &nbsp;mov &nbsp; &nbsp; r2, #100 &nbsp; &nbsp; &nbsp; &nbsp;; 0x64</span><br />
&nbsp;</p>

<p>  看起来正常,那么把它弄到 STM32MP157 的 SRAM 里面运行一下。因为这段代码没有使用除了GPIOA之外的绝对内存地址,放到任何地址运行都是可以的。将编译结果二进制文件提取出来:</p>

<p><span style="color:#16a085;"><strong><span style="font-size:16px;"><span style="font-family:Arial;">E:\stm32mp157\a7&gt;arm-none-eabi-objcopy -Obinary test.o test.bin</span></span></strong></span></p>

<p>  然后,用 OpenOCD 的命令将其写到内存地址 0x2FFC4000 (先确认过这块可访问)<br />
<span style="font-family:Courier;"><span style="background-color:#ecf0f1;">&gt; </span><strong><span style="background-color:#ecf0f1;">load_image e:/stm32mp157/a7/test.bin 0x2FFC4000</span></strong><br />
<span style="background-color:#ecf0f1;">492&nbsp;bytes written at address 0x2ffc4000</span><br />
<span style="background-color:#ecf0f1;">downloaded 492&nbsp;bytes in 0.062500s (1.500 KiB/s)</span></span><br />
  程序写到 SRAM 里面了,然后就运行它:让 CPU 恢复执行,从 0x2FFC4000 处开始。<br />
<span style="font-family:Courier;"><span style="background-color:#ecf0f1;">&gt; <strong>resume 0x2FFC4000</strong></span><br />
<span style="background-color:#ecf0f1;">stm32mp15x.cpu0 rev 5, partnum c07, arch f, variant 0, implementor 41</span><br />
<span style="color:#c0392b;"><span style="background-color:#ecf0f1;">Timeout waiting for halt</span></span><br />
<span style="background-color:#ecf0f1;">Polling target stm32mp15x.cpu0 failed, trying to reexamine</span><br />
<span style="background-color:#ecf0f1;">stm32mp15x.cpu0: hardware has 6 breakpoints, 4 watchpoints</span></span></p>

<p>  出了问题,而且 PC 寄存器就停留在 0x2FFC4000</p>

<p><span style="font-family:Courier;"><span style="background-color:#ecf0f1;">&gt; <strong>reg pc</strong></span><br />
<span style="background-color:#ecf0f1;">pc (/32): 0x2FFC4000</span></span><br />
&nbsp;</p>

<p>  我查看了下 CPSR, 发现 T 位是置1的,那么就给取消一下试试。因为我编译的代码是 ARM 模式的。</p>

<p><span style="font-family:Courier;"><span style="background-color:#ecf0f1;">&gt; <strong>reg cpsr</strong></span><br />
<span style="background-color:#ecf0f1;">cpsr (/32): 0x800001F3</span></span></p>

<p><span style="font-family:Courier;"><span style="background-color:#ecf0f1;">&gt; <strong>reg cpsr 0x1d3</strong></span><br />
<span style="background-color:#ecf0f1;">cpsr (/32): 0x000001D3</span></span></p>

<p><span style="font-family:Courier;"><span style="background-color:#ecf0f1;">&gt; <strong>resume</strong></span></span></p>

<p>&nbsp;</p>

<p>  然后,LED开始闪烁,运行了!</p>

<p>  看LED LD6(红色)上面的波形</p>

<p>  因为我在代码中每次修改这个引脚 (PA13) 状态,间隔了10000条NOP指令,可以估算下每条 NOP 指令执行时间:25.1us/10000 = 2.51ns, &nbsp;若以每条 NOP 指令一个时钟周期的速度执行的话,大约是 400MHz&nbsp;的时钟。这只是揣测,不一定对。<br />
<br />
<b><font color="#5E7384">此内容由EEWORLD论坛网友<font size="3">cruelfox</font>原创,如需转载或用于商业用途需征得作者同意并注明出处</font></b></p>
</div><script>                                        var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;"   style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
                                       
                                        if(parseInt(discuz_uid)==0){
                                                                                                (function($){
                                                        var postHeight = getTextHeight(400);
                                                        $(".showpostmsg").html($(".showpostmsg").html());
                                                        $(".showpostmsg").after(loginstr);
                                                        $(".showpostmsg").css({height:postHeight,overflow:"hidden"});
                                                })(jQuery);
                                        }                </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script>

cruelfox 发表于 2020-4-19 10:26

<p>  32位的ARM处理器有 ARM 和 Thumb 两种指令编码模式,上面实验我是生成的&nbsp;ARM 模式代码,从反汇编可以看到每条指令以&nbsp;32-bit 字长为基本单位编码。而 Cortex-m 系列的 MCU 只支持 Thumb 模式,每条指令字长是 16-bit 为基本单位的。这也意味着 ARM 模式下 PC 寄存器地址是4字节对齐的,而 Thumb 模式下是2字节对齐。</p>

<p>  Cortex-A7 当然也可以用 Thumb 模式运行程序。如上面的程序,如果编译时 GCC 加上 -mthumb 选项,那么就生成 Thumb 代码。</p>

<p><span style="color:#16a085"><strong>E:\stm32mp157\a7&gt;arm-none-eabi-gcc -mcpu=cortex-a7 -Os test.c -c -std=gnu99 -mthumb</strong></span></p>

<p><span style="color:#16a085"><strong>E:\stm32mp157\a7&gt;arm-none-eabi-objdump -d test.o</strong></span></p>

<p>test.o: &nbsp; &nbsp; file format elf32-littlearm</p>

<p>Disassembly of section .text:</p>

<p>00000000 &lt;_start&gt;:<br />
&nbsp; &nbsp;0: &nbsp; 4b40 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ldr &nbsp; &nbsp; r3, &nbsp;; (104 &lt;_start+0x104&gt;)<br />
&nbsp; &nbsp;2: &nbsp; f06f 5220 &nbsp; &nbsp; &nbsp; mvn.w &nbsp; r2, #671088640 &nbsp;; 0x28000000<br />
&nbsp; &nbsp;6: &nbsp; 601a &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;str &nbsp; &nbsp; r2, <br />
&nbsp; &nbsp;8: &nbsp; 4b3e &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ldr &nbsp; &nbsp; r3, &nbsp;; (104 &lt;_start+0x104&gt;)<br />
&nbsp; &nbsp;a: &nbsp; 695a &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ldr &nbsp; &nbsp; r2, <br />
&nbsp; &nbsp;c: &nbsp; f412 4f80 &nbsp; &nbsp; &nbsp; tst.w &nbsp; r2, #16384 &nbsp; &nbsp; &nbsp;; 0x4000<br />
&nbsp; 10: &nbsp; f44f 4280 &nbsp; &nbsp; &nbsp; mov.w &nbsp; r2, #16384 &nbsp; &nbsp; &nbsp;; 0x4000<br />
&nbsp; 14: &nbsp; bf14 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ite &nbsp; &nbsp; ne<br />
&nbsp; 16: &nbsp; 629a &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;strne &nbsp; r2, &nbsp; ; 0x28<br />
&nbsp; 18: &nbsp; 619a &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;streq &nbsp; r2, <br />
&nbsp; 1a: &nbsp; f242 7310 &nbsp; &nbsp; &nbsp; movw &nbsp; &nbsp;r3, #10000 &nbsp; &nbsp; &nbsp;; 0x2710<br />
&nbsp; 1e: &nbsp; 4a39 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ldr &nbsp; &nbsp; r2, &nbsp;; (104 &lt;_start+0x104&gt;)<br />
&nbsp; 20: &nbsp; 6951 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ldr &nbsp; &nbsp; r1, <br />
&nbsp; 22: &nbsp; f411 5f00 &nbsp; &nbsp; &nbsp; tst.w &nbsp; r1, #8192 &nbsp; &nbsp; &nbsp; ; 0x2000<br />
&nbsp; 26: &nbsp; f44f 5100 &nbsp; &nbsp; &nbsp; mov.w &nbsp; r1, #8192 &nbsp; &nbsp; &nbsp; ; 0x2000<br />
&nbsp; 2a: &nbsp; bf14 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ite &nbsp; &nbsp; ne<br />
&nbsp; 2c: &nbsp; 6291 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;strne &nbsp; r1, &nbsp; ; 0x28<br />
&nbsp; 2e: &nbsp; 6191 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;streq &nbsp; r1, <br />
&nbsp; 30: &nbsp; 2264 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;movs &nbsp; &nbsp;r2, #100 &nbsp; &nbsp; &nbsp; &nbsp;; 0x64<br />
&nbsp; 32: &nbsp; bf00 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nop<br />
&nbsp; 34: &nbsp; bf00 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nop<br />
  尺寸上 Thumb 指令占用的空间要省不少。用同样的方式可以把程序载入到 STM32MP157 的 SRAM 中运行。CPU 如果在 ARM 模式则要设置成 Thumb 模式再运行。</p>

<p>  用了 Thumb 模式,Cortex-A7 和 Cortex-m 系列的差别又缩小一步。那么它是否可以执行 Cortex-m0/m3 的指令呢?我想多半是没有问题的,Cortex-A7 覆盖的指令集更大。上面这段程序的话,用 -mcpu=cortex-a7 和 -mcpu=cortex-m3 生成的 Thumb 代码完全一样。</p>
页: [1]
查看完整版本: STM32MP157A-DK1测评 (3) Cortex-A7点个灯