简体   繁体   English

使用JLink和GDB读取Cortex M0 MCU的外设寄存器

[英]Reading peripheral register of Cortex M0 MCU using JLink and GDB

I'm trying to read the MCUs ADC register using GDB but I can't seem to find how it's done. 我正在尝试使用GDB读取MCU的ADC寄存器,但我似乎无法找到它是如何完成的。

Using x\\10x 0x40012708 in gdb just returns zeroes, as do any memory mapped peripheral register I try to read. gdb使用x\\10x 0x40012708只返回零,我尝试读取的任何内存映射外设寄存器也是如此。

It this possible to do? 这可能吗? If so, how is it done? 如果是这样,它是如何完成的?

Thanks! 谢谢!

I would suggest to validate that your setup is functional first. 我建议先验证您的设置是否正常。 For example, you could try to read the CPUID register which is present on all Cortex-M0 processors - see section 4.3 of the Cortex™-M0 DevicesGeneric User Guide . 例如,您可以尝试读取所有Cortex-M0处理器上的CPUID寄存器 - 请参阅“ Cortex™-M0器件通用用户指南”的第4.3节。

It is located at address 0xE000ED00, and it shall contain value 0x410CC200. 它位于地址0xE000ED00,它应包含值0x410CC200。 If you can read it, this would be a good sign. 如果你能读懂它,这将是一个好兆头。

You probably should try using J-Link commander first, then with GDB-Server and GDB. 您可能应首先尝试使用J-Link命令,然后使用GDB-Server和GDB。 I ran the procedure hereafter on an Olimex board using an LPC1114/301 Cortex-M0. 我使用LPC1114 / 301 Cortex-M0在Olimex板上运行此程序。 I was using J-Link software V5.10n , and arm-none-eabi-gdb version 7.10.1.20151217-cvs, which is part of Linaro gcc 5.2 for ARM Cortex-M processors package. 我使用的是J-Link软件V5.10n和arm-none-eabi-gdb版本7.10.1.20151217-cvs,它是Linaro gcc 5.2 for ARM Cortex-M处理器软件包的一部分。

Start JLink.exe using the following options: 使用以下选项启动JLink.exe:

jlink.exe -if SWD -speed 4000  -AutoConnect 1 -device Cortex-M0

You should see something similar to: 你应该看到类似的东西:

SEGGER J-Link Commander V5.10n (Compiled Feb 19 2016 18:39:46)
DLL version V5.10n, compiled Feb 19 2016 18:39:11<br/>
Connecting to J-Link via USB...O.K.
Firmware: J-Link ARM V8 compiled Nov 28 2014 13:44:46
Hardware version: V8.00
S/N: [My J-Link EDU Serial Number]
License(s): FlashBP, GDB
OEM: SEGGER-EDU
Emulator has Trace capability
VTref = 3.313V
Device "CORTEX-M0" selected.

Found SWD-DP with ID 0x0BB11477
Found Cortex-M0 r0p0, Little endian.
FPUnit: 4 code (BP) slots and 0 literal slots
CoreSight components:
ROMTbl 0 @ E00FF000
ROMTbl 0 [0]: FFF0F000, CID: B105E00D, PID: 000BB008 SCS
ROMTbl 0 [1]: FFF02000, CID: B105E00D, PID: 000BB00A DWT
ROMTbl 0 [2]: FFF03000, CID: B105E00D, PID: 000BB00B FPB
Cortex-M0 identified.
J-Link>

You can now read the CPUID register using the J-Link commander mem32 command, and verify the CPUID register does contain the expected value: 您现在可以使用J-Link命令mem32命令读取CPUID寄存器,并验证CPUID寄存器是否包含预期值:

J-Link>mem32  0xE000ED00,1

You should get: 你应该得到:

E000ED00 = 410CC200

If this is the case, I would say that your J-Link/Cortex-M0 setup is likely functional. 如果是这种情况,我会说你的J-Link / Cortex-M0设置可能正常运行。 We can now verify GDB Server and GDB are working fine too. 我们现在可以验证GDB服务器和GDB也正常工作。

Launch JLinkGDBServerCL.exe with the following options: 使用以下选项启动JLinkGDBServerCL.exe:
JLinkGDBServerCL.exe -if SWD -speed 4000 -device Cortex-M0
SEGGER J-Link GDB Server V5.10n Command Line Version JLinkARM.dll V5.10n (DLL compiled Feb 19 2016 18:39:11) SEGGER J-Link GDB服务器V5.10n命令行版本JLinkARM.dll V5.10n(DLL编译于2016年2月19日18:39:11)

-----GDB Server start settings-----
GDBInit file:                  none
GDB Server Listening port:     2331
SWO raw output listening port: 2332
Terminal I/O port:             2333
Accept remote connection:      localhost only
Generate logfile:              off
Verify download:               off
Init regs on start:            off
Silent mode:                   off
Single run mode:               off
Target connection timeout:     0 ms
------J-Link related settings------
J-Link Host interface:         USB
J-Link script:                 none
J-Link settings file:          none
------Target related settings------
Target device:                 Cortex-M0
Target interface:              SWD
Target interface speed:        4000kHz
Target endian:                 little

Connecting to J-Link...
J-Link is connected.
Firmware: J-Link ARM V8 compiled Nov 28 2014 13:44:46
Hardware: V8.00
S/N: [My J-Link EDU Serial Number]
OEM: SEGGER-EDU
Feature(s): FlashBP, GDB
Checking target voltage...
Target voltage: 3.31 V
Listening on TCP/IP port 2331
Connecting to target...Connected to target
Waiting for GDB connection...

Keep the GDB server running, and start GDB in an other Windows console session: 保持GDB服务器运行,并在其他Windows控制台会话中启动GDB:

arm-none-eabi-gdb
GNU gdb (GNU Tools for ARM Embedded Processors) 7.10.1.20151217-cvs
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=i686-w64-mingw32 --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".

We can now connect to GDB server, and attempt to display the content of the CPUID register again: 我们现在可以连接到GDB服务器,并尝试再次显示CPUID寄存器的内容:

(gdb) target remote localhost:2331
Remote debugging using localhost:2331
0xfffffffe in ?? ()
(gdb) monitor halt
(gdb) monitor reset
Resetting target
(gdb) x/1xw  0xE000ED00
0xe000ed00:     0x410cc200
(gdb)

If you are getting 0x410cc200 again, your J-Link/Cortex-m0/GDB Server/GDB setup should be functional, and you should now try again to read your ADC register using this command: 如果再次获得0x410cc200,则J-Link / Cortex-m0 / GDB服务器/ GDB设置应该正常工作,现在您应该再次尝试使用以下命令读取ADC寄存器:

x/1xw 0x40012708

If you were able to read the CPUID register, but not the ADC register, and if the address for the ADC register is correct, I would not have an explanation for this behavior right now - knowing the exact brand/model for the MCU you are using could of course help further. 如果您能够读取CPUID寄存器,但不能读取ADC寄存器,并且ADC寄存器的地址是否正确,我现在也无法解释此行为 - 了解MCU的确切品牌/型号使用当然可以进一步帮助。

Please note that from now on, you should specify the exact model for your MCU as the argument to the -device J-Link Commander/GDB Server options instead of Cortex-M0. 请注意,从现在开始,您应该指定MCU的确切型号作为-device J-Link Commander / GDB Server选项的参数,而不是Cortex-M0。 You can get the list by entering command ? 您可以通过输入命令获取列表? on the J-Link Commander command-prompt. 在J-Link Commander命令提示符上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM