Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpu/msp430: implement get_caller_pc #20602

Merged
merged 1 commit into from
Apr 22, 2024

Conversation

maribu
Copy link
Member

@maribu maribu commented Apr 19, 2024

Contribution description

Testing procedure

Apply the following patch:

diff --git a/examples/default/main.c b/examples/default/main.c
index b847e0e5a1..b8c6856395 100644
--- a/examples/default/main.c
+++ b/examples/default/main.c
@@ -32,6 +32,15 @@
 #include "net/gnrc.h"
 #endif
 
+static int _cmd_assert(int argc, char **argv)
+{
+    (void)argc;
+    (void)argv;
+    assert(0);
+}
+
+SHELL_COMMAND(assert_fail, "trigger a blowing assertion", _cmd_assert);
+
 int main(void)
 {
 #ifdef MODULE_NETIF

Then run

make BOARD=olimex-msp430-h1611 flash term -C examples/default 
make: Entering directory '/home/maribu/Repos/software/RIOT/master/examples/default'
Building application "default" for "olimex-msp430-h1611" with CPU "msp430".

"make" -C /home/maribu/Repos/software/RIOT/master/boards/common/init
"make" -C /home/maribu/Repos/software/RIOT/master/boards/olimex-msp430-h1611
"make" -C /home/maribu/Repos/software/RIOT/master/core
"make" -C /home/maribu/Repos/software/RIOT/master/core/lib
"make" -C /home/maribu/Repos/software/RIOT/master/cpu/msp430
"make" -C /home/maribu/Repos/software/RIOT/master/cpu/msp430/periph
"make" -C /home/maribu/Repos/software/RIOT/master/drivers
"make" -C /home/maribu/Repos/software/RIOT/master/drivers/periph_common
"make" -C /home/maribu/Repos/software/RIOT/master/drivers/saul
"make" -C /home/maribu/Repos/software/RIOT/master/drivers/saul/init_devs
"make" -C /home/maribu/Repos/software/RIOT/master/sys
"make" -C /home/maribu/Repos/software/RIOT/master/sys/auto_init
"make" -C /home/maribu/Repos/software/RIOT/master/sys/div
"make" -C /home/maribu/Repos/software/RIOT/master/sys/fmt
"make" -C /home/maribu/Repos/software/RIOT/master/sys/isrpipe
"make" -C /home/maribu/Repos/software/RIOT/master/sys/libc
"make" -C /home/maribu/Repos/software/RIOT/master/sys/malloc_thread_safe
"make" -C /home/maribu/Repos/software/RIOT/master/sys/newlib_syscalls_default
"make" -C /home/maribu/Repos/software/RIOT/master/sys/phydat
"make" -C /home/maribu/Repos/software/RIOT/master/sys/preprocessor
"make" -C /home/maribu/Repos/software/RIOT/master/sys/ps
"make" -C /home/maribu/Repos/software/RIOT/master/sys/saul_reg
"make" -C /home/maribu/Repos/software/RIOT/master/sys/shell
"make" -C /home/maribu/Repos/software/RIOT/master/sys/shell/cmds
"make" -C /home/maribu/Repos/software/RIOT/master/sys/stdio
"make" -C /home/maribu/Repos/software/RIOT/master/sys/stdio_uart
"make" -C /home/maribu/Repos/software/RIOT/master/sys/tsrb
   text	  data	   bss	   dec	   hex	filename
  15950	   192	  1144	 17286	  4386	/home/maribu/Repos/software/RIOT/master/examples/default/bin/olimex-msp430-h1611/default.elf
[INFO] mspdebug binary not found - building it from source now
[INFO] mspdebug requires readline and libusb-compat headers to build
CC= CFLAGS= make -C /home/maribu/Repos/software/RIOT/master/dist/tools/mspdebug
[INFO] mspdebug binary successfully built!
/home/maribu/Repos/software/RIOT/master/dist/tools/mspdebug/mspdebug -j --expect-id "MSP430F1611" olimex "prog /home/maribu/Repos/software/RIOT/master/examples/default/bin/olimex-msp430-h1611/default.hex"
MSPDebug version 0.25 - debugging tool for MSP430 MCUs
Copyright (C) 2009-2017 Daniel Beer <[email protected]>
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Chip info database from MSP430.dll v3.15.0.1 Copyright (C) 2013 TI, Inc.

Resetting Olimex command processor...
Initializing FET...
FET protocol version is 20000007
Set Vcc: 3000 mV
Configured for JTAG (2)
Sending reset...
Using Olimex identification procedure
Device ID: 0xf16c
  Code start address: 0x4000
  Code size         : 49152 byte = 48 kb
  RAM  start address: 0x200
  RAM  end   address: 0x9ff
  RAM  size         : 2048 byte = 2 kb
Device: MSP430F1611
Number of breakpoints: 8
fet: FET returned error code 34 (Not supported by selected interface or interface is not initialized)
fet: warning: message C_IDENT3 failed
fet: FET returned NAK
warning: device does not support power profiling
Device: MSP430F1611
Erasing...
Programming...
Writing 4096 bytes at 4000...
Writing 4096 bytes at 5000...
Writing 4096 bytes at 6000...
Writing 3850 bytes at 7000...
Writing    2 bytes at ffe6...
Writing    2 bytes at fffe...
Done, 16142 bytes total
/home/maribu/Repos/software/RIOT/master/dist/tools/pyterm/pyterm -p "/dev/ttyUSB0" -b "9600"  
Twisted not available, please install it if you want to use pyterm's JSON capabilities
2024-04-19 21:24:29,607 # Connect to serial port /dev/ttyUSB0
Welcome to pyterm!
Type '/exit' to exit.
2024-04-19 21:26:30,585 # 2024.07-devel-49-g024832-cpu/msp430/clock)
2024-04-19 21:26:30,585 # Welcome to RIOT!
> help
2024-04-19 21:26:34,783 # help
2024-04-19 21:26:34,819 # Command              Description
2024-04-19 21:26:34,855 # ---------------------------------------
2024-04-19 21:26:34,892 # assert_fail          trigger a blowing assertion
2024-04-19 21:26:34,964 # pm                   interact with layered PM subsystem
2024-04-19 21:26:35,036 # ps                   Prints information about running threads.
2024-04-19 21:26:35,072 # reboot               Reboot the node
2024-04-19 21:26:35,145 # saul                 interact with sensors and actuators using SAUL
2024-04-19 21:26:35,204 # version              Prints current RIOT_VERSION
> assert_fail
2024-04-19 21:26:37,909 # assert_fail
2024-04-19 21:26:37,910 # 4c22
2024-04-19 21:26:37,945 # *** RIOT kernel panic:
2024-04-19 21:26:37,945 # FAILED ASSERTION.
2024-04-19 21:26:37,946 # 
2024-04-19 21:26:38,054 # 	pid | name                 | state    Q | pri | stack  ( used) ( free) | base addr  | current     
2024-04-19 21:26:38,198 # 	 - | isr_stack            | -        - |   - |    256 (   -1) (  257) |     0xffff |     0xffff
2024-04-19 21:26:38,306 # 	 1 | idle                 | pending  Q |  15 |     96 (   60) (   36) |     0x11b8 |     0x11de 
2024-04-19 21:26:38,415 # 	 2 | main                 | running  Q |   7 |    640 (  418) (  222) |     0x1218 |     0x137a 
2024-04-19 21:26:38,487 # 	   | SUM                  |            |     |    992 (  478) (  514)
2024-04-19 21:26:38,488 # 
2024-04-19 21:26:38,488 # *** halted.
msp430-elf-addr2line -e examples/default/bin/olimex-msp430-h1611/default.elf --address 0x4c22
0x00004c22
/home/maribu/Repos/software/RIOT/master/examples/default/main.c:45

Issues/PRs references

None

This "implements" the `get_caller_pc()` function by simply wiring up
compiler intrinsics.
@maribu maribu added Platform: MSP Platform: This PR/issue effects MSP-based platforms Type: new feature The issue requests / The PR implemements a new feature for RIOT Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Apr 19, 2024
@github-actions github-actions bot added the Area: cpu Area: CPU/MCU ports label Apr 19, 2024
@riot-ci
Copy link

riot-ci commented Apr 19, 2024

Murdock results

✔️ PASSED

f01fb53 cpu/msp430: implement get_caller_pc

Success Failures Total Runtime
10066 0 10066 12m:22s

Artifacts

@benpicco benpicco enabled auto-merge April 22, 2024 08:41
@benpicco benpicco added this pull request to the merge queue Apr 22, 2024
@maribu
Copy link
Member Author

maribu commented Apr 22, 2024

I think btw. that this implementation would work for all platforms we support except for AVR. (The return type is void *, which is 16 bit on AVR, but there are AVR MCUs with more than 64 KiB of flash - assuming it will return an address in byte as unit. But even if it would use instructions as unit - as the program counter does - there are MCUs with more than 128 KiB flash or 64 Ki instructions.)

Maybe it would be a good cleanup to just use the builtin unless the platform has some flag set.

Merged via the queue into RIOT-OS:master with commit 3cd83c7 Apr 22, 2024
30 checks passed
@maribu maribu deleted the cpu/msp430/get_caller_pc branch April 22, 2024 12:08
@maribu
Copy link
Member Author

maribu commented Apr 22, 2024

Thx!

@mguetschow mguetschow added this to the Release 2024.07 milestone Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: cpu Area: CPU/MCU ports CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer Platform: MSP Platform: This PR/issue effects MSP-based platforms Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants