Skip to content

Conversation

benpicco
Copy link
Contributor

Contribution description

This implements timer_set_periodic() for STM32.

Seems like the Interrupt flag for a Capture/Compare channel gets set when

  • the CC-value is reached
  • the timer resets before the CC value is reached.

We only want the first event and ignore the second one. Unfortunately I did
not find a way to disable the second event type, so it is filtered in software.

That is we need to

  • ignore the CC-interrupts when the CNT register register is reset
  • ignore the CC-interrupts > TOP value/ARR (auto-reload register)

Testing procedure

Verify that tests/periph_timer & periph_timer_periodic still work.

tested on nucleo-l031k6, weact-f411ce & stm32f429i-disco

Issues/PRs references

@benpicco benpicco added Type: new feature The issue requests / The PR implemements a new feature for RIOT Area: cpu Area: CPU/MCU ports labels Jun 29, 2020
@benpicco benpicco added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jun 29, 2020
@benpicco benpicco force-pushed the cpu/stm32-timer_periodic branch from b82ef02 to 2e1b835 Compare June 30, 2020 08:06
@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 Jun 30, 2020
@benpicco benpicco requested a review from smlng June 30, 2020 09:10
@MrKevinWeiss
Copy link
Contributor

samr21-xpro
nucleo-l073rz
nucleo-f411re
remote-revb
arduino-mega2560
nucleo-f103rb
frdm-kw41z
nucleo-f091rc
nucleo-f767zi
saml10-xpro
esp32-wroom-32
arduino-due

All boards PASSED

tests/periph_timer
2020-06-30 10:30:08,059 # TIMER_0: starting                                                                                                                                                                                                     │2020-06-30 10:30:08,040 # Testing TIMER_0:                                                                                                                       │2020-06-30 10:30:08,044 # Testing TIMER_0:
2020-06-30 10:30:08,069 # TIMER_0: channel 0 fired at SW count    24014 - init:    24014                                                                                                                                                        │2020-06-30 10:30:08,046 # TIMER_0: initialization successful                                                                                                     │2020-06-30 10:30:08,050 # TIMER_0: initialization successful
2020-06-30 10:30:08,078 # TIMER_0: channel 1 fired at SW count    47997 - diff:    23983                                                                                                                                                        │2020-06-30 10:30:08,049 # TIMER_0: stopped                                                                                                                       │2020-06-30 10:30:08,054 # TIMER_0: stopped
2020-06-30 10:30:08,079 #                                                                                                                                                                                                                       │2020-06-30 10:30:08,054 # TIMER_0: set channel 0 to 5000                                                                                                         │2020-06-30 10:30:08,060 # TIMER_0: set channel 0 to 5000
2020-06-30 10:30:08,082 # Testing TIMER_1:                                                                                                                                                                                                      │2020-06-30 10:30:08,060 # TIMER_0: set channel 1 to 10000                                                                                                        │2020-06-30 10:30:08,067 # TIMER_0: set channel 1 to 10000
2020-06-30 10:30:08,088 # TIMER_1: initialization successful                                                                                                                                                                                    │2020-06-30 10:30:08,066 # TIMER_0: set channel 2 to 15000                                                                                                        │2020-06-30 10:30:08,073 # TIMER_0: set channel 2 to 15000
2020-06-30 10:30:08,091 # TIMER_1: stopped                                                                                                                                                                                                      │2020-06-30 10:30:08,071 # TIMER_0: set channel 3 to 20000                                                                                                        │2020-06-30 10:30:08,080 # TIMER_0: set channel 3 to 20000
2020-06-30 10:30:08,097 # TIMER_1: set channel 0 to 5000                                                                                                                                                                                        │2020-06-30 10:30:08,074 # TIMER_0: starting                                                                                                                      │2020-06-30 10:30:08,085 # TIMER_0: starting
2020-06-30 10:30:08,102 # TIMER_1: set channel 1 to 10000                                                                                                                                                                                       │2020-06-30 10:30:08,084 # TIMER_0: channel 0 fired at SW count    14544 - init:    14544                                                                         │2020-06-30 10:30:08,096 # TIMER_0: channel 0 fired at SW count    47992 - init:    47992
2020-06-30 10:30:08,105 # TIMER_1: starting                                                                                                                                                                                                     │2020-06-30 10:30:08,094 # TIMER_0: channel 1 fired at SW count    27864 - diff:    13320                                                                         │2020-06-30 10:30:08,107 # TIMER_0: channel 1 fired at SW count    95978 - diff:    47986
2020-06-30 10:30:08,115 # TIMER_1: channel 0 fired at SW count    24019 - init:    24019                                                                                                                                                        │2020-06-30 10:30:08,104 # TIMER_0: channel 2 fired at SW count    42394 - diff:    14530                                                                         │2020-06-30 10:30:08,118 # TIMER_0: channel 2 fired at SW count   143964 - diff:    47986
2020-06-30 10:30:08,125 # TIMER_1: channel 1 fired at SW count    48001 - diff:    23982                                                                                                                                                        │2020-06-30 10:30:08,115 # TIMER_0: channel 3 fired at SW count    55711 - diff:    13317                                                                         │2020-06-30 10:30:08,125 # TIMER_0: channel 3 fired at SW count   191949 - diff:    47985
2020-06-30 10:30:08,125 #                                                                                                                                                                                                                       │2020-06-30 10:30:08,116 #                                                                                                                                        │2020-06-30 10:30:08,126 # 
2020-06-30 10:30:08,128 # TEST SUCCEEDED                                                                                                                                                                                                        │2020-06-30 10:30:08,119 # TEST SUCCEEDED                                                                                                                         │2020-06-30 10:30:08,128 # TEST SUCCEEDED
^[[C2020-06-30 10:31:17,712 # Exiting Pyterm                                                                                                                                                                                                    │^[[C2020-06-30 10:31:17,712 # Exiting Pyterm                                                                                                                     │^[[C2020-06-30 10:31:17,713 # Exiting Pyterm
make: *** [/home/pi/.tmp/RobotFW-tests/RIOT/tests/periph_timer/../../Makefile.include:719: term] Interrupt                                                                                                                                      │make: *** [/home/pi/.tmp/RobotFW-tests/RIOT/tests/periph_timer/../../Makefile.include:719: term] Interrupt                                                       │make: *** [/home/pi/.tmp/RobotFW-tests/RIOT/tests/periph_timer/../../Makefile.include:719: term] Interrupt
                                                                                                                                                                                                                                                │                                                                                                                                                                 │
pi@HIL-R1P1:~/.tmp/RobotFW-tests/RIOT $ echo $BOARD                                                                                                                                                                                             │pi@HIL-R1P3:~/.tmp/RobotFW-tests/RIOT $ echo $BOARD                                                                                                              │pi@HIL-R1P4:~/.tmp/RobotFW-tests/RIOT $ echo $BOARD
samr21-xpro                                                                                                                                                                                                                                     │nucleo-l073rz                                                                                                                                                    │nucleo-f411re
pi@HIL-R1P1:~/.tmp/RobotFW-tests/RIOT $                                                                                                                                                                                                         │pi@HIL-R1P3:~/.tmp/RobotFW-tests/RIOT $                                                                                                                          │pi@HIL-R1P4:~/.tmp/RobotFW-tests/RIOT $                                                                                                                      
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┬────────────────────────────────────────────────────────────────────┴────────────────────────────────────────────────────────────────────────────────────────────┬────────────────────────────────────────────────────────────────────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
2020-06-30 10:30:08,156 # TIMER_2: stopped                                                                                                                                 │2020-06-30 10:30:08,587 #                                                                                                                                        │2020-06-30 10:30:08,135 # TIMER_1: initialization successful
2020-06-30 10:30:08,161 # TIMER_2: set channel 0 to 5000                                                                                                                   │2020-06-30 10:30:08,605 # Testing TIMER_1:                                                                                                                       │2020-06-30 10:30:08,139 # TIMER_1: stopped
2020-06-30 10:30:08,165 # TIMER_2: starting                                                                                                                                │2020-06-30 10:30:08,639 # TIMER_1: initialization successful                                                                                                     │2020-06-30 10:30:08,154 # TIMER_1: set channel 0 to 5000
2020-06-30 10:30:08,174 # TIMER_2: channel 0 fired at SW count      276 - init:      276                                                                                   │2020-06-30 10:30:08,659 # TIMER_1: stopped                                                                                                                       │2020-06-30 10:30:08,160 # TIMER_1: set channel 1 to 10000
2020-06-30 10:30:08,175 #                                                                                                                                                  │2020-06-30 10:30:08,692 # TIMER_1: set channel 0 to 5000                                                                                                         │2020-06-30 10:30:08,165 # TIMER_1: set channel 2 to 15000
2020-06-30 10:30:08,178 # Testing TIMER_3:                                                                                                                                 │2020-06-30 10:30:08,724 # TIMER_1: set channel 1 to 10000                                                                                                        │2020-06-30 10:30:08,171 # TIMER_1: set channel 3 to 20000
2020-06-30 10:30:08,184 # TIMER_3: initialization successful                                                                                                               │2020-06-30 10:30:08,757 # TIMER_1: set channel 2 to 15000                                                                                                        │2020-06-30 10:30:08,174 # TIMER_1: starting
2020-06-30 10:30:08,187 # TIMER_3: stopped                                                                                                                                 │2020-06-30 10:30:08,774 # TIMER_1: starting                                                                                                                      │2020-06-30 10:30:08,184 # TIMER_1: channel 0 fired at SW count    22496 - init:    22496
2020-06-30 10:30:08,192 # TIMER_3: set channel 0 to 5000                                                                                                                   │2020-06-30 10:30:08,897 # TIMER_1: channel 0 fired at SW count    11426 - init:    11426                                                                         │2020-06-30 10:30:08,194 # TIMER_1: channel 1 fired at SW count    44985 - diff:    22489
2020-06-30 10:30:08,196 # TIMER_3: starting                                                                                                                                │2020-06-30 10:30:08,962 # TIMER_1: channel 1 fired at SW count    22845 - diff:    11419                                                                         │2020-06-30 10:30:08,204 # TIMER_1: channel 2 fired at SW count    67473 - diff:    22488
2020-06-30 10:30:08,205 # TIMER_3: channel 0 fired at SW count      276 - init:      276                                                                                   │2020-06-30 10:30:09,028 # TIMER_1: channel 2 fired at SW count    34263 - diff:    11418                                                                         │2020-06-30 10:30:08,214 # TIMER_1: channel 3 fired at SW count    89959 - diff:    22486
2020-06-30 10:30:08,206 #                                                                                                                                                  │2020-06-30 10:30:09,032 #                                                                                                                                        │2020-06-30 10:30:08,215 # 
2020-06-30 10:30:08,209 # TEST SUCCEEDED                                                                                                                                   │2020-06-30 10:30:09,044 # TEST SUCCEEDED                                                                                                                         │2020-06-30 10:30:08,218 # TEST SUCCEEDED
^[[C2020-06-30 10:31:17,710 # Exiting Pyterm                                                                                                                               │^[[C2020-06-30 10:31:17,712 # Exiting Pyterm                                                                                                                     │^[[C2020-06-30 10:31:17,712 # Exiting Pyterm
make: *** [/home/pi/.tmp/RobotFW-tests/RIOT/tests/periph_timer/../../Makefile.include:719: term] Interrupt                                                                 │make: *** [/home/pi/.tmp/RobotFW-tests/RIOT/tests/periph_timer/../../Makefile.include:719: term] Interrupt                                                       │make: *** [/home/pi/.tmp/RobotFW-tests/RIOT/tests/periph_timer/../../Makefile.include:719: term] Interrupt
                                                                                                                                                                           │                                                                                                                                                                 │
pi@HIL-R2P1:~/.tmp/RobotFW-tests/RIOT $ echo $BOARD                                                                                                                        │pi@HIL-R2P2:~/.tmp/RobotFW-tests/RIOT $ echo $BOARD                                                                                                              │pi@HIL-R2P3:~/.tmp/RobotFW-tests/RIOT $ echo $BOARD
remote-revb                                                                                                                                                                │arduino-mega2560                                                                                                                                                 │nucleo-f103rb
pi@HIL-R2P1:~/.tmp/RobotFW-tests/RIOT $                                                                                                                                    │pi@HIL-R2P2:~/.tmp/RobotFW-tests/RIOT $                                                                                                                          │pi@HIL-R2P3:~/.tmp/RobotFW-tests/RIOT $                                                                                                                                                                                           
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┬──────────────────────────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────┬─────────────────────────────────────────────┴────────────────────────────────────────────────────────────────────────────────────────────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
READY                                                                                                                                           │2020-06-30 10:30:08,067 # TIMER_0: stopped                                                                                                    │2020-06-30 10:30:08,041 # TIMER_0: initialization successful                                                                              │2020-06-30 10:30:08,044 # TIMER_0: initialization successful
s                                                                                                                                               │2020-06-30 10:30:08,072 # TIMER_0: set channel 0 to 5000                                                                                      │2020-06-30 10:30:08,045 # TIMER_0: stopped                                                                                                │2020-06-30 10:30:08,047 # TIMER_0: stopped
START                                                                                                                                           │2020-06-30 10:30:08,076 # TIMER_0: starting                                                                                                   │2020-06-30 10:30:08,050 # TIMER_0: set channel 0 to 5000                                                                                  │2020-06-30 10:30:08,053 # TIMER_0: set channel 0 to 5000
main(): This is RIOT! (Version: 2020.07-devel-1631-g2e1b8-tst14391)                                                                             │2020-06-30 10:30:08,205 # TIMER_0: channel 0 fired at SW count   732145 - init:   732145                                                      │2020-06-30 10:30:08,055 # TIMER_0: set channel 1 to 10000                                                                                 │2020-06-30 10:30:08,058 # TIMER_0: set channel 1 to 10000
                                                                                                                                                │2020-06-30 10:30:08,206 #                                                                                                                     │2020-06-30 10:30:08,061 # TIMER_0: set channel 2 to 15000                                                                                 │2020-06-30 10:30:08,063 # TIMER_0: set channel 2 to 15000
Test for peripheral TIMERs                                                                                                                      │2020-06-30 10:30:08,209 # Testing TIMER_1:                                                                                                    │2020-06-30 10:30:08,066 # TIMER_0: set channel 3 to 20000                                                                                 │2020-06-30 10:30:08,069 # TIMER_0: set channel 3 to 20000
                                                                                                                                                │2020-06-30 10:30:08,212 # TIMER_1: initialization successful                                                                                  │2020-06-30 10:30:08,069 # TIMER_0: starting                                                                                               │2020-06-30 10:30:08,073 # TIMER_0: starting
Available timers: 1                                                                                                                             │2020-06-30 10:30:08,214 # TIMER_1: stopped                                                                                                    │2020-06-30 10:30:08,079 # TIMER_0: channel 0 fired at SW count    18462 - init:    18462                                                  │2020-06-30 10:30:08,083 # TIMER_0: channel 0 fired at SW count   179995 - init:   179995
                                                                                                                                                │2020-06-30 10:30:08,217 # TIMER_1: set channel 0 to 5000                                                                                      │2020-06-30 10:30:08,089 # TIMER_0: channel 1 fired at SW count    36911 - diff:    18449                                                  │2020-06-30 10:30:08,093 # TIMER_0: channel 1 fired at SW count   359936 - diff:   179941
Testing TIMER_0:                                                                                                                                │2020-06-30 10:30:08,219 # TIMER_1: starting                                                                                                   │2020-06-30 10:30:08,099 # TIMER_0: channel 2 fired at SW count    55358 - diff:    18447                                                  │2020-06-30 10:30:08,103 # TIMER_0: channel 2 fired at SW count   539873 - diff:   179937
TIMER_0: initialization successful                                                                                                              │2020-06-30 10:30:08,370 # TIMER_1: channel 0 fired at SW count   734628 - init:   734628                                                      │2020-06-30 10:30:08,109 # TIMER_0: channel 3 fired at SW count    73804 - diff:    18446                                                  │2020-06-30 10:30:08,113 # TIMER_0: channel 3 fired at SW count   719816 - diff:   179943
TIMER_0: stopped                                                                                                                                │2020-06-30 10:30:08,371 #                                                                                                                     │2020-06-30 10:30:08,110 #                                                                                                                 │2020-06-30 10:30:08,114 # 
TIMER_0: set channel 0 to 5000                                                                                                                  │2020-06-30 10:30:08,373 # TEST SUCCEEDED                                                                                                      │2020-06-30 10:30:08,113 # TEST SUCCEEDED                                                                                                  │2020-06-30 10:30:08,116 # TEST SUCCEEDED
TIMER_0: starting                                                                                                                               │^[[C2020-06-30 10:31:17,813 # Exiting Pyterm                                                                                                  │^[[C2020-06-30 10:31:17,711 # Exiting Pyterm                                                                                              │^[[C2020-06-30 10:31:17,710 # Exiting Pyterm
TIMER_0: channel 0 fired at SW count   185017 - init:   185017                                                                                  │make: *** [/home/pi/.tmp/RobotFW-tests/RIOT/tests/periph_timer/../../Makefile.include:719: term] Interrupt                                    │make: *** [/home/pi/.tmp/RobotFW-tests/RIOT/tests/periph_timer/../../Makefile.include:719: term] Interrupt                                │make: *** [/home/pi/.tmp/RobotFW-tests/RIOT/tests/periph_timer/../../Makefile.include:719: term] Interrupt
                                                                                                                                                │                                                                                                                                              │                                                                                                                                          │
TEST SUCCEEDED                                                                                                                                  │pi@HIL-R3P2:~/.tmp/RobotFW-tests/RIOT $ echo $BOARD                                                                                           │pi@HIL-R3P3:~/.tmp/RobotFW-tests/RIOT $ echo $BOARD                                                                                       │pi@HIL-R3P4:~/.tmp/RobotFW-tests/RIOT $ echo $BOARD
^[[D^[[C^[[C^Cecho $BOARD                                                                                                                       │frdm-kw41z                                                                                                                                    │nucleo-f091rc                                                                                                                             │nucleo-f767zi
                                                                                                                                                │pi@HIL-R3P2:~/.tmp/RobotFW-tests/RIOT $                                                                                                       │pi@HIL-R3P3:~/.tmp/RobotFW-tests/RIOT $                                                                                                   │pi@HIL-R3P4:~/.tmp/RobotFW-tests/RIOT $                                                                                              
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
2020-06-30 10:30:08,589 #                                                                                                                       │2020-06-30 10:30:08,034 #                                                                                                                     │2020-06-30 10:30:08,089 # TIMER_1: stopped                                                                                                │2020-06-30 10:30:08,115 # 
2020-06-30 10:30:08,606 # Testing TIMER_1:                                                                                                      │2020-06-30 10:30:08,038 # Available timers: 1                                                                                                 │2020-06-30 10:30:08,094 # TIMER_1: set channel 0 to 5000                                                                                  │2020-06-30 10:30:08,119 # Testing TIMER_1:
2020-06-30 10:30:08,642 # TIMER_1: initialization successful                                                                                    │2020-06-30 10:30:08,039 #                                                                                                                     │2020-06-30 10:30:08,098 # TIMER_1: starting                                                                                               │2020-06-30 10:30:08,125 # TIMER_1: initialization successful
2020-06-30 10:30:08,660 # TIMER_1: stopped                                                                                                      │2020-06-30 10:30:08,042 # Testing TIMER_0:                                                                                                    │2020-06-30 10:30:08,108 # TIMER_1: channel 0 fired at SW count     2708 - init:     2708                                                  │2020-06-30 10:30:08,129 # TIMER_1: stopped
2020-06-30 10:30:08,692 # TIMER_1: set channel 0 to 5000                                                                                        │2020-06-30 10:30:08,051 # TIMER_0: initialization successful                                                                                  │2020-06-30 10:30:08,109 #                                                                                                                 │2020-06-30 10:30:08,135 # TIMER_1: set channel 0 to 5000
2020-06-30 10:30:08,725 # TIMER_1: set channel 1 to 10000                                                                                       │2020-06-30 10:30:08,055 # TIMER_0: stopped                                                                                                    │2020-06-30 10:30:08,112 # Testing TIMER_2:                                                                                                │2020-06-30 10:30:08,141 # TIMER_1: set channel 1 to 10000
2020-06-30 10:30:08,757 # TIMER_1: set channel 2 to 15000                                                                                       │2020-06-30 10:30:08,061 # TIMER_0: set channel 0 to 5000                                                                                      │2020-06-30 10:30:08,118 # TIMER_2: initialization successful                                                                              │2020-06-30 10:30:08,145 # TIMER_1: set channel 2 to 15000
2020-06-30 10:30:08,778 # TIMER_1: starting                                                                                                     │2020-06-30 10:30:08,066 # TIMER_0: set channel 1 to 10000                                                                                     │2020-06-30 10:30:08,121 # TIMER_2: stopped                                                                                                │2020-06-30 10:30:08,147 # TIMER_1: starting
2020-06-30 10:30:08,901 # TIMER_1: channel 0 fired at SW count    11426 - init:    11426                                                        │2020-06-30 10:30:08,069 # TIMER_0: starting                                                                                                   │2020-06-30 10:30:08,126 # TIMER_2: set channel 0 to 5000                                                                                  │2020-06-30 10:30:08,151 # TIMER_1: channel 0 fired at SW count    17498 - init:    17498
2020-06-30 10:30:08,966 # TIMER_1: channel 1 fired at SW count    22845 - diff:    11419                                                        │2020-06-30 10:30:08,079 # TIMER_0: channel 0 fired at SW count     6668 - init:     6668                                                      │2020-06-30 10:30:08,128 # TIMER_2: starting                                                                                               │2020-06-30 10:30:08,156 # TIMER_1: channel 1 fired at SW count    34991 - diff:    17493
2020-06-30 10:30:09,032 # TIMER_1: channel 2 fired at SW count    34264 - diff:    11419                                                        │2020-06-30 10:30:08,089 # TIMER_0: channel 1 fired at SW count    13323 - diff:     6655                                                      │2020-06-30 10:30:08,132 # TIMER_2: channel 0 fired at SW count     2707 - init:     2707                                                  │2020-06-30 10:30:08,160 # TIMER_1: channel 2 fired at SW count    52484 - diff:    17493
2020-06-30 10:30:09,033 #                                                                                                                       │2020-06-30 10:30:08,090 #                                                                                                                     │2020-06-30 10:30:08,133 #                                                                                                                 │2020-06-30 10:30:08,161 # 
2020-06-30 10:30:09,048 # TEST SUCCEEDED                                                                                                        │2020-06-30 10:30:08,093 # TEST SUCCEEDED                                                                                                      │2020-06-30 10:30:08,134 # TEST SUCCEEDED                                                                                                  │2020-06-30 10:30:08,162 # TEST SUCCEEDED
^[[C2020-06-30 10:31:17,812 # Exiting Pyterm                                                                                                    │^[[C2020-06-30 10:31:17,812 # Exiting Pyterm                                                                                                  │^[[C2020-06-30 10:31:17,813 # Exiting Pyterm                                                                                              │^[[C2020-06-30 10:31:17,814 # Exiting Pyterm
make: *** [/home/pi/.tmp/RobotFW-tests/RIOT/tests/periph_timer/../../Makefile.include:719: term] Interrupt                                      │make: *** [/home/pi/.tmp/RobotFW-tests/RIOT/tests/periph_timer/../../Makefile.include:719: term] Interrupt                                    │make: *** [/home/pi/.tmp/RobotFW-tests/RIOT/tests/periph_timer/../../Makefile.include:719: term] Interrupt                                │make: *** [/home/pi/.tmp/RobotFW-tests/RIOT/tests/periph_timer/../../Makefile.include:719: term] Interrupt
                                                                                                                                                │                                                                                                                                              │                                                                                                                                          │
pi@HIL-R3P5:~/.tmp/RobotFW-tests/RIOT $ echo $BOARD                                                                                             │pi@HIL-R3P6:~/.tmp/RobotFW-tests/RIOT $ echo $BOARD                                                                                           │pi@HIL-R3P7:~/.tmp/RobotFW-tests/RIOT $ echo $BOARD                                                                                       │pi@HIL-R3P8:~/.tmp/RobotFW-tests/RIOT $ echo $BOARD
arduino-mega2560                                                                                                                                │saml10-xpro                                                                                                                                   │esp32-wroom-32                                                                                                                            │arduino-due
pi@HIL-R3P5:~/.tmp/RobotFW-tests/RIOT $                                                                                                         │pi@HIL-R3P6:~/.tmp/RobotFW-tests/RIOT $                                                                                                       │pi@HIL-R3P7:~/.tmp/RobotFW-tests/RIOT $                                                                                                   │pi@HIL-R3P8:~/.tmp/RobotFW-tests/RIOT $                                                                                              

@MrKevinWeiss
Copy link
Contributor

MrKevinWeiss commented Jun 30, 2020

samr21-xpro
nucleo-l073rz
nucleo-f411re
arduino-mega2560
nucleo-f103rb
nucleo-f091rc
nucleo-f767zi
saml10-xpro

All boards PASSED

tests/periph_timer_periodic
2020-06-30 10:40:58,584 # [0] tick                                                            │2020-06-30 10:40:58,658 # [0] tick                                                     │2020-06-30 10:40:58,659 # [0] tick
2020-06-30 10:40:58,608 # [0] tick                                                            │2020-06-30 10:40:58,684 # [0] tick                                                     │2020-06-30 10:40:58,684 # [0] tick
2020-06-30 10:40:58,633 # [0] tick                                                            │2020-06-30 10:40:58,709 # [0] tick                                                     │2020-06-30 10:40:58,710 # [0] tick
2020-06-30 10:40:58,658 # [0] tick                                                            │2020-06-30 10:40:58,735 # [0] tick                                                     │2020-06-30 10:40:58,735 # [0] tick
2020-06-30 10:40:58,683 # [0] tick                                                            │2020-06-30 10:40:58,759 # [0] tick                                                     │2020-06-30 10:40:58,760 # [0] tick
2020-06-30 10:40:58,709 # [0] tick                                                            │2020-06-30 10:40:58,784 # [0] tick                                                     │2020-06-30 10:40:58,784 # [0] tick
2020-06-30 10:40:58,734 # [0] tick                                                            │2020-06-30 10:40:58,808 # [0] tick                                                     │2020-06-30 10:40:58,809 # [0] tick
2020-06-30 10:40:58,759 # [0] tick                                                            │2020-06-30 10:40:58,833 # [0] tick                                                     │2020-06-30 10:40:58,835 # [0] tick
2020-06-30 10:40:58,784 # [0] tick                                                            │2020-06-30 10:40:58,859 # [0] tick                                                     │2020-06-30 10:40:58,860 # [0] tick
2020-06-30 10:40:58,809 # [0] tick                                                            │2020-06-30 10:40:58,860 #                                                              │2020-06-30 10:40:58,861 # 
2020-06-30 10:40:58,834 # [0] tick                                                            │2020-06-30 10:40:58,861 # Cycles:                                                      │2020-06-30 10:40:58,863 # Cycles:
2020-06-30 10:40:58,835 #                                                                     │2020-06-30 10:40:58,865 # channel 0 = 12        [OK]                                   │2020-06-30 10:40:58,867 # channel 0 = 12        [OK]
2020-06-30 10:40:58,837 # Cycles:                                                             │2020-06-30 10:40:58,869 # channel 1 = 00        [OK]                                   │2020-06-30 10:40:58,870 # channel 1 = 00        [OK]
2020-06-30 10:40:58,841 # channel 0 = 12        [OK]                                          │2020-06-30 10:40:58,873 # channel 2 = 00        [OK]                                   │2020-06-30 10:40:58,874 # channel 2 = 00        [OK]
2020-06-30 10:40:58,846 # channel 1 = 00        [OK]                                          │2020-06-30 10:40:58,876 # channel 3 = 00        [OK]                                   │2020-06-30 10:40:58,878 # channel 3 = 00        [OK]
2020-06-30 10:40:58,849 # TEST SUCCEEDED                                                      │2020-06-30 10:40:58,879 # TEST SUCCEEDED                                               │2020-06-30 10:40:58,881 # TEST SUCCEEDED
2020-06-30 10:41:02,550 # Exiting Pyterm                                                      │2020-06-30 10:41:02,551 # Exiting Pyterm                                               │2020-06-30 10:41:02,552 # Exiting Pyterm
make: *** [/home/pi/.tmp/RobotFW-tests/RIOT/tests/periph_timer_periodic/../../Makefile.include│make: *** [/home/pi/.tmp/RobotFW-tests/RIOT/tests/periph_timer_periodic/../../Makefile.│make: *** [/home/pi/.tmp/RobotFW-tests/RIOT/tests/periph_timer_periodic/../../Makefile.inclu
:719: term] Interrupt                                                                         │include:719: term] Interrupt                                                           │de:719: term] Interrupt
                                                                                              │                                                                                       │
pi@HIL-R1P1:~/.tmp/RobotFW-tests/RIOT $ echo $BOARD                                           │pi@HIL-R1P3:~/.tmp/RobotFW-tests/RIOT $ echo $BOARD                                    │pi@HIL-R1P4:~/.tmp/RobotFW-tests/RIOT $ echo $BOARD
samr21-xpro                                                                                   │nucleo-l073rz                                                                          │nucleo-f411re
pi@HIL-R1P1:~/.tmp/RobotFW-tests/RIOT $                                                       │pi@HIL-R1P3:~/.tmp/RobotFW-tests/RIOT $                                                │pi@HIL-R1P4:~/.tmp/RobotFW-tests/RIOT $                                                     
──────────────────────────────────────────────────────────────────────────────────────────────┴────────────────────────────────────────────────┬──────────────────────────────────────┴────────────────────────────────────────────────────────────────────────────────────────────
2020-06-30 10:40:58,920 # [0] tick                                                                                                             │2020-06-30 10:40:58,758 # [0] tick
2020-06-30 10:40:58,945 # [0] tick                                                                                                             │2020-06-30 10:40:58,783 # [0] tick
2020-06-30 10:40:58,969 # [0] tick                                                                                                             │2020-06-30 10:40:58,808 # [0] tick
2020-06-30 10:40:58,997 # [0] tick                                                                                                             │2020-06-30 10:40:58,834 # [0] tick
2020-06-30 10:40:59,021 # [0] tick                                                                                                             │2020-06-30 10:40:58,859 # [0] tick
2020-06-30 10:40:59,046 # [0] tick                                                                                                             │2020-06-30 10:40:58,860 # 
2020-06-30 10:40:59,047 #                                                                                                                      │2020-06-30 10:40:58,862 # Cycles:
2020-06-30 10:40:59,054 # Cycles:                                                                                                              │2020-06-30 10:40:58,865 # channel 0 = 12        [OK]
2020-06-30 10:40:59,075 # channel 0 = 12        [OK]                                                                                           │2020-06-30 10:40:58,869 # channel 1 = 00        [OK]
2020-06-30 10:40:59,095 # channel 1 = 00        [OK]                                                                                           │2020-06-30 10:40:58,873 # channel 2 = 00        [OK]
2020-06-30 10:40:59,117 # channel 2 = 00        [OK]                                                                                           │2020-06-30 10:40:58,876 # channel 3 = 00        [OK]
2020-06-30 10:40:59,133 # TEST SUCCEEDED                                                                                                       │2020-06-30 10:40:58,879 # TEST SUCCEEDED
2020-06-30 10:41:02,551 # Exiting Pyterm                                                                                                       │2020-06-30 10:41:02,551 # Exiting Pyterm
make: *** [/home/pi/.tmp/RobotFW-tests/RIOT/tests/periph_timer_periodic/../../Makefile.include:719: term] Interrupt                            │make: *** [/home/pi/.tmp/RobotFW-tests/RIOT/tests/periph_timer_periodic/../../Makefile.include:719: term] Interrupt
                                                                                                                                               │
pi@HIL-R2P2:~/.tmp/RobotFW-tests/RIOT $ echo $BOARD                                                                                            │pi@HIL-R2P3:~/.tmp/RobotFW-tests/RIOT $ echo $BOARD
arduino-mega2560                                                                                                                               │nucleo-f103rb
pi@HIL-R2P2:~/.tmp/RobotFW-tests/RIOT $                                                                                                        │pi@HIL-R2P3:~/.tmp/RobotFW-tests/RIOT $                                                                                            
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
2020-06-30 10:40:58,737 # [0] tick                                                                                                             │2020-06-30 10:40:58,737 # [0] tick
2020-06-30 10:40:58,760 # [0] tick                                                                                                             │2020-06-30 10:40:58,761 # [0] tick
2020-06-30 10:40:58,785 # [0] tick                                                                                                             │2020-06-30 10:40:58,785 # [0] tick
2020-06-30 10:40:58,811 # [0] tick                                                                                                             │2020-06-30 10:40:58,810 # [0] tick
2020-06-30 10:40:58,835 # [0] tick                                                                                                             │2020-06-30 10:40:58,835 # [0] tick
2020-06-30 10:40:58,861 # [0] tick                                                                                                             │2020-06-30 10:40:58,861 # [0] tick
2020-06-30 10:40:58,862 #                                                                                                                      │2020-06-30 10:40:58,862 # 
2020-06-30 10:40:58,864 # Cycles:                                                                                                              │2020-06-30 10:40:58,864 # Cycles:
2020-06-30 10:40:58,868 # channel 0 = 12        [OK]                                                                                           │2020-06-30 10:40:58,871 # channel 0 = 12        [OK]
2020-06-30 10:40:58,872 # channel 1 = 00        [OK]                                                                                           │2020-06-30 10:40:58,877 # channel 1 = 00        [OK]
2020-06-30 10:40:58,876 # channel 2 = 00        [OK]                                                                                           │2020-06-30 10:40:58,883 # channel 2 = 00        [OK]
2020-06-30 10:40:58,881 # channel 3 = 00        [OK]                                                                                           │2020-06-30 10:40:58,890 # channel 3 = 00        [OK]
2020-06-30 10:40:58,884 # TEST SUCCEEDED                                                                                                       │2020-06-30 10:40:58,895 # TEST SUCCEEDED
2020-06-30 10:41:02,551 # Exiting Pyterm                                                                                                       │2020-06-30 10:41:02,547 # Exiting Pyterm
make: *** [/home/pi/.tmp/RobotFW-tests/RIOT/tests/periph_timer_periodic/../../Makefile.include:719: term] Interrupt                            │make: *** [/home/pi/.tmp/RobotFW-tests/RIOT/tests/periph_timer_periodic/../../Makefile.include:719: term] Interrupt
                                                                                                                                               │
pi@HIL-R3P3:~/.tmp/RobotFW-tests/RIOT $ echo $BOARD                                                                                            │pi@HIL-R3P4:~/.tmp/RobotFW-tests/RIOT $ echo $BOARD
nucleo-f091rc                                                                                                                                  │nucleo-f767zi
pi@HIL-R3P3:~/.tmp/RobotFW-tests/RIOT $                                                                                                        │pi@HIL-R3P4:~/.tmp/RobotFW-tests/RIOT $                                                                                            
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
2020-06-30 10:40:58,904 # [0] tick                                                                                                             │2020-06-30 10:40:58,661 # [0] tick
2020-06-30 10:40:58,930 # [0] tick                                                                                                             │2020-06-30 10:40:58,685 # [0] tick
2020-06-30 10:40:58,954 # [0] tick                                                                                                             │2020-06-30 10:40:58,710 # [0] tick
2020-06-30 10:40:58,979 # [0] tick                                                                                                             │2020-06-30 10:40:58,735 # [0] tick
2020-06-30 10:40:59,004 # [0] tick                                                                                                             │2020-06-30 10:40:58,760 # [0] tick
2020-06-30 10:40:59,028 # [0] tick                                                                                                             │2020-06-30 10:40:58,785 # [0] tick
2020-06-30 10:40:59,053 # [0] tick                                                                                                             │2020-06-30 10:40:58,810 # [0] tick
2020-06-30 10:40:59,057 #                                                                                                                      │2020-06-30 10:40:58,835 # [0] tick
2020-06-30 10:40:59,064 # Cycles:                                                                                                              │2020-06-30 10:40:58,836 # 
2020-06-30 10:40:59,084 # channel 0 = 12        [OK]                                                                                           │2020-06-30 10:40:58,838 # Cycles:
2020-06-30 10:40:59,106 # channel 1 = 00        [OK]                                                                                           │2020-06-30 10:40:58,842 # channel 0 = 12        [OK]
2020-06-30 10:40:59,126 # channel 2 = 00        [OK]                                                                                           │2020-06-30 10:40:58,845 # channel 1 = 00        [OK]
2020-06-30 10:40:59,142 # TEST SUCCEEDED                                                                                                       │2020-06-30 10:40:58,848 # TEST SUCCEEDED
2020-06-30 10:41:02,755 # Exiting Pyterm                                                                                                       │2020-06-30 10:41:02,554 # Exiting Pyterm
make: *** [/home/pi/.tmp/RobotFW-tests/RIOT/tests/periph_timer_periodic/../../Makefile.include:719: term] Interrupt                            │make: *** [/home/pi/.tmp/RobotFW-tests/RIOT/tests/periph_timer_periodic/../../Makefile.include:719: term] Interrupt
                                                                                                                                               │
pi@HIL-R3P5:~/.tmp/RobotFW-tests/RIOT $ echo $BOARD                                                                                            │pi@HIL-R3P6:~/.tmp/RobotFW-tests/RIOT $ echo $BOARD
arduino-mega2560                                                                                                                               │saml10-xpro
pi@HIL-R3P5:~/.tmp/RobotFW-tests/RIOT $                                                                                                        │pi@HIL-R3P6:~/.tmp/RobotFW-tests/RIOT $                                                                                            

Copy link
Contributor

@MrKevinWeiss MrKevinWeiss left a comment

Choose a reason for hiding this comment

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

The code looks good to me. If someone who worked on stm timers has anything to say then now is the time!

Copy link
Member

@maribu maribu left a comment

Choose a reason for hiding this comment

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

See inline comments

Comment on lines 128 to 151
/**
* @brief Set timer TOP to the lowest reset on match channel
*/
static void _set_arr(tim_t tim)
{
uint32_t dir = dev(tim)->DIER;
uint32_t arr = timer_config[tim].max;

/* find the lowest reset value */
for (unsigned int i = 0; i < TIMER_CHANNEL_NUMOF; i++) {

/* skip disabled channels */
if ((dir & (TIM_DIER_CC1IE << i)) == 0) {
continue;
}

uint32_t cc = TIM_CHAN(tim, i);
if (is_reset_on_match(tim, i) && cc < arr) {
arr = cc;
}
}

dev(tim)->ARR = arr;
}
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason why TIM_FLAG_RESET_ON_MATCH is allowed for multiple channels? Otherwise, I wouldn't mind adding an @pre to the API doc that at most one channel per timer may be used with TIM_FLAG_RESET_ON_MATCH.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The documentation for TIM_FLAG_RESET_ON_MATCH says

When set on multiple channels, only the channel with the lowest match value will be reached.

so if you could have two channels with this flag and only the lower one would be reached.
Then if you disable the lower channel, the higher one would be used.

However, this is not used anywhere and with the Atmel timers (both on AVR & ARM) only channel 0 can be used as TOP value.

So yea, we could extend the API documentation here.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we could even restrict it to a certain channel, then? E.g.:

#ifndef HAVE_TIMER_GET_PERIODIC_CHANNEL
static inline int timer_get_periodic_channel(tim_t tim)
{
    (void)tim;
    return 0;
}
#endif /* HAVE_TIMER_GET_PERIODIC_CHANNEL */

Copy link
Member

Choose a reason for hiding this comment

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

Care to create a PR limiting the use of TIM_FLAG_RESET_ON_MATCH by extending the doc?

Copy link
Contributor Author

@benpicco benpicco Jul 27, 2020

Choose a reason for hiding this comment

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

Can I just piggy-back it on this PR?

Copy link
Member

Choose a reason for hiding this comment

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

I would prefer a separate PR, as it is formally an API change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved it to a separate PR.
This doesn't change anything - TIM_FLAG_RESET_ON_MATCH is already documented on it's own.

Copy link
Member

Choose a reason for hiding this comment

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

With #14619 in, you should be able to simplify the code here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright!
Still untested though

@maribu
Copy link
Member

maribu commented Jul 23, 2020

Feel free to squash

@benpicco benpicco force-pushed the cpu/stm32-timer_periodic branch from d67c160 to c70b272 Compare July 23, 2020 16:25
@benpicco
Copy link
Contributor Author

Squashed.

@benpicco benpicco removed the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Aug 7, 2020
Comment on lines 190 to 162
if (flags & TIM_FLAG_RESET_ON_SET) {
/* setting COUNT gives us an interrupt on all channels */
set_ignore_irq(tim);
dev(tim)->CNT = 0;
}
Copy link
Member

Choose a reason for hiding this comment

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

Have you tried if wrapping this is irq_disable() ... irq_restore() and clearing the interrupt flags from the status registers works? IMO, that would be favorable over conditionally ignoring IRQs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, that simplifies things quite a bit.

@maribu
Copy link
Member

maribu commented Aug 8, 2020

make -C tests/periph_timer_periodic test fails. It asserts that the test run takes between 1.0 and 1.5 seconds, but on my Nucleo F767ZI it is done in ~0.33 seconds.

@benpicco
Copy link
Contributor Author

benpicco commented Aug 8, 2020

Yea I lowered the cycle duration without adjusting the testcase - fixed.

Copy link
Member

@maribu maribu left a comment

Choose a reason for hiding this comment

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

ACK. Code looks good and both periph_timer and periph_timer_periodic are passing. (periph_timer_short_relative_set fails, as expected. But that is unrelated to this PR.)

benpicco and others added 3 commits August 9, 2020 22:55
Reduce CYCLE_MS to 25 ms so the period also fits into a 16 bit 1 MHz
timer.
Seems like the Interrupt flag for a Capture/Compare channel gets set when

- the CC-value is reached
- the timer resets before the CC value is reached.

We only want the first event and ignore the second one. Unfortunately I did
not find a way to disable the second event type, so it is filtered in software.

That is we need to

 - ignore the CC-interrupts when the COUNT register register is reset
 - ignore the CC-interrupts > TOP value/ARR (auto-reload register)
@benpicco benpicco force-pushed the cpu/stm32-timer_periodic branch from 7e57e6b to 29f83a6 Compare August 9, 2020 20:55
@benpicco benpicco added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Aug 9, 2020
@maribu maribu merged commit 7d9aed7 into RIOT-OS:master Aug 10, 2020
@benpicco benpicco deleted the cpu/stm32-timer_periodic branch August 10, 2020 07:26
Comment on lines +19 to +21
# test should run 10 cycles with 25ms each
assert (end - start) > 0.25
assert (end - start) < 0.35
Copy link
Contributor

Choose a reason for hiding this comment

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

On atmega (arduino-uno and arduino-mega2560) it takes 0.3523.... can we simply increase the margin to fix the test or might something else be going on? Found while running RIOT-OS/Release-Specs#192.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea pushing it to 40 ms won't hurt much if it helps with slow UARTs.

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 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