stm32-async-1wire 3.2.0
Non-blocking 1-Wire master for STM32 with DS18B20 temperature and DS2431 EEPROM drivers
Loading...
Searching...
No Matches
ow_config.h File Reference

Central compile-time configuration for the 1-Wire stack. More...

#include <stdint.h>

Go to the source code of this file.

Macros

#define OW_PARASITE_POWER   0
 Compile-time flag: bus is wired for parasite power.
#define ONEWIRE_ONE_PULSE   5
 Duration of a '1' bit write/read pulse in microseconds.
#define ONEWIRE_ZERO_PULSE   60
 Duration of a '0' bit write pulse in microseconds.
#define ONEWIRE_GUARD_BAND   5
 Guard interval between the end of a write/read slot and the next slot, in microseconds.
#define ONEWIRE_SHORT_PULSE_MAX   10
 Upper bound (in µs) for the short-pulse detection window.
#define OW_BUS_DRIVE_WEAK   0
 GPIO output speed / drive strength for the 1-Wire bus pin.
#define OW_BUS_DRIVE_MEDIUM   1
#define OW_BUS_DRIVE_STRONG   2
#define OW_BUS_DRIVE_MAX   3
#define OW_BUS_DRIVE   OW_BUS_DRIVE_MAX
#define OW_DMA_PRIO   0
 Arbitration class of the 1-Wire feed and capture DMA channels.
#define OW_LOW_POWER   0
 Opt-in low-power WFE sleep path.
#define OW_DRIVE_ACTIVE   0
 Opt-in active-drive (push-pull) write path.
#define DS18B20_MAX_DEVICES   8
 Optional per-sensor pulse-width statistics module.
#define OW_CONFIG_SYSCLK_MHZ   0u
 Compile-time configuration token of the library build.
#define OW_CONFIG_TIM1_MHZ   0u
#define OW_CONFIG_TOKEN

Detailed Description

Central compile-time configuration for the 1-Wire stack.

All genuinely tunable build constants are collected here. Every macro carries its own #ifndef guard so that a -D on the command line (Makefile EXT, PlatformIO build_flags) overrides the default without touching this file — the existing override mechanism is unchanged. Note that these are preprocessor macros, not CMake options: the CMake project does not forward -D<macro>=... cache variables to the compiler, so pass the flags via the C flags (CMAKE_C_FLAGS / toolchain file) or, for the stats example, rely on the example target.

Protocol-inherent constants (ONEWIRE_MAX_SLOTS, ONEWIRE_MAX_READ_BYTES, DS18B20_RES_MIN, DS18B20_RES_MAX, DS18B20_RES_DEFAULT) and the system clock (OW_SYSCLK_MHZ) and timer kernel clock (OW_TIM1_MHZ, defaulting to OW_SYSCLK_MHZ) remain build facts; the port core uses them to program the 1us timer tick.

The four feature flags are value-style: define to 1 to enable, omit or set to 0 to disable. Old -D presence-only style (-DOW_LOW_POWER without =1) no longer works with these flags — always pass =1.

Macro Definition Documentation

◆ DS18B20_MAX_DEVICES

#define DS18B20_MAX_DEVICES   8

Optional per-sensor pulse-width statistics module.

When 1 the ow_stats module collects per-sensor pulse-width min/max, a global histogram and error counters; ow_stats_dump_start() streams them over UART. When 0 every inline body compiles away to nothing so there is zero overhead in production builds. Enable with -DOW_STATS_ENABLE=1.

See also
ow_stats.h for the public API.

Maximum number of DS18B20 devices tracked by the driver.

Size of the internal device table filled by the device search; the simultaneous-conversion (scan) mode uses it to address every sensor. Each entry costs DS18B20_ROM_BYTES (8) bytes of static RAM.

◆ ONEWIRE_GUARD_BAND

#define ONEWIRE_GUARD_BAND   5

Guard interval between the end of a write/read slot and the next slot, in microseconds.

5 µs is sufficient for external-power buses. When OW_PARASITE_POWER is 1 the default is raised to 100 µs to leave margin for the bus-pull-up capacitor (one full µs-tick period at the slowest supported clock).

◆ ONEWIRE_ONE_PULSE

#define ONEWIRE_ONE_PULSE   5

Duration of a '1' bit write/read pulse in microseconds.

DS18B20 requires only ≥ 1 µs and samples the slot at ≥ 15 µs after its start. The read-slot capture latency (bus RC rise + input filter

  • timer sync) stays far below the ONEWIRE_SHORT_PULSE_MAX window on all supported clocks.

Previous releases tried a 2 µs pulse for ≤ 16 MHz compensation. Hardware on STM32F030 @ 8 MHz showed that a 2 µs master pulse breaks the sensor's slot decoding outright — every capture stretches past the threshold regardless of the answer — while a plain 5 µs pulse measures ~ 9 µs there with every input-filter variant swept (fCK_INT N=2/4/8 and fDTS/4 N=8). The short-pulse path was tuned on F103 @ 8 MHz bench wiring whose slower rise is not reproduced by other boards; re-validate per board before reintroducing anything similar.

Note
Hardware-validated at 5 µs on every supported clock: STM32F030 @ 48/8 MHz, STM32F103 @ 72/8 MHz and STM32G031 @ 64/16 MHz.

◆ ONEWIRE_SHORT_PULSE_MAX

#define ONEWIRE_SHORT_PULSE_MAX   10

Upper bound (in µs) for the short-pulse detection window.

◆ ONEWIRE_ZERO_PULSE

#define ONEWIRE_ZERO_PULSE   60

Duration of a '0' bit write pulse in microseconds.

◆ OW_BUS_DRIVE

#define OW_BUS_DRIVE   OW_BUS_DRIVE_MAX

◆ OW_BUS_DRIVE_MAX

#define OW_BUS_DRIVE_MAX   3

◆ OW_BUS_DRIVE_MEDIUM

#define OW_BUS_DRIVE_MEDIUM   1

◆ OW_BUS_DRIVE_STRONG

#define OW_BUS_DRIVE_STRONG   2

◆ OW_BUS_DRIVE_WEAK

#define OW_BUS_DRIVE_WEAK   0

GPIO output speed / drive strength for the 1-Wire bus pin.

Controls the OSPEEDR/OSPEEDER bits on families with a separate speed register, or the MODE10 bits in CRH on F1, for the bus pin (PA10). Higher values increase the pad's ability to source current into heavy capacitive loads at the cost of higher EMI and marginally higher power consumption.

Values: 0 = WEAK (2 MHz, lowest drive) 1 = MEDIUM (25 MHz / 10 MHz on F1) 2 = STRONG (50 MHz / 50 MHz on F1 — F1 ceiling) 3 = MAX (100 MHz where the pad supports it; clamps to STRONG on F1)

Default: MAX — safe for parasite-powered multi-drop buses where the strong pull-up must source the whole fleet during broadcast conversion. Override with -DOW_BUS_DRIVE=N.

Note
F1 has no OSPEEDR; speed is set via MODE bits in CRH. WEAK/MEDIUM/STRONG map to 2/10/50 MHz; MAX equals STRONG.

◆ OW_CONFIG_SYSCLK_MHZ

#define OW_CONFIG_SYSCLK_MHZ   0u

Compile-time configuration token of the library build.

Mixes the macros that must agree between the translation units the library was compiled from and the application sources that include these headers: feature flags, DS18B20_MAX_DEVICES, SYSCLK and TIM1 kernel frequency. Compare it at startup with onewire_config_token(): a mismatch means the archive and the application were built with different -D flags and must not run together.

◆ OW_CONFIG_TIM1_MHZ

#define OW_CONFIG_TIM1_MHZ   0u

◆ OW_CONFIG_TOKEN

#define OW_CONFIG_TOKEN
Value:
((uint32_t)(OW_PARASITE_POWER & 1u) | ((uint32_t)(OW_LOW_POWER & 1u) << 1) | \
((uint32_t)(OW_DRIVE_ACTIVE & 1u) << 2) | ((uint32_t)(OW_STATS_ENABLE & 1u) << 3) | \
((uint32_t)(OW_BUS_DRIVE & 3u) << 4) | ((uint32_t)(DS18B20_MAX_DEVICES & 0xFFu) << 6) | \
((uint32_t)(OW_CONFIG_SYSCLK_MHZ & 0x1FFu) << 14) | \
((uint32_t)(OW_CONFIG_TIM1_MHZ & 0x1FFu) << 23))
#define OW_CONFIG_SYSCLK_MHZ
Compile-time configuration token of the library build.
Definition ow_config.h:275
#define OW_PARASITE_POWER
Compile-time flag: bus is wired for parasite power.
Definition ow_config.h:63
#define OW_LOW_POWER
Opt-in low-power WFE sleep path.
Definition ow_config.h:220
#define OW_BUS_DRIVE
Definition ow_config.h:156
#define OW_DRIVE_ACTIVE
Opt-in active-drive (push-pull) write path.
Definition ow_config.h:231
#define OW_CONFIG_TIM1_MHZ
Definition ow_config.h:280
#define DS18B20_MAX_DEVICES
Optional per-sensor pulse-width statistics module.
Definition ow_config.h:260

◆ OW_DMA_PRIO

#define OW_DMA_PRIO   0

Arbitration class of the 1-Wire feed and capture DMA channels.

0 = the reset class (the shipped default), 3 = the highest class. The encoding is per DMA IP and private to the engine (DMA_CCR_PL on the classic DMA1 channels, DMA_SxCR_PL on the F4/H7 streams, DMA_CCR_PRIO on the H5/C5/U5 GPDMA/LPDMA channels), so a build only ever passes a level.

Raise it when the application runs its own DMA above the driver's: on the benches a level-5 load starved the default class on F446 (8/16 MHz) and H503 (8/64/250 MHz). The measured minimum is per part: class 1 is enough on the F446 (load at PL 0), class 3 on the H503 (load at PRIO 3); a class below the load's own class starves. On classic DMA and F4 streams an equal-class load is still ordered by channel/stream index, so this is not a substitute for the portable rule there: a higher-ranked burst must not outlast the feed window (guard + 1 us). On the H5/U5 GPDMA only class 3 is a fixed higher class; class 0/1/2 share a weighted round-robin (RM0492 for the H5, RM0456 for the U5, GPDMA channel arbitration), and equal class is clean: CCR.PRIO does not break ties by channel number.

The knob changes no timing constant and no ABI, so it is deliberately not mixed into OW_CONFIG_TOKEN: an application and an archive built with different levels still agree on everything the token covers.

Enable with -DOW_DMA_PRIO=N (0..3).

◆ OW_DRIVE_ACTIVE

#define OW_DRIVE_ACTIVE   0

Opt-in active-drive (push-pull) write path.

When 1 the bus pin is temporarily switched to push-pull during master-only write slots (see Bus Electrical Model). Enable with -DOW_DRIVE_ACTIVE=1.

◆ OW_LOW_POWER

#define OW_LOW_POWER   0

Opt-in low-power WFE sleep path.

When 1 the TIM1 update interrupt (UIE) and SEVONPEND are armed for long hardware stages (> 1 ms), and the driver then idles the core in __WFE() until the stage is done, so the CPU does not spin instead. No ISR is ever installed and NVIC_EnableIRQ is never called; the pending bit is cleared explicitly by the engine so WFE does not degrade into a busy-loop.

The application's code is unchanged: the idling happens inside the driver's poll(), the application never waits for a result, and the result is ready at the same moment it would be in a spinning build.

Enable with -DOW_LOW_POWER=1.

◆ OW_PARASITE_POWER

#define OW_PARASITE_POWER   0

Compile-time flag: bus is wired for parasite power.

When 1 the default ONEWIRE_GUARD_BAND is raised from 5 µs to 100 µs to leave enough time for the bus-pull-up capacitor to charge. The Makefile TIMING= presets override GUARD_BAND directly and are unaffected.

Example applications use this flag to automatically call ds18b20_set_parasite(1) at startup — a runtime per-bus override that is independent of the compile-time guard-band default.