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

periph/rtt: fix overflow in tick conversion macros #15431

Merged
merged 2 commits into from
Nov 17, 2020

Conversation

haukepetersen
Copy link
Contributor

Contribution description

The tick conversion macros provided by the periph/rtt driver are subject to overflow for large values. E.g. when doing something like

uint32_t ticks = RTT_TICKS_TO_MS(RTT_MAX_VALUE + 1);
// with RTT_MAX_VALUE = 0x00ffffff -> 24 bit counter
// and RTT_FREQUENCY 1024 -> e.g. on the nrf52dk

the resulting tick value will be wrong. Reason is this line:

#define RTT_TICKS_TO_US(ticks)  ((uint32_t)((uint64_t)(ticks) * 1000000UL / RTT_FREQUENCY))

-> the value of ticks * 10000000 / RTT_FREQUENCY is larger then UINT32_MAX, and therefore overflows. And as this macro is used in a RTT_TICKS_TO_MIN() -> RTT_TICKS_TO_SEC() -> RTT_TICKS_TO_MS() -> RTT_TICKS_TO_US() cascade, all resulting values will be flawed.

The same goes for the time-to-tick conversion the other way around...

This PR fixes this by omitting the explicit cast to uint32_t in both directions. Now when assiging uint32_t foo = RTT_TICKS_TO_US() with a (static) value larger then UINT32_MAX the compiler will shout at you :-)

Also added some basic tests for the tick conversion to the test application.

Testing procedure

Run the included version of the test application on any platform of your choice, it should fail. Run it with the fix included in this PR -> it should run successfully..

Issues/PRs references

none

@haukepetersen haukepetersen added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Nov 11, 2020
@aabadie
Copy link
Contributor

aabadie commented Nov 11, 2020

tests/periph_rtt comes with an automated Python test script. With the changes in this PR, it's certainly broken ("This test will now display"...). Can you adapt it ? Bonus point if you even extend it with the new tick conversion tests.

@haukepetersen
Copy link
Contributor Author

done, make test is now working as expected again.

tests/periph_rtt/main.c Outdated Show resolved Hide resolved
@haukepetersen
Copy link
Contributor Author

good catch, fixed.

@MrKevinWeiss
Copy link
Contributor

here are the results from the HiL Tests

@MrKevinWeiss
Copy link
Contributor

MrKevinWeiss commented Nov 12, 2020

nucleo-f767zi, esp8266-esp-12x seem to have introduced problems when compared to master... If possible please verify.

@haukepetersen
Copy link
Contributor Author

I will see on Monday which boards I have available at the office and check them out...

@aabadie
Copy link
Contributor

aabadie commented Nov 13, 2020

I gave this one some testing:

nucleo-f767zi: works like a charm
$ BUILD_IN_DOCKER=1 TRIBE_CI=1 make BOARD=nucleo-f767zi -C tests/periph_rtt flash test --no-print-directory 
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-f767zi'  -w '/data/riotbuild/riotbase/tests/periph_rtt/' 'riot/riotbuild:latest' make 'BOARD=nucleo-f767zi'    
Building application "tests_periph_rtt" for "nucleo-f767zi" with MCU "stm32".

[INFO] updating stm32cmsis /data/riotbuild/riotbase/cpu/stm32/include/vendor/cmsis/f7/.pkg-state.git-downloaded
echo 71be130bda6963d9d8ddbb71530477eadf0be740   > /data/riotbuild/riotbase/cpu/stm32/include/vendor/cmsis/f7/.pkg-state.git-downloaded
[INFO] patch stm32cmsis
"make" -C /data/riotbuild/riotbase/boards/nucleo-f767zi
"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/auto_init
"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
   text	   data	    bss	    dec	    hex	filename
  12116	    132	   2408	  14656	   3940	/data/riotbuild/riotbase/tests/periph_rtt/bin/nucleo-f767zi/tests_periph_rtt.elf
rsync --chmod=ugo=rwX /work/riot/RIOT/tests/periph_rtt/bin/nucleo-f767zi/tests_periph_rtt.elf [email protected]:/builds/boards/bin/nucleo-f767zi_flashfile.elf
ssh [email protected] 'IMAGE_OFFSET= BOARD=nucleo-f767zi QUIET=0 make --no-print-directory -C /builds/boards flash-only FLASHFILE=/builds/boards/bin/nucleo-f767zi_flashfile.elf'
/builds/boards/RIOT/dist/tools/openocd/openocd.sh flash /builds/boards/bin/nucleo-f767zi_flashfile.elf
### Flashing Target ###
Open On-Chip Debugger 0.10.0+dev-g68611ef-dirty (2020-07-20-09:42)
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 2000 kHz
Info : STLINK V2J28M17 (API v2) VID:PID 0483:374B
Info : Target voltage: 3.249376
Info : stm32f7x.cpu: hardware has 8 breakpoints, 4 watchpoints
Info : starting gdb server for stm32f7x.cpu on 0
Info : Listening on port 33777 for gdb connections
    TargetName         Type       Endian TapName            State       
--  ------------------ ---------- ------ ------------------ ------------
 0* stm32f7x.cpu       hla_target little stm32f7x.cpu       reset

Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x080005e0 msp: 0x20000200
Info : device id = 0x10006451
Info : flash size = 2048 kbytes
Info : Single Bank 2048 kiB STM32F76x/77x found
auto erase enabled
wrote 32768 bytes from file /builds/boards/bin/nucleo-f767zi_flashfile.elf in 0.790018s (40.505 KiB/s)

verified 12248 bytes in 0.136880s (87.383 KiB/s)

Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
shutdown command invoked
Done flashing
r
ssh -t [email protected] 'BOARD=nucleo-f767zi QUIET=0 make --no-print-directory -C /builds/boards term' 
/builds/boards/RIOT/dist/tools/pyterm/pyterm -p "/dev/riot/tty-nucleo-f767zi" -b "115200"  
Twisted not available, please install it if you want to use pyterm's JSON capabilities
2020-11-13 07:41:49,413 # Connect to serial port /dev/riot/tty-nucleo-f767zi
Welcome to pyterm!
Type '/exit' to exit.
2020-11-13 07:41:50,418 # READY
s
2020-11-13 07:41:50,531 # START
2020-11-13 07:41:50,538 # main(): This is RIOT! (Version: 2021.01-devel-787-gaf036-review_periph_rtt_test)
2020-11-13 07:41:50,539 # 
2020-11-13 07:41:50,541 # RIOT RTT low-level driver test
2020-11-13 07:41:50,543 # RTT configuration:
2020-11-13 07:41:50,545 # RTT_MAX_VALUE: 0x0000ffff
2020-11-13 07:41:50,547 # RTT_FREQUENCY: 1024
2020-11-13 07:41:50,547 # 
2020-11-13 07:41:50,549 # Testing the tick conversion
2020-11-13 07:41:50,554 # Trying to convert 1 to seconds and back
2020-11-13 07:41:50,557 # Trying to convert 256 to seconds and back
2020-11-13 07:41:50,560 # Trying to convert 65536 to seconds and back
2020-11-13 07:41:50,564 # Trying to convert 16777216 to seconds and back
2020-11-13 07:41:50,569 # Trying to convert 2147483648 to seconds and back
2020-11-13 07:41:50,569 # All ok
2020-11-13 07:41:50,570 # 
2020-11-13 07:41:50,572 # Initializing the RTT driver
2020-11-13 07:41:50,581 # This test will now display 'Hello' every 5 seconds
2020-11-13 07:41:50,581 # 
2020-11-13 07:41:50,582 # RTT now: 1
2020-11-13 07:41:50,585 # Setting initial alarm to now + 5 s (5121)
2020-11-13 07:41:50,592 # Done setting up the RTT, wait for many Hellos
2020-11-13 07:41:55,584 # Hello
2020-11-13 07:42:00,584 # Hello
2020-11-13 07:42:05,585 # Hello
2020-11-13 07:42:10,585 # Hello
2020-11-13 07:42:15,585 # Hello

esp32-wroom-32 (not esp8266 though): works
$ BUILD_IN_DOCKER=1 make BOARD=esp32-wroom-32 -C tests/periph_rtt flash test --no-print-directory 
ESP32_SDK_DIR should be defined as /path/to/esp-idf directory
ESP32_SDK_DIR is set by default to /opt/esp/esp-idf
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=esp32-wroom-32'  -w '/data/riotbuild/riotbase/tests/periph_rtt/' 'riot/riotbuild:latest' make 'BOARD=esp32-wroom-32'    
ESP32_SDK_DIR should be defined as /path/to/esp-idf directory
ESP32_SDK_DIR is set by default to /opt/esp/esp-idf
Building application "tests_periph_rtt" for "esp32-wroom-32" with MCU "esp32".

"make" -C /data/riotbuild/riotbase/boards/esp32-wroom-32
"make" -C /data/riotbuild/riotbase/boards/common/esp32
"make" -C /data/riotbuild/riotbase/core
"make" -C /data/riotbuild/riotbase/cpu/esp32
"make" -C /data/riotbuild/riotbase/cpu/esp32/freertos
"make" -C /data/riotbuild/riotbase/cpu/esp32/periph
"make" -C /data/riotbuild/riotbase/cpu/esp32/vendor
"make" -C /data/riotbuild/riotbase/cpu/esp32/vendor/esp-idf
"make" -C /data/riotbuild/riotbase/cpu/esp32/vendor/esp-idf/driver
"make" -C /data/riotbuild/riotbase/cpu/esp32/vendor/esp-idf/esp32
"make" -C /data/riotbuild/riotbase/cpu/esp32/vendor/esp-idf/soc
"make" -C /data/riotbuild/riotbase/cpu/esp32/vendor/esp-idf/spi_flash
"make" -C /data/riotbuild/riotbase/cpu/esp_common
"make" -C /data/riotbuild/riotbase/cpu/esp_common/freertos
"make" -C /data/riotbuild/riotbase/cpu/esp_common/periph
"make" -C /data/riotbuild/riotbase/cpu/esp_common/vendor
"make" -C /data/riotbuild/riotbase/cpu/esp_common/vendor/xtensa
"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/auto_init
"make" -C /data/riotbuild/riotbase/sys/isrpipe
"make" -C /data/riotbuild/riotbase/sys/log
"make" -C /data/riotbuild/riotbase/sys/luid
"make" -C /data/riotbuild/riotbase/sys/newlib_syscalls_default
"make" -C /data/riotbuild/riotbase/sys/pm_layered
"make" -C /data/riotbuild/riotbase/sys/random
"make" -C /data/riotbuild/riotbase/sys/random/tinymt32
"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
   text	   data	    bss	    dec	    hex	filename
  55626	   3648	   6384	  65658	  1007a	/data/riotbuild/riotbase/tests/periph_rtt/bin/esp32-wroom-32/tests_periph_rtt.elf
/work/riot/RIOT/dist/tools/esptool/esptool.py --chip esp32 elf2image --flash_mode dout --flash_size 4MB --flash_freq 40m     -o /work/riot/RIOT/tests/periph_rtt/bin/esp32-wroom-32/tests_periph_rtt.elf.bin /work/riot/RIOT/tests/periph_rtt/bin/esp32-wroom-32/tests_periph_rtt.elf; printf "\n" > /work/riot/RIOT/tests/periph_rtt/bin/esp32-wroom-32/partitions.csv; printf "nvs, data, nvs, 0x9000, 0x6000\n" >> /work/riot/RIOT/tests/periph_rtt/bin/esp32-wroom-32/partitions.csv; printf "phy_init, data, phy, 0xf000, 0x1000\n" >> /work/riot/RIOT/tests/periph_rtt/bin/esp32-wroom-32/partitions.csv; printf "factory, app, factory, 0x10000, " >> /work/riot/RIOT/tests/periph_rtt/bin/esp32-wroom-32/partitions.csv; ls -l /work/riot/RIOT/tests/periph_rtt/bin/esp32-wroom-32/tests_periph_rtt.elf.bin | awk '{ print $5 }' >> /work/riot/RIOT/tests/periph_rtt/bin/esp32-wroom-32/partitions.csv; python3 /work/riot/RIOT/dist/tools/esptool/gen_esp32part.py --verify /work/riot/RIOT/tests/periph_rtt/bin/esp32-wroom-32/partitions.csv /work/riot/RIOT/tests/periph_rtt/bin/esp32-wroom-32/partitions.bin
esptool.py v2.4.0
Parsing CSV input...
/work/riot/RIOT/dist/tools/esptool/esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 460800 --before default_reset write_flash -z --flash_mode dout --flash_freq 40m    0x1000 /work/riot/RIOT/cpu/esp32/bin/bootloader.bin 0x8000 /work/riot/RIOT/tests/periph_rtt/bin/esp32-wroom-32/partitions.bin 0x10000 /work/riot/RIOT/tests/periph_rtt/bin/esp32-wroom-32/tests_periph_rtt.elf.bin
esptool.py v2.4.0
Connecting......
Chip is ESP32D0WDQ6 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse
MAC: 80:7d:3a:fd:d9:90
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Auto-detected Flash size: 4MB
Flash params set to 0x0320
Compressed 18640 bytes to 11444...
Wrote 18640 bytes (11444 compressed) at 0x00001000 in 0.3 seconds (effective 571.5 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 85...
Wrote 3072 bytes (85 compressed) at 0x00008000 in 0.0 seconds (effective 6194.7 kbit/s)...
Hash of data verified.
Compressed 91744 bytes to 39805...
Wrote 91744 bytes (39805 compressed) at 0x00010000 in 1.1 seconds (effective 691.0 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...
r
/work/riot/RIOT/dist/tools/pyterm/pyterm -p "/dev/ttyUSB0" -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/ttyUSB0
Welcome to pyterm!
Type '/exit' to exit.
READY
s
START
main(): This is RIOT! (Version: 2021.01-devel-787-gaf036-review_periph_rtt_test)

RIOT RTT low-level driver test
RTT configuration:
RTT_MAX_VALUE: 0xffffffff
RTT_FREQUENCY: 32768

Testing the tick conversion
Trying to convert 1 to seconds and back
Trying to convert 256 to seconds and back
Trying to convert 65536 to seconds and back
Trying to convert 16777216 to seconds and back
Trying to convert 2147483648 to seconds and back
All ok

Initializing the RTT driver
This test will now display 'Hello' every 5 seconds

RTT now: 274021
Setting initial alarm to now + 5 s (437861)
Done setting up the RTT, wait for many Hellos
Hello
Hello
Hello
Hello
Hello

frdm-kw41z (for the fun): works
$ BUILD_IN_DOCKER=1 TRIBE_CI=1 make BOARD=frdm-kw41z -C tests/periph_rtt flash test --no-print-directory 
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=frdm-kw41z'  -w '/data/riotbuild/riotbase/tests/periph_rtt/' 'riot/riotbuild:latest' make 'BOARD=frdm-kw41z'    
Building application "tests_periph_rtt" for "frdm-kw41z" with MCU "kinetis".

"make" -C /data/riotbuild/riotbase/boards/frdm-kw41z
"make" -C /data/riotbuild/riotbase/boards/common/kw41z
"make" -C /data/riotbuild/riotbase/core
"make" -C /data/riotbuild/riotbase/cpu/kinetis
"make" -C /data/riotbuild/riotbase/cpu/cortexm_common
"make" -C /data/riotbuild/riotbase/cpu/cortexm_common/periph
"make" -C /data/riotbuild/riotbase/cpu/kinetis/periph
"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/auto_init
"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
   text	   data	    bss	    dec	    hex	filename
  12524	    132	   2384	  15040	   3ac0	/data/riotbuild/riotbase/tests/periph_rtt/bin/frdm-kw41z/tests_periph_rtt.elf
rsync --chmod=ugo=rwX /work/riot/RIOT/tests/periph_rtt/bin/frdm-kw41z/tests_periph_rtt.elf [email protected]:/builds/boards/bin/frdm-kw41z_flashfile.elf
ssh [email protected] 'IMAGE_OFFSET= BOARD=frdm-kw41z QUIET=0 make --no-print-directory -C /builds/boards flash-only FLASHFILE=/builds/boards/bin/frdm-kw41z_flashfile.elf'
/builds/boards/RIOT/dist/tools/openocd/openocd.sh flash /builds/boards/bin/frdm-kw41z_flashfile.elf
### Flashing Target ###
/builds/boards/bin/frdm-kw41z_flashfile.elf is not locked.
Open On-Chip Debugger 0.10.0+dev-g68611ef-dirty (2020-07-20-09:42)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
swd
Info : add flash_bank kinetis klx.pflash
srst_only separate srst_nogate srst_open_drain connect_assert_srst

Info : J-Link OpenSDA 2 compiled May  6 2016 11:04:17
Info : Hardware version: 1.00
Info : VTarget = 3.300 V
Info : clock speed 1000 kHz
Info : SWD DPIDR 0x0bc11477
Info : klx.cpu: hardware has 2 breakpoints, 2 watchpoints
Info : klx.cpu: external reset detected
Info : starting gdb server for klx.cpu on 0
Info : Listening on port 43563 for gdb connections
    TargetName         Type       Endian TapName            State       
--  ------------------ ---------- ------ ------------------ ------------
 0* klx.cpu            cortex_m   little klx.cpu            reset

target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x00000d80 msp: 0x1fff8200
Info : Kinetis MKW41Z512xxx4 detected: 2 flash blocks
Info : 2 PFlash banks: 512k total
Info : This device supports Program Longword execution only.
Info : Disabling Kinetis watchdog (initial SIM_COPC 0x0c)
Info : This device supports Program Longword execution only.
auto erase enabled
wrote 14336 bytes from file /builds/boards/bin/frdm-kw41z_flashfile.elf in 0.466262s (30.026 KiB/s)

verified 12656 bytes in 0.160141s (77.178 KiB/s)

shutdown command invoked
Done flashing
r
ssh -t [email protected] 'BOARD=frdm-kw41z QUIET=0 make --no-print-directory -C /builds/boards term' 
/builds/boards/RIOT/dist/tools/pyterm/pyterm -p "/dev/riot/tty-frdm-kw41z" -b "115200"  
Twisted not available, please install it if you want to use pyterm's JSON capabilities
2020-11-13 07:46:36,555 # Connect to serial port /dev/riot/tty-frdm-kw41z
Welcome to pyterm!
Type '/exit' to exit.
2020-11-13 07:46:37,559 # t it is ready
2020-11-13 07:46:37,561 # Help: Press s to start test, r to print it is ready
2020-11-13 07:46:37,594 # READY
s
2020-11-13 07:46:37,709 # START
2020-11-13 07:46:37,716 # main(): This is RIOT! (Version: 2021.01-devel-787-gaf036-review_periph_rtt_test)
2020-11-13 07:46:37,716 # 
2020-11-13 07:46:37,719 # RIOT RTT low-level driver test
2020-11-13 07:46:37,720 # RTT configuration:
2020-11-13 07:46:37,721 # RTT_MAX_VALUE: 0xffffffff
2020-11-13 07:46:37,724 # RTT_FREQUENCY: 1
2020-11-13 07:46:37,725 # 
2020-11-13 07:46:37,726 # Testing the tick conversion
2020-11-13 07:46:37,730 # Trying to convert 1 to seconds and back
2020-11-13 07:46:37,739 # Trying to convert 256 to seconds and back
2020-11-13 07:46:37,741 # Trying to convert 65536 to seconds and back
2020-11-13 07:46:37,743 # Trying to convert 16777216 to seconds and back
2020-11-13 07:46:37,745 # Trying to convert 2147483648 to seconds and back
2020-11-13 07:46:37,746 # All ok
2020-11-13 07:46:37,746 # 
2020-11-13 07:46:37,750 # Initializing the RTT driver
2020-11-13 07:46:37,754 # This test will now display 'Hello' every 5 seconds
2020-11-13 07:46:37,755 # 
2020-11-13 07:46:37,755 # RTT now: 1751686
2020-11-13 07:46:37,760 # Setting initial alarm to now + 5 s (1751691)
2020-11-13 07:46:37,764 # Done setting up the RTT, wait for many Hellos
2020-11-13 07:46:42,416 # Hello
2020-11-13 07:46:47,414 # Hello
2020-11-13 07:46:52,412 # Hello
2020-11-13 07:46:57,415 # Hello
2020-11-13 07:47:02,413 # Hello

arduino-mega2560: conversion works (but RTT is not supported anyway)

Apply the following patch:

diff --git a/boards/common/arduino-atmega/Makefile.features b/boards/common/arduino-atmega/Makefile.features
index 3bc938d8f6..6c234e4bd1 100644
--- a/boards/common/arduino-atmega/Makefile.features
+++ b/boards/common/arduino-atmega/Makefile.features
@@ -2,6 +2,7 @@
 FEATURES_PROVIDED += periph_adc
 FEATURES_PROVIDED += periph_i2c
 FEATURES_PROVIDED += periph_pwm
+FEATURES_PROVIDED += periph_rtt
 FEATURES_PROVIDED += periph_spi
 FEATURES_PROVIDED += periph_timer
 FEATURES_PROVIDED += periph_uart

I could verify that the conversion are also working on 8 bits (RTT doesn't work on arduino-mega2560 but we can already check the conversion):

$ BUILD_IN_DOCKER=1 TRIBE_CI=1 make BOARD=arduino-mega2560 -C tests/periph_rtt flash test --no-print-directory 
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=arduino-mega2560'  -w '/data/riotbuild/riotbase/tests/periph_rtt/' 'riot/riotbuild:latest' make 'BOARD=arduino-mega2560'    
Building application "tests_periph_rtt" for "arduino-mega2560" with MCU "atmega2560".

"make" -C /data/riotbuild/riotbase/boards/arduino-mega2560
"make" -C /data/riotbuild/riotbase/boards/common/arduino-atmega
"make" -C /data/riotbuild/riotbase/boards/common/atmega
"make" -C /data/riotbuild/riotbase/core
"make" -C /data/riotbuild/riotbase/cpu/atmega2560
"make" -C /data/riotbuild/riotbase/cpu/atmega_common
"make" -C /data/riotbuild/riotbase/cpu/atmega_common/avr_libc_extra
"make" -C /data/riotbuild/riotbase/cpu/atmega_common/periph
"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/auto_init
"make" -C /data/riotbuild/riotbase/sys/isrpipe
"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
   text	   data	    bss	    dec	    hex	filename
   7624	    654	    981	   9259	   242b	/data/riotbuild/riotbase/tests/periph_rtt/bin/arduino-mega2560/tests_periph_rtt.elf
rsync --chmod=ugo=rwX /work/riot/RIOT/tests/periph_rtt/bin/arduino-mega2560/tests_periph_rtt.hex [email protected]:/builds/boards/bin/arduino-mega2560_flashfile.hex
ssh [email protected] 'IMAGE_OFFSET= BOARD=arduino-mega2560 QUIET=0 make --no-print-directory -C /builds/boards flash-only FLASHFILE=/builds/boards/bin/arduino-mega2560_flashfile.hex'
avrdude -c stk500v2 -p m2560 -P /dev/riot/tty-arduino-mega2560 -D -U flash:w:/builds/boards/bin/arduino-mega2560_flashfile.hex

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e9801 (probably m2560)
avrdude: reading input file "/builds/boards/bin/arduino-mega2560_flashfile.hex"
avrdude: input file /builds/boards/bin/arduino-mega2560_flashfile.hex auto detected as Intel Hex
avrdude: writing flash (8278 bytes):

Writing | ################################################## | 100% 1.35s

avrdude: 8278 bytes of flash written
avrdude: verifying flash memory against /builds/boards/bin/arduino-mega2560_flashfile.hex:
avrdude: load data flash data from input file /builds/boards/bin/arduino-mega2560_flashfile.hex:
avrdude: input file /builds/boards/bin/arduino-mega2560_flashfile.hex auto detected as Intel Hex
avrdude: input file /builds/boards/bin/arduino-mega2560_flashfile.hex contains 8278 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 1.08s

avrdude: verifying ...
avrdude: 8278 bytes of flash verified

avrdude done.  Thank you.

r
ssh -t [email protected] 'BOARD=arduino-mega2560 QUIET=0 make --no-print-directory -C /builds/boards term' 
/builds/boards/RIOT/dist/tools/pyterm/pyterm -p "/dev/riot/tty-arduino-mega2560" -b "9600"  
Twisted not available, please install it if you want to use pyterm's JSON capabilities
2020-11-13 07:49:11,918 # Connect to serial port /dev/riot/tty-arduino-mega2560
Welcome to pyterm!
Type '/exit' to exit.
2020-11-13 07:49:12,920 # 

2020-11-13 07:49:12,922 # Help: Press s to start test, r to print it is ready
2020-11-13 07:49:13,058 # READY
s
2020-11-13 07:49:13,153 # START
2020-11-13 07:49:13,235 # main(): This is RIOT! (Version: 2021.01-devel-787-gaf036-review_periph_rtt_test)
2020-11-13 07:49:13,239 # 
2020-11-13 07:49:13,271 # RIOT RTT low-level driver test
2020-11-13 07:49:13,288 # RTT configuration:
2020-11-13 07:49:13,316 # RTT_MAX_VALUE: 0x0000ffff
2020-11-13 07:49:13,337 # RTT_FREQUENCY: 1024
2020-11-13 07:49:13,337 # 
2020-11-13 07:49:13,366 # Testing the tick conversion
2020-11-13 07:49:13,411 # Trying to convert 1 to seconds and back
2020-11-13 07:49:13,452 # Trying to convert 256 to seconds and back
2020-11-13 07:49:13,497 # Trying to convert 65536 to seconds and back
2020-11-13 07:49:13,546 # Trying to convert 16777216 to seconds and back
2020-11-13 07:49:13,599 # Trying to convert 2147483648 to seconds and back
2020-11-13 07:49:13,607 # All ok

I think we are good with this PR.

Please squash!

@haukepetersen
Copy link
Contributor Author

Squashed - many thanks for the verification @aabadie!

@MrKevinWeiss as @aabadie has verified this PR to be working on some of the boards in question, could there any other issue with this PR that causes the HIL to fail? Seems like we should sort this out before merging this fix, right?!

@aabadie aabadie added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Nov 13, 2020
@haukepetersen
Copy link
Contributor Author

@aabadie fixed.

@haukepetersen haukepetersen added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Nov 16, 2020
@benpicco benpicco added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Nov 16, 2020
@haukepetersen haukepetersen added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Nov 17, 2020
@aabadie aabadie added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Nov 17, 2020
Copy link
Contributor

@aabadie aabadie left a comment

Choose a reason for hiding this comment

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

All good to me. I think the problem raised by @MrKevinWeiss on nucleo-f767zi/esp8266 are false positives (maybe a setup issue ?).

ACK

@aabadie aabadie merged commit 5d99793 into RIOT-OS:master Nov 17, 2020
@haukepetersen haukepetersen deleted the fix_periphrtt_tickconversion branch November 17, 2020 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants