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

Board facts: the family selection token and ow_pulse_t. More...

Functions

void onewire_init (void)
 Initialize the shared 1-Wire timer/DMA/GPIO resources.
uint32_t onewire_config_token (void)
 Configuration token the library was compiled with.
uint8_t onewire_clock_ok (uint32_t sysclk_mhz)
 Whether the runtime core clock agrees with the build.

Detailed Description

Board facts: the family selection token and ow_pulse_t.

The token resolves from the CMSIS device macro of the target (e.g. -DSTM32F030x6) or, for host-test mocks, PlatformIO and STM32CubeMX projects, from a family macro (STM32F0, STM32F1, STM32F3, STM32F4, STM32G0, STM32G4, STM32L4, STM32C5, STM32H5, STM32U5, STM32H7). Concrete device spellings are accepted for the parts this project supports (STM32F030x6 for F0; STM32F103xB for F1; STM32F303xC for F3; STM32F407xx / STM32F401xC / STM32F446xx for F4; STM32G031xx for G0; STM32G474xx for G4; STM32L476xx for L4; STM32C552xx for C5; STM32H503xx for H5; STM32U585xx for U5; STM32H743xx for H7). The token is the single point of family selection: app.c takes the device header and clock configuration from it, and the per-family facts ow_pulse_t and the OW_HSE_MHZ / OW_*_MAX_SYSCLK_MHZ defaults live in inc/ow_board.h beside it. The TIM1+DMA engine and the register-level per-family facts are library-internal and are not needed to use this API. To add a family, extend the dispatch in inc/ow_board.h (plus the #error spelling list), the app.c clock/UART config, a chips/<part>.mk part file, the Makefile (OW_KNOWN_TARGETS, the OW_TARGET family block, the OW_MCU mapping entries, TEST_CLOCK_FLAG) and CMakeLists.txt (the OW_MCU mapping, the OW_TARGET branch, the default chip) wiring, the tests/mock device header, and a case in tests/test/test_sysclk_fallback.c.

Function Documentation

◆ onewire_clock_ok()

uint8_t onewire_clock_ok ( uint32_t sysclk_mhz)

Whether the runtime core clock agrees with the build.

Parameters
[in]sysclk_mhzCore clock in whole MHz as the firmware actually runs, e.g. (SystemCoreClock / 1000000u)
Returns
1 when the core-clock reading matches OW_SYSCLK_MHZ
Note
Call once at startup before any bus operation and refuse to run on 0: with -DOW_SYSCLK_MHZ this validates the core clock; the timer prescaler is compiled from OW_TIM1_MHZ (defaults to OW_SYSCLK_MHZ). A split-clock target must configure TIM1 to that timer frequency. Without -DOW_SYSCLK_MHZ (SystemCoreClock auto-path) the port derives its timer prescaler from SystemCoreClock itself, so this only rejects a zero/uninitialized reading - staleness after a clock-tree change is undetectable here, call SystemCoreClockUpdate().

◆ onewire_config_token()

uint32_t onewire_config_token ( void )

Configuration token the library was compiled with.

Returns
OW_CONFIG_TOKEN as seen by the library translation units
Note
Compare with the application-side OW_CONFIG_TOKEN at startup: a mismatch means the archive and the application were built with different OW flags, clock frequencies, or DS18B20_MAX_DEVICES. Fail loudly there instead of running with a silently different bus timing or table size.

◆ onewire_init()

void onewire_init ( void )

Initialize the shared 1-Wire timer/DMA/GPIO resources.

Precondition
Call after MCU reset, before any 1-Wire bus operation or slave-driver activity. Initialize the system clock first when its final frequency is not the backend default.
Note
Enables the timer/DMA/GPIO clocks, sets the timer prescaler for 1µs resolution, configures the bus pin as alternate-function open-drain and marks the search engine idle. The timer is left stopped: the first operation only starts when the application requests it.
Warning
This is a bootstrap operation, not a reinitialization hook. A second call does not stop or reset an active TIM1/DMA operation, clear stale timer/DMA/low-power state, or fully reset slave-driver state. Calling it twice before any bus operation is harmless (it re-applies the same idle configuration, which is how all three slave drivers are brought up in one image); starting a new driver lifecycle requires an MCU reset.
After initialization the 1-Wire layer exclusively owns TIM1, the DMA feed/capture pair of the active backend (DMA1 channels 3 and 4 on F0/F1/G0, DMA2 streams 2 and 4 on F4), and the bus GPIO pin including its alternate-function/remap configuration. Application code, ISRs and other drivers must not configure or use these resources while the layer is in use. The library has no deinit or release API: the ownership lasts until reset.