Skip to content

sys/arduino: replace xtimer by ztimer as high-level background timer#15317

Merged
fjmolinas merged 2 commits intoRIOT-OS:masterfrom
aabadie:pr/sys/arduino_ztimer
Jun 17, 2021
Merged

sys/arduino: replace xtimer by ztimer as high-level background timer#15317
fjmolinas merged 2 commits intoRIOT-OS:masterfrom
aabadie:pr/sys/arduino_ztimer

Conversation

@aabadie
Copy link
Copy Markdown
Contributor

@aabadie aabadie commented Oct 27, 2020

Contribution description

This PR replaces xtimer by ztimer as high-level background timer for delay/delayMicroseconds/millis/micros functions.

Testing procedure

  • A green Murdock
  • tests/sys_arduino should still work:
nucleo-l412kb
$ BUILD_IN_DOCKER=1 RIOT_VERSION=test make BOARD=nucleo-l412kb -C tests/sys_arduino --no-print-directory flash test
Launching build container using image "riot/riotbuild:latest".
docker run --rm --tty --user $(id -u) -v '/usr/share/zoneinfo/Europe/Paris:/etc/localtime:ro' -v '/work/riot/RIOT:/data/riotbuild/riotbase:delegated' -e 'RIOTBASE=/data/riotbuild/riotbase' -e 'CCACHE_BASEDIR=/data/riotbuild/riotbase' -e 'BUILD_DIR=/data/riotbuild/riotbase/build' -e 'RIOTPROJECT=/data/riotbuild/riotbase' -e 'RIOTCPU=/data/riotbuild/riotbase/cpu' -e 'RIOTBOARD=/data/riotbuild/riotbase/boards' -e 'RIOTMAKE=/data/riotbuild/riotbase/makefiles'      -e 'BOARD=nucleo-l412kb' -e 'RIOT_VERSION=test'  -w '/data/riotbuild/riotbase/tests/sys_arduino/' 'riot/riotbuild:latest' make 'BOARD=nucleo-l412kb'    
Building application "tests_sys_arduino" for "nucleo-l412kb" with MCU "stm32".

"make" -C /data/riotbuild/riotbase/boards/nucleo-l412kb
"make" -C /data/riotbuild/riotbase/boards/common/nucleo
"make" -C /data/riotbuild/riotbase/core
"make" -C /data/riotbuild/riotbase/cpu/stm32
"make" -C /data/riotbuild/riotbase/cpu/cortexm_common
"make" -C /data/riotbuild/riotbase/cpu/cortexm_common/periph
"make" -C /data/riotbuild/riotbase/cpu/stm32/periph
"make" -C /data/riotbuild/riotbase/cpu/stm32/stmclk
"make" -C /data/riotbuild/riotbase/cpu/stm32/vectors
"make" -C /data/riotbuild/riotbase/drivers
"make" -C /data/riotbuild/riotbase/drivers/periph_common
"make" -C /data/riotbuild/riotbase/sys
"make" -C /data/riotbuild/riotbase/sys/arduino
"make" -C /data/riotbuild/riotbase/sys/auto_init
"make" -C /data/riotbuild/riotbase/sys/frac
"make" -C /data/riotbuild/riotbase/sys/isrpipe
"make" -C /data/riotbuild/riotbase/sys/newlib_syscalls_default
"make" -C /data/riotbuild/riotbase/sys/pm_layered
"make" -C /data/riotbuild/riotbase/sys/stdio_uart
"make" -C /data/riotbuild/riotbase/sys/test_utils/interactive_sync
"make" -C /data/riotbuild/riotbase/sys/tsrb
"make" -C /data/riotbuild/riotbase/sys/ztimer
"make" -C /data/riotbuild/riotbase/tests/sys_arduino/bin/nucleo-l412kb/arduino_sketches
   text	   data	    bss	    dec	    hex	filename
  21692	    176	   2820	  24688	   6070	/data/riotbuild/riotbase/tests/sys_arduino/bin/nucleo-l412kb/tests_sys_arduino.elf
/work/riot/RIOT/dist/tools/openocd/openocd.sh flash /work/riot/RIOT/tests/sys_arduino/bin/nucleo-l412kb/tests_sys_arduino.elf
### Flashing Target ###
Open On-Chip Debugger 0.10.0+dev-01406-gca211373d-dirty (2020-10-26-22:35)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
hla_swd
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
srst_only separate srst_nogate srst_open_drain connect_assert_srst

Info : clock speed 500 kHz
Info : STLINK V2J31M21 (API v2) VID:PID 0483:374B
Info : Target voltage: 3.243158
Info : stm32l4x.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : starting gdb server for stm32l4x.cpu on 0
Info : Listening on port 38363 for gdb connections
    TargetName         Type       Endian TapName            State       
--  ------------------ ---------- ------ ------------------ ------------
 0* stm32l4x.cpu       hla_target little stm32l4x.cpu       reset

Info : Unable to match requested speed 500 kHz, using 480 kHz
Info : Unable to match requested speed 500 kHz, using 480 kHz
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08000fc8 msp: 0x20000200
Info : device idcode = 0x10006464 (STM32L41/L42xx - Rev: A)
Info : flash size = 128kbytes
Info : flash mode : single-bank
Info : Padding image section 1 at 0x0800556c with 4 bytes (bank write end alignment)
Warn : Adding extra erase range, 0x08005570 .. 0x080057ff
auto erase enabled
wrote 21872 bytes from file /work/riot/RIOT/tests/sys_arduino/bin/nucleo-l412kb/tests_sys_arduino.elf in 1.149167s (18.587 KiB/s)

verified 21868 bytes in 0.802228s (26.620 KiB/s)

Info : Unable to match requested speed 500 kHz, using 480 kHz
Info : Unable to match requested speed 500 kHz, using 480 kHz
shutdown command invoked
Done flashing
r
/work/riot/RIOT/dist/tools/pyterm/pyterm -p "/dev/ttyACM0" -b "115200" --no-reconnect --noprefix --no-repeat-command-on-empty-line 
Twisted not available, please install it if you want to use pyterm's JSON capabilities
Connect to serial port /dev/ttyACM0
Welcome to pyterm!
Type '/exit' to exit.
READY
s
START
main(): This is RIOT! (Version: test)
Hello Arduino!
wrang
UNK
echo quite long string echoing on arduino module test
ECHO: quite long string echoing on arduino module test
numb 4242
4242 4242 1092 10222
time
5233391 5270134 5306862 OK END
print
print(int, BIN): 11111111111111111111101011000111
println(int, BIN): 11111111111111111111101011000111
print(int, OCT): 37777775307
println(int, OCT): 37777775307
print(int, DEC): -1337
println(int, DEC): -1337
print(int, HEX): fffffac7
println(int, HEX): fffffac7
print(unsigned int, BIN): 101010
println(unsigned int, BIN): 101010
print(unsigned int, OCT): 52
println(unsigned int, OCT): 52
print(unsigned int, DEC): 42
println(unsigned int, DEC): 42
print(unsigned int, HEX): 2a
println(unsigned int, HEX): 2a
print(long, BIN): 10110110011010011111110100101110
println(long, BIN): 10110110011010011111110100101110
print(long, OCT): 26632376456
println(long, OCT): 26632376456
print(long, DEC): -1234567890
println(long, DEC): -1234567890
print(long, HEX): b669fd2e
println(long, HEX): b669fd2e
print(unsigned long, BIN): 1001001100101100000001011010010
println(unsigned long, BIN): 1001001100101100000001011010010
print(unsigned long, OCT): 11145401322
println(unsigned long, OCT): 11145401322
print(unsigned long, DEC): 1234567890
println(unsigned long, DEC): 1234567890
print(unsigned long, HEX): 499602d2
println(unsigned long, HEX): 499602d2

Issues/PRs references

None

@aabadie aabadie added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Area: arduino API Area: Arduino wrapper API labels Oct 27, 2020
@aabadie aabadie added Area: timers Area: timer subsystems CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Oct 27, 2020
@aabadie aabadie force-pushed the pr/sys/arduino_ztimer branch from 1e71a7a to 26bed0f Compare October 28, 2020 09:45
@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Oct 28, 2020

Hmm the tests/sys_arduino application doesn't fit anymore on arduino-uno when built on Murdock. It fits if I use RIOT_VERSION=test locally...

@fjmolinas
Copy link
Copy Markdown
Contributor

Ztimer seems to just be heavier:

  • master
   text	   data	    bss	    dec	    hex	filename
  12164	    480	   1341	  13985	   36a1	/home/francisco/workspace/RIOT/tests/sys_arduino/bin/arduino-uno/tests_sys_arduino.elf
  • pr
   text	   data	    bss	    dec	    hex	filename
  13746	    532	   1354	  15632	   3d10	/home/francisco/workspace/RIOT/tests/sys_arduino/bin/arduino-uno/tests_sys_arduino.elf

@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Nov 4, 2020

Ztimer seems to just be heavier

And tests/sys_arduino doesn't fit anymore on arduino-uno, which is a bit a problem.

@aabadie aabadie removed the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Nov 12, 2020
@fjmolinas
Copy link
Copy Markdown
Contributor

So what is the conclusion here @aabadie? Should we move forward? Can we refactor the application so more constant data is stored in FLASH?

@fjmolinas
Copy link
Copy Markdown
Contributor

Ping @aabadie do you still care about this one?

@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Feb 23, 2021

do you still care about this one?

A bit, but we should first fix the problem with ztimer msec backend selection if RTT is available and frequency is fast enough. Are you willing to work on that ? That would be awesome :)

@fjmolinas
Copy link
Copy Markdown
Contributor

do you still care about this one?

A bit, but we should first fix the problem with ztimer msec backend selection if RTT is available and frequency is fast enough. Are you willing to work on that ? That would be awesome :)

Is this problem still present with the fix to kinetis merged I think all BOARDS providing rtt can do ztimer_msec.

sys/Makefile.dep Outdated
Comment on lines +16 to +20
USEMODULE += ztimer_usec
USEMODULE += ztimer_msec
ifneq (,$(filter periph_rtt,$(USEMODULE)))
USEMODULE += ztimer_msec_periph_rtt
endif
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
USEMODULE += ztimer_usec
USEMODULE += ztimer_msec
ifneq (,$(filter periph_rtt,$(USEMODULE)))
USEMODULE += ztimer_msec_periph_rtt
endif
USEMODULE += ztimer_usec
USEMODULE += ztimer_msec

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The later will be addressed with #16553

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, exactly what I needed !

@fjmolinas
Copy link
Copy Markdown
Contributor

Ztimer seems to just be heavier

And tests/sys_arduino doesn't fit anymore on arduino-uno, which is a bit a problem.

Lets just blacklist arduino-uno

@fjmolinas
Copy link
Copy Markdown
Contributor

Please rebase @aabadie!

@fjmolinas
Copy link
Copy Markdown
Contributor

Ping @aabadie, I can directly push force otherwise

@aabadie aabadie force-pushed the pr/sys/arduino_ztimer branch from 26bed0f to e30a107 Compare June 17, 2021 08:29
@github-actions github-actions bot added Area: sys Area: System Area: tests Area: tests and testing framework and removed Area: timers Area: timer subsystems labels Jun 17, 2021
@aabadie aabadie added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jun 17, 2021
Copy link
Copy Markdown
Contributor

@fjmolinas fjmolinas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK!

@fjmolinas fjmolinas merged commit a012a08 into RIOT-OS:master Jun 17, 2021
@aabadie aabadie deleted the pr/sys/arduino_ztimer branch June 17, 2021 16:09
@MrKevinWeiss MrKevinWeiss added this to the Release 2021.07 milestone Jul 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: arduino API Area: Arduino wrapper API Area: sys Area: System Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants