MCCI Trusted Bootloader
Simple trusted bootloader and tools for small embedded systems
mccibootloader_stm32l0_i2c_bus.c File Reference
#include "mcci_bootloader_device_i2c_bus_stm32l0.h"
#include "mcci_bootloader.h"
#include "mcci_bootloader_platform.h"
#include "mcci_bootloader_device_i2c_device_stm32l0.h"
#include "mcci_bootloader_device_internal.h"
#include "mcci_stm32l0xx.h"
#include "mcci_arm_cm0plus.h"
#include <string.h>

Go to the source code of this file.

Macros

#define MCCI_BOOTLOADER_STM32L0_I2C_TIME_OUT_MS   100
 

Enumerations

enum  McciBootloaderI2cBusStm32l0_Status_t {
  McciBootloaderI2cBusStm32l0_Status_Busy = 0 , McciBootloaderI2cBusStm32l0_Status_Done , McciBootloaderI2cBusStm32l0_Status_Stopped , McciBootloaderI2cBusStm32l0_Status_ArbitrationLost ,
  McciBootloaderI2cBusStm32l0_Status_Timeout , McciBootloaderI2cBusStm32l0_Status_BusError , McciBootloaderI2cBusStm32l0_Status_NotBusy , McciBootloaderI2cBusStm32l0_Status_NackError ,
  McciBootloaderI2cBusStm32l0_Status__MAX
}
 

Functions

static McciBootloaderDeviceI2cResult_t i2cBusAddDevice (McciBootloaderDeviceI2cBus_t *pBusAbstract, McciBootloaderDeviceI2cDevice_t *pDeviceAbstract, size_t sizeDevice, McciBootloaderDeviceI2cAddress_t i2cAddress, McciBootloaderDeviceI2cSpeed_t i2cSpeed)
 
static bool i2cBusBegin (McciBootloaderDevice_t *pDevice)
 
static bool i2cBusEnd (McciBootloaderDevice_t *pDevice)
 
static McciBootloaderDeviceI2cResult_t i2cBusRead (McciBootloaderDeviceI2cBus_t *pBus, McciBootloaderDeviceI2cDevice_t *pDevice, uint8_t *pBuffer, size_t nBuffer, size_t *pnActual)
 
static McciBootloaderDeviceI2cResult_t i2cBusWrite (McciBootloaderDeviceI2cBus_t *pBus, McciBootloaderDeviceI2cDevice_t *pDevice, const uint8_t *pBuffer, size_t nBuffer, size_t *pnActual)
 
static McciBootloaderDeviceI2cResult_t i2cDeviceRead (McciBootloaderDeviceI2cDevice_t *pI2cDevice, uint8_t *pBuffer, size_t nBuffer, size_t *pnActual)
 
static McciBootloaderDeviceI2cResult_t i2cDeviceWrite (McciBootloaderDeviceI2cDevice_t *pI2cDevice, const uint8_t *pBuffer, size_t nBuffer, size_t *pnActual)
 
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.
 
static McciBootloaderDeviceI2cResult_t status_getResult (McciBootloaderI2cBusStm32l0_Status_t status)
 

Variables

const McciBootloaderDeviceI2cBusStm32l0_Config_t gk_McciBootloaderDeviceI2cBusStm32l0_Config_I2c1
 global config for I2C1. Linker discards this if not used.
 
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 const McciBootloaderDeviceMethods_t i2cBus_deviceMethods
 
static const McciBootloaderDeviceI2cBusMethods_t i2cBus_i2cBusMethods
 
static McciBootloaderDeviceI2cBus_AddDeviceFn_t i2cBusAddDevice
 
static McciBootloaderDevice_BeginFn_t i2cBusBegin
 
static McciBootloaderDevice_EndFn_t i2cBusEnd
 
static McciBootloaderDeviceI2cBus_ReadFn_t i2cBusRead
 
static McciBootloaderDeviceI2cBus_WriteFn_t i2cBusWrite
 
static const McciBootloaderDeviceMethods_t i2cDevice_deviceMethods
 I2C device node methods.
 
static const McciBootloaderDeviceI2cDeviceMethods_t i2cDevice_i2cDeviceMethods
 I2C device accessor methods.
 
static McciBootloaderDeviceI2cDevice_ReadFn_t i2cDeviceRead
 
static McciBootloaderDeviceI2cDevice_WriteFn_t i2cDeviceWrite
 

Macro Definition Documentation

◆ MCCI_BOOTLOADER_STM32L0_I2C_TIME_OUT_MS

#define MCCI_BOOTLOADER_STM32L0_I2C_TIME_OUT_MS   100

Definition at line 40 of file mccibootloader_stm32l0_i2c_bus.c.

Enumeration Type Documentation

◆ McciBootloaderI2cBusStm32l0_Status_t

Enumerator
McciBootloaderI2cBusStm32l0_Status_Busy 
McciBootloaderI2cBusStm32l0_Status_Done 
McciBootloaderI2cBusStm32l0_Status_Stopped 
McciBootloaderI2cBusStm32l0_Status_ArbitrationLost 
McciBootloaderI2cBusStm32l0_Status_Timeout 
McciBootloaderI2cBusStm32l0_Status_BusError 
McciBootloaderI2cBusStm32l0_Status_NotBusy 
McciBootloaderI2cBusStm32l0_Status_NackError 
McciBootloaderI2cBusStm32l0_Status__MAX 

muat always be last, for error checking.

Definition at line 43 of file mccibootloader_stm32l0_i2c_bus.c.

Function Documentation

◆ i2cBusAddDevice()

static McciBootloaderDeviceI2cResult_t i2cBusAddDevice ( McciBootloaderDeviceI2cBus_t *  pBusAbstract,
McciBootloaderDeviceI2cDevice_t *  pDeviceAbstract,
size_t  sizeDevice,
McciBootloaderDeviceI2cAddress_t  i2cAddress,
McciBootloaderDeviceI2cSpeed_t  i2cSpeed 
)
static

◆ i2cBusBegin()

◆ i2cBusEnd()

static bool i2cBusEnd ( McciBootloaderDevice_t *  pDevice)
static

◆ i2cBusRead()

◆ i2cBusWrite()

◆ i2cDeviceRead()

static McciBootloaderDeviceI2cResult_t i2cDeviceRead ( McciBootloaderDeviceI2cDevice_t *  pI2cDevice,
uint8_t *  pBuffer,
size_t  nBuffer,
size_t *  pnActual 
)
static

Definition at line 785 of file mccibootloader_stm32l0_i2c_bus.c.

◆ i2cDeviceWrite()

static McciBootloaderDeviceI2cResult_t i2cDeviceWrite ( McciBootloaderDeviceI2cDevice_t *  pI2cDevice,
const uint8_t *  pBuffer,
size_t  nBuffer,
size_t *  pnActual 
)
static

Definition at line 802 of file mccibootloader_stm32l0_i2c_bus.c.

◆ McciBootloader_Stm32L0Interface_initI2cBus()

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.

Parameters
pRamForBusPointer to a block of RAM to be used for the driver instance data
sizeForBusSize of the block of RAM. The driver checks this against the required size (must be >= sizeof(McciBootloaderDeviceI2cBusStm32l0_t))
pConfigConfiguration of the I2C block; selects the controller, etc.
timingr100kValue to use in timing register for 100kHz I2C operations
timingr400kValue to use in timing register for 400kHz I2C operations, or MCCI_BOOTLOADER_STM32L0_I2C_TIMINGR_NOT_SUPPORTED
timingr1MValue to use in timing register for 1MHz I2C operations, or MCCI_BOOTLOADER_STM32L0_I2C_TIMINGR_NOT_SUPPORTED
Returns
pointer to initialized McciBootloaderDeviceI2cBus_t object.

For simplicity, the details of the pin mapping for the I2C I/O pins is left to the caller to control. Please set up the pins prior to using the bus.

This funcion does an implicit device begin on the initialized bus.

Definition at line 196 of file mccibootloader_stm32l0_i2c_bus.c.

References i2cBus_deviceMethods, i2cBus_i2cBusMethods, MCCI_BOOTLOADER_STM32L0_I2C_TIMINGR_NOT_SUPPORTED, McciBootloaderError_I2cBegin, McciBootloaderError_InternalConsistency, and McciBootloaderPlatform_fail().

Referenced by McciBootloaderBoard_Catena5230_systemInit().

◆ status_getResult()

Variable Documentation

◆ gk_McciBootloaderDeviceI2cBusStm32l0_Config_I2c1

const McciBootloaderDeviceI2cBusStm32l0_Config_t gk_McciBootloaderDeviceI2cBusStm32l0_Config_I2c1
Initial value:
=
{
.baseAddress = MCCI_STM32L0_REG_I2C1,
.CCIPR_select =
{
},
}
#define MCCI_STM32L0_REG_RCC_APB1RSTR_I2C1RST
#define MCCI_STM32L0_REG_RCC_CCIPR_I2C1SEL_HSI16
#define MCCI_STM32L0_REG_RCC_APB1ENR_I2C1EN
#define MCCI_STM32L0_REG_RCC_CCIPR_I2C1SEL
#define MCCI_STM32L0_REG_I2C1
Section 27.7.12: I2C register map (1K)

global config for I2C1. Linker discards this if not used.

Definition at line 91 of file mccibootloader_stm32l0_i2c_bus.c.

◆ gk_McciBootloaderDeviceI2cBusStm32l0_Config_I2c2

const McciBootloaderDeviceI2cBusStm32l0_Config_t gk_McciBootloaderDeviceI2cBusStm32l0_Config_I2c2
Initial value:
=
{
.baseAddress = MCCI_STM32L0_REG_I2C2,
.CCIPR_select =
{
.mask = 0,
.value = 0
},
}
#define MCCI_STM32L0_REG_RCC_APB1RSTR_I2C2RST
#define MCCI_STM32L0_REG_I2C2
Section 27.7.12: I2C register map (1K)
#define MCCI_STM32L0_REG_RCC_APB1ENR_I2C2EN

global config for I2C2. Linker discards this if not used.

Definition at line 104 of file mccibootloader_stm32l0_i2c_bus.c.

Referenced by McciBootloaderBoard_Catena5230_systemInit().

◆ gk_McciBootloaderDeviceI2cBusStm32l0_Config_I2c3

const McciBootloaderDeviceI2cBusStm32l0_Config_t gk_McciBootloaderDeviceI2cBusStm32l0_Config_I2c3
Initial value:
=
{
.baseAddress = MCCI_STM32L0_REG_I2C3,
.CCIPR_select =
{
},
}
#define MCCI_STM32L0_REG_RCC_CCIPR_I2C3SEL
#define MCCI_STM32L0_REG_RCC_APB1ENR_I2C3EN
#define MCCI_STM32L0_REG_RCC_CCIPR_I2C3SEL_HSI16
#define MCCI_STM32L0_REG_I2C3
Section 27.7.12: I2C register map (1K)
#define MCCI_STM32L0_REG_RCC_APB1RSTR_I2C3RST

global config for I2C3. Linker discards this if not used.

Definition at line 117 of file mccibootloader_stm32l0_i2c_bus.c.

◆ i2cBus_deviceMethods

const McciBootloaderDeviceMethods_t i2cBus_deviceMethods
static
Initial value:
=
{
.pBegin = i2cBusBegin,
.pEnd = i2cBusEnd
}
static McciBootloaderDevice_BeginFn_t i2cBusBegin
static McciBootloaderDevice_EndFn_t i2cBusEnd

Definition at line 77 of file mccibootloader_stm32l0_i2c_bus.c.

Referenced by McciBootloader_Stm32L0Interface_initI2cBus().

◆ i2cBus_i2cBusMethods

const McciBootloaderDeviceI2cBusMethods_t i2cBus_i2cBusMethods
static
Initial value:
=
{
.pAddDevice = i2cBusAddDevice,
.pRead = i2cBusRead,
.pWrite = i2cBusWrite
}
static McciBootloaderDeviceI2cBus_WriteFn_t i2cBusWrite
static McciBootloaderDeviceI2cBus_ReadFn_t i2cBusRead
static McciBootloaderDeviceI2cBus_AddDeviceFn_t i2cBusAddDevice

Definition at line 83 of file mccibootloader_stm32l0_i2c_bus.c.

Referenced by McciBootloader_Stm32L0Interface_initI2cBus().

◆ i2cBusAddDevice

McciBootloaderDeviceI2cBus_AddDeviceFn_t i2cBusAddDevice
static

Definition at line 58 of file mccibootloader_stm32l0_i2c_bus.c.

◆ i2cBusBegin

McciBootloaderDevice_BeginFn_t i2cBusBegin
static

Definition at line 56 of file mccibootloader_stm32l0_i2c_bus.c.

◆ i2cBusEnd

McciBootloaderDevice_EndFn_t i2cBusEnd
static

Definition at line 57 of file mccibootloader_stm32l0_i2c_bus.c.

◆ i2cBusRead

McciBootloaderDeviceI2cBus_ReadFn_t i2cBusRead
static

Definition at line 59 of file mccibootloader_stm32l0_i2c_bus.c.

◆ i2cBusWrite

McciBootloaderDeviceI2cBus_WriteFn_t i2cBusWrite
static

Definition at line 60 of file mccibootloader_stm32l0_i2c_bus.c.

◆ i2cDevice_deviceMethods

const McciBootloaderDeviceMethods_t i2cDevice_deviceMethods
static
Initial value:
=
{
.pBegin = NULL,
.pEnd = NULL
}

I2C device node methods.

I2C device nodes are the equivalent of Windows PDOs; they are drivers, but they exist to export device-specific functionality from the parent bus driver to the function driver that uses the specific I2C device. Thus, we can null out the method functions as the framework behavior is sufficient.

Definition at line 137 of file mccibootloader_stm32l0_i2c_bus.c.

Referenced by i2cBusAddDevice().

◆ i2cDevice_i2cDeviceMethods

const McciBootloaderDeviceI2cDeviceMethods_t i2cDevice_i2cDeviceMethods
static
Initial value:
=
{
.pRead = i2cDeviceRead,
.pWrite = i2cDeviceWrite
}
static McciBootloaderDeviceI2cDevice_ReadFn_t i2cDeviceRead
static McciBootloaderDeviceI2cDevice_WriteFn_t i2cDeviceWrite

I2C device accessor methods.

Definition at line 144 of file mccibootloader_stm32l0_i2c_bus.c.

Referenced by i2cBusAddDevice().

◆ i2cDeviceRead

McciBootloaderDeviceI2cDevice_ReadFn_t i2cDeviceRead
static

Definition at line 62 of file mccibootloader_stm32l0_i2c_bus.c.

◆ i2cDeviceWrite

McciBootloaderDeviceI2cDevice_WriteFn_t i2cDeviceWrite
static

Definition at line 63 of file mccibootloader_stm32l0_i2c_bus.c.