MCCI Trusted Bootloader
Simple trusted bootloader and tools for small embedded systems
mcci_bootloader_device_i2c_bus_stm32l0.h
Go to the documentation of this file.
1/*
2
3Module: mcci_bootloader_device_i2c_bus_stm32l0.h
4
5Function:
6 MccBootloaderDeviceI2cBusStm32l0_t
7
8Copyright and License:
9 This file copyright (C) 2026 by
10
11 MCCI Corporation
12 3520 Krums Corners Road
13 Ithaca, NY 14850
14
15 See accompanying LICENSE file for copyright and license information.
16
17Author:
18 Terry Moore, MCCI Corporation May 2026
19
20*/
21
22#ifndef _mcci_bootloader_device_i2c_bus_stm32l0_h_
23#define _mcci_bootloader_device_i2c_bus_stm32l0_h_ /* prevent multiple includes */
24
25#pragma once
26
27#ifndef _mcci_bootloader_device_i2c_bus_stm32l0_types_h_
29#endif
30
31#ifndef _mcci_bootloader_device_i2c_device_stm32l0_types_h_
33#endif
34
35#ifndef _mcci_bootloader_device_i2c_bus_h_
36# include "mcci_bootloader_device_i2c_bus.h"
37#endif
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
44 {
45 /// @brief base address of this channel.
46 uint32_t baseAddress; ///< base address of this i2c block.
47
48 /// values for RCC_CCIPR control for this I2C block
49 struct
50 {
51 uint32_t mask; ///< mask of affected bits. zero means "not applicable for this block".
52 uint32_t value; ///< value to write to RCC_CCIPR in masked field.
54
55 uint32_t APB1ENR_mask; ///< bit mask of block-related bit in register MCCI_STM32L0_REG_RCC_APB1ENR
56 uint32_t APB1RSTR_mask; ///< bit mask of block-related bit in register MCCI_STM32L0_REG_RCC_APB1RSTR
57 };
58
60 {
62
63 /// pointer to I2C channel-specific bit masks
64 const McciBootloaderDeviceI2cBusStm32l0_Config_t *pConfig;
65 uint32_t timingr[McciBootloaderDeviceI2cSpeed__MAX]; ///< timing register value to use for each speed
66 };
67
69 {
71 McciBootloaderDeviceI2cBusStm32l0_Contents_t Stm32l0;
72 };
73
74///
75/// @brief Initialize an I2C bus controller driver on an STM32L0
76///
77/// @param pRamForBus Pointer to a block of RAM to be used for the driver instance data
78/// @param sizeForBus Size of the block of RAM. The driver checks this against the required size
79/// (must be >= sizeof(McciBootloaderDeviceI2cBusStm32l0_t))
80/// @param pConfig Configuration of the I2C block; selects the controller, etc.
81/// @param timingr100k Value to use in timing register for 100kHz I2C operations
82/// @param timingr400k Value to use in timing register for 400kHz I2C operations,
83/// or MCCI_BOOTLOADER_STM32L0_I2C_TIMINGR_NOT_SUPPORTED
84/// @param timingr1M Value to use in timing register for 1MHz I2C operations,
85/// or MCCI_BOOTLOADER_STM32L0_I2C_TIMINGR_NOT_SUPPORTED
86///
87/// @return pointer to initialized McciBootloaderDeviceI2cBus_t object.
88///
89/// @details
90/// For simplicity, the details of the pin mapping for the I2C I/O pins is left
91/// to the caller to control. Please set up the pins prior to using the bus.
92///
93/// This funcion does an implicit device begin on the initialized bus.
94///
95McciBootloaderDeviceI2cBus_t *
97 void *pRamForBus,
98 size_t sizeForBus,
99 const McciBootloaderDeviceI2cBusStm32l0_Config_t *pConfig,
100 uint32_t timingr100k,
101 uint32_t timingr400k,
102 uint32_t timingr1M
103 );
104
105/// value to use for timing parameters when a speed is not supported.
106#define MCCI_BOOTLOADER_STM32L0_I2C_TIMINGR_NOT_SUPPORTED UINT32_C(0xFFFFFFFF)
107
108///
109/// value for 100k ("standard mode")
110///
111/// @details
112///
113/// |----------|-----------|-------------------------------|----------|
114/// | Field | Value | Time | Comments |
115/// |----------|-----------|-------------------------------|----------|
116/// | `PRESC` | 3 | t_PRESC = 4 × 31.25 = 125 ns | free choice, keeps counts in 8 bits |
117/// | `SCLL` | 39 (0x27) | 40 x 125 = 5000 ns | >= t_LOW min, 4.7 us |
118/// | `SCLH` | 39 (0x27) | 40 x 125 = 5000 ns | >= t_HIGH min, 4.0 us |
119/// | `SDADEL` | 2 | 2 x 125 = 250 ns | >= ~156 ns (fall time - filter - 3*t_I2CCLK); <= 3.45 us max
120/// | `SCLDEL` | 9 | 10 x 125 = 1250 ns | >= t_r + t_SU DAT = 1000+ 250 |
121///
122/// Actual is about 95 kHz
123///
124#define MCCI_BOOTLOADER_STM32L0_I2C_TIMINGR_100K UINT32_C(0x30922727)
125
126///
127/// value for 400k ("fast mode")
128///
129/// @details
130///
131/// |----------|-----------|-------------------------------|----------|
132/// | Field | Value | Time | Comments |
133/// |----------|-----------|-------------------------------|----------|
134/// | `PRESC` | 1 | t_PRESC = 2 × 31.25 = 62.5 ns | free choice |
135/// | `SCLL` | 20 (0x14) | 21 x 62.5 = 1312.5 ns | >= t_LOW min, 1.3 us |
136/// | `SCLH` | 14 (0x0E) | 15 x 62.5 = 937.5 ns | >= t_HIGH min, 0.6 us |
137/// | `SDADEL` | 4 | 4 x 62.5 = 250 ns | >= ~156 ns, <= 0.9 us |
138/// | `SCLDEL` | 6 | 7 x 62.5 = 437.5 ns | >= t_r + t_SU DAT = 400 ns |
139///
140/// Actual is approximately 388 kHz
141///
142#define MCCI_BOOTLOADER_STM32L0_I2C_TIMINGR_400K UINT32_C(0x10640e14)
143
144///
145/// value for 1M ("fast mode plus")
146///
147/// @details
148///
149/// |----------|-----------|-------------------------------|----------|
150/// | Field | Value | Time | Comments |
151/// |----------|-----------|-------------------------------|----------|
152/// | `PRESC` | 0 | t_PRESC = 1 × 31.25 = 31.25 ns | free choice |
153/// | `SCLL` | 15 (0x0F) | 16 x 31.25 = 500 ns | >= t_LOW min, 0.5 us |
154/// | `SCLH` | 9 | 10 x 31.25 = 312.5 ns | >= t_HIGH min, 0.26 us |
155/// | `SDADEL` | 0 | 0 ns | fast edges + analog filter cover hold time |
156/// | `SCLDEL` | 5 | 6 x 31.25 = 187.5 ns | >= t_r + t_SU DAT = 170 ns |
157///
158/// Actual is approximately 965 kHz
159///
160#define MCCI_BOOTLOADER_STM32L0_I2C_TIMINGR_1M UINT32_C(0x0050090F)
161
162extern const McciBootloaderDeviceI2cBusStm32l0_Config_t gk_McciBootloaderDeviceI2cBusStm32l0_Config_I2c1;
163extern const McciBootloaderDeviceI2cBusStm32l0_Config_t gk_McciBootloaderDeviceI2cBusStm32l0_Config_I2c2;
164extern const McciBootloaderDeviceI2cBusStm32l0_Config_t gk_McciBootloaderDeviceI2cBusStm32l0_Config_I2c3;
165
166///
167/// @brief upcast from device to enclosing McciBootloaderDeviceI2cBusStm32l0_t
168/// @param pDevice Pointer to device
169/// @return pointer to enclosing object
170///
171/// @note
172/// This is only safe to call when you know that the device is part of
173/// a STM32L0 I2C Bus Controller driver instance.
174///
175static inline
176McciBootloaderDeviceI2cBusStm32l0_t *
178 McciBootloaderDevice_t *pDevice
179 )
180 {
181 return (McciBootloaderDeviceI2cBusStm32l0_t *)pDevice;
182 }
183
184///
185/// @brief upcast from i2c controller device to enclosing McciBootloaderDeviceI2cBusStm32l0_t
186/// @param pDevice Pointer to i2c controller device
187/// @return pointer to enclosing object
188///
189/// @note
190/// This is only safe to call when you know that the device is part of
191/// a STM32L0 I2C Bus Controller driver instance.
192///
193static inline
194McciBootloaderDeviceI2cBusStm32l0_t *
196 McciBootloaderDeviceI2cBus_t *pDevice
197 )
198 {
199 return (McciBootloaderDeviceI2cBusStm32l0_t *)pDevice;
200 }
201
202#ifdef __cplusplus
203}
204#endif
205
206#endif /* _mcci_bootloader_device_i2c_bus_stm32l0_h_ */
const McciBootloaderDeviceI2cBusStm32l0_Config_t gk_McciBootloaderDeviceI2cBusStm32l0_Config_I2c2
global config for I2C2. Linker discards this if not used.
const McciBootloaderDeviceI2cBusStm32l0_Config_t gk_McciBootloaderDeviceI2cBusStm32l0_Config_I2c3
global config for I2C3. Linker discards this if not used.
static McciBootloaderDeviceI2cBusStm32l0_t * McciBootloaderDeviceI2cBus_getI2cBusStm32l0(McciBootloaderDeviceI2cBus_t *pDevice)
upcast from i2c controller device to enclosing McciBootloaderDeviceI2cBusStm32l0_t
static McciBootloaderDeviceI2cBusStm32l0_t * McciBootloaderDevice_getI2cBusStm32l0(McciBootloaderDevice_t *pDevice)
upcast from device to enclosing McciBootloaderDeviceI2cBusStm32l0_t
McciBootloaderDeviceI2cBus_t * McciBootloader_Stm32L0Interface_initI2cBus(void *pRamForBus, size_t sizeForBus, const McciBootloaderDeviceI2cBusStm32l0_Config_t *pConfig, uint32_t timingr100k, uint32_t timingr400k, uint32_t timingr1M)
Initialize an I2C bus controller driver on an STM32L0.
const McciBootloaderDeviceI2cBusStm32l0_Config_t gk_McciBootloaderDeviceI2cBusStm32l0_Config_I2c1
global config for I2C1. Linker discards this if not used.
const McciBootloaderDeviceI2cBusStm32l0_Config_t * pConfig
pointer to I2C channel-specific bit masks
uint32_t timingr[McciBootloaderDeviceI2cSpeed__MAX]
timing register value to use for each speed
struct McciBootloaderDeviceI2cBusStm32l0_Masks_s::@0 CCIPR_select
values for RCC_CCIPR control for this I2C block
uint32_t value
value to write to RCC_CCIPR in masked field.
uint32_t mask
mask of affected bits. zero means "not applicable for this block".
uint32_t APB1RSTR_mask
bit mask of block-related bit in register MCCI_STM32L0_REG_RCC_APB1RSTR
uint32_t APB1ENR_mask
bit mask of block-related bit in register MCCI_STM32L0_REG_RCC_APB1ENR
McciBootloaderDeviceI2cBusStm32l0_Contents_t Stm32l0