The stse_init() API currently performs the same initialization steps every time it is called.
At the moment, stse_init() invokes the following functions for every STSAFE device being initialized:
- stse_platform_i2c_init() or stse_platform_st1wire_init()
- stse_platform_generate_random_init()
- stse_platform_delay_init()
- stse_platform_power_init()
- stse_device_power_on()
- stse_platform_crc16_init()
- stse_platform_crypto_init()
- stsafea_perso_info_update()
However, several of these initialization steps are not device-specific. A cleaner approach would be to split the initialization process into three distinct phases: platform initialization, bus initialization, and device initialization. This could be achieved by introducing the following APIs:
-
stse_ReturnCode_t stse_init_platform(void *pArg);
This function would internally call:
- stse_platform_generate_random_init(pArg)
- stse_platform_delay_init(pArg)
- stse_platform_power_init(pArg)
- stse_platform_crc16_init(pArg)
- stse_platform_crypto_init(pArg)
-
stse_ReturnCode_t stse_init_bus(stse_io_t *io, void *pArg);
This function would initialize the communication bus by calling either:
- stse_platform_i2c_init(io->busID, pArg), or
- stse_platform_st1wire_init(io->busID, pArg)
depending on the value of io->BusType.
-
stse_ReturnCode_t stse_init_device(stse_Handle_t *pSTSE, stse_io_t *io, void *pArg);
This function would:
- associate the communication interface with the device handle by assigning pSTSE->io = io (store the pointer rather than copying the entire stse_io_t structure);
- call stse_device_power_on(pSTSE);
- call stsafea_perso_info_update(pSTSE).
Splitting the initialization into these three phases also avoids repeatedly invoking the platform and bus initialization routines every time a new device is initialized, preventing unnecessary attempts to reinitialize components that have already been initialized.
In addition, this design would allow reducing the size of stse_Handle_t. Currently, each device handle contains its own copy of stse_io_t io. Replacing this with a pointer (stse_io_t *io) would avoid duplicating the bus configuration for every device and reduce the size of stse_Handle_t by approximately 51 bytes on 32-bit platforms.
The stse_init() API currently performs the same initialization steps every time it is called.
At the moment, stse_init() invokes the following functions for every STSAFE device being initialized:
However, several of these initialization steps are not device-specific. A cleaner approach would be to split the initialization process into three distinct phases: platform initialization, bus initialization, and device initialization. This could be achieved by introducing the following APIs:
stse_ReturnCode_t stse_init_platform(void *pArg);
This function would internally call:
stse_ReturnCode_t stse_init_bus(stse_io_t *io, void *pArg);
This function would initialize the communication bus by calling either:
depending on the value of io->BusType.
stse_ReturnCode_t stse_init_device(stse_Handle_t *pSTSE, stse_io_t *io, void *pArg);
This function would:
Splitting the initialization into these three phases also avoids repeatedly invoking the platform and bus initialization routines every time a new device is initialized, preventing unnecessary attempts to reinitialize components that have already been initialized.
In addition, this design would allow reducing the size of stse_Handle_t. Currently, each device handle contains its own copy of stse_io_t io. Replacing this with a pointer (stse_io_t *io) would avoid duplicating the bus configuration for every device and reduce the size of stse_Handle_t by approximately 51 bytes on 32-bit platforms.