@@ -191,50 +191,6 @@ PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.usbserial*)))
191191PROGRAMMER ?= openocd
192192```
193193
194- ### Timer Configurations
195-
196- When using the high level timer ` ztimer ` there is an overhead in calling the
197- [ ztimer_sleep] ( https://doc.riot-os.org/group__sys__ztimer.html#gade98636e198f2d571c8acd861d29d360 )
198- and [ ztimer_set] ( https://doc.riot-os.org/group__sys__ztimer.html#ga8934a79a89e35d58673418a1e4a2e69c )
199- functions. This offset can be compensated for.
200- It can be measured by running ` tests/sys/ztimer_overhead ` on your board, i.e:
201-
202- ``` bash
203- $ BOARD=my-new-board make -C tests/sys/ztimer_overhead flash term
204- ```
205-
206- This should give the following output:
207- ```
208- main(): This is RIOT!
209- ZTIMER_USEC auto_adjust params:
210- ZTIMER_USEC->adjust_set = xx
211- ZTIMER_USEC->adjust_sleep = xx
212- ZTIMER_USEC auto_adjust params cleared
213- zitmer_overhead_set...
214- min=6 max=7 avg_diff=6
215- zitmer_overhead_sleep...
216- min=21 max=21 avg_diff=21
217- ZTIMER_USEC adjust params for my-new-board:
218- CONFIG_ZTIMER_USEC_ADJUST_SET 6
219- CONFIG_ZTIMER_USEC_ADJUST_SLEEP 21
220- ```
221-
222- The last two lines can be added as defines to the new board ` board.h ` :
223-
224- ``` c
225- /* *
226- * @name ztimer configuration values
227- * @{
228- */
229- #define CONFIG_ZTIMER_USEC_ADJUST_SET 6
230- #define CONFIG_ZTIMER_USEC_ADJUST_SLEEP 21
231- /* * @} */
232- ```
233-
234- Alternatively, the pseudomodule [ ztimer_auto_adjust] ( https://doc.riot-os.org/group__pseudomodule__ztimer__auto__adjust.html )
235- can be used in an application to enable automatic timer offset compensation at board startup.
236- This however incurs overhead both in the text segment and at bootup time.
237-
238194### doc.md
239195
240196Although not explicitly needed, if upstreamed and as a general good
@@ -277,6 +233,84 @@ the latest version with
277233pip install --upgrade riotgen
278234```
279235
236+ ## Timer Configuration
237+
238+ ### Timer Width
239+
240+ The ` ztimer ` driver assumes a timer register bit-width of 32-bits by default.
241+ If your microcontroller has a smaller timer register (e.g. 16-bits), you have
242+ to explicitly specify the maximum value the timer register can hold with the
243+ ` TIMER_0_MAX_VALUE ` define.
244+ This is the same value that is put in the ` max ` field of the ` timer_config `
245+ structure.
246+ Typical values are ` 0x0000FFFFUL ` for 16-bit wide timers, ` 0x00FFFFFFUL ` for
247+ 24-bit wide timers and ` 0xFFFFFFFFUL ` for 32-bit wide timers.
248+
249+ ``` c
250+ static const timer_conf_t timer_config[] = {
251+ {
252+ [...]
253+ .max = 0x0000ffff,
254+ [...]
255+ }
256+ };
257+
258+ #define TIMER_0_MAX_VALUE 0x0000FFFFUL
259+ ```
260+
261+ :::caution
262+ `ztimer` does not automatically check if the `max` field and the
263+ `TIMER_0_MAX_VALUE` definition match!
264+
265+ For example: If you observe "erratic" blinking patterns in
266+ `examples/basic/blinky`, make sure to check if the sizes match.
267+ :::
268+
269+ ### Overhead Calibration
270+
271+ When using the high level timer `ztimer` there is an overhead in calling the
272+ [ztimer_sleep](https://doc.riot-os.org/group__sys__ztimer.html#gade98636e198f2d571c8acd861d29d360)
273+ and [ztimer_set](https://doc.riot-os.org/group__sys__ztimer.html#ga8934a79a89e35d58673418a1e4a2e69c)
274+ functions. This offset can be compensated for.
275+ It can be measured by running `tests/sys/ztimer_overhead` on your board, i.e:
276+
277+ ```bash
278+ $ BOARD=my-new-board make -C tests/sys/ztimer_overhead flash term
279+ ```
280+
281+ This should give the following output:
282+ ```
283+ main(): This is RIOT!
284+ ZTIMER_USEC auto_adjust params:
285+ ZTIMER_USEC->adjust_set = xx
286+ ZTIMER_USEC->adjust_sleep = xx
287+ ZTIMER_USEC auto_adjust params cleared
288+ zitmer_overhead_set...
289+ min=6 max=7 avg_diff=6
290+ zitmer_overhead_sleep...
291+ min=21 max=21 avg_diff=21
292+ ZTIMER_USEC adjust params for my-new-board:
293+ CONFIG_ZTIMER_USEC_ADJUST_SET 6
294+ CONFIG_ZTIMER_USEC_ADJUST_SLEEP 21
295+ ```
296+
297+ The last two lines can be added as defines to the new board `board.h`:
298+
299+ ```c
300+ /**
301+ * @name ztimer configuration values
302+ * @{
303+ */
304+ #define CONFIG_ZTIMER_USEC_ADJUST_SET 6
305+ #define CONFIG_ZTIMER_USEC_ADJUST_SLEEP 21
306+ /** @} */
307+ ```
308+
309+ Alternatively, the pseudomodule
310+ [ ztimer_auto_adjust] ( https://doc.riot-os.org/group__pseudomodule__ztimer__auto__adjust.html )
311+ can be used in an application to enable automatic timer offset compensation at board startup.
312+ This however incurs overhead both in the text segment and at bootup time.
313+
280314## Helper Tools
281315
282316To help you start porting a board, the RIOT build system provides the
0 commit comments