Skip to content

Add sensor firmware upload API support #93340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions drivers/sensor/sensor_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ static inline int z_vrfy_sensor_get_decoder(const struct device *dev,
}
#include <zephyr/syscalls/sensor_get_decoder_mrsh.c>

static inline int z_vrfy_sensor_upload_fw(const struct device *dev,
const void *fw_buf, size_t fw_len)
{
K_OOPS(K_SYSCALL_OBJ(dev, K_OBJ_DRIVER_SENSOR));
K_OOPS(K_SYSCALL_MEMORY_READ(fw_buf, fw_len));
return z_impl_sensor_upload_fw(dev, fw_buf, fw_len);
}
#include <zephyr/syscalls/sensor_upload_fw_mrsh.c>

static inline int z_vrfy_sensor_reconfigure_read_iodev(struct rtio_iodev *iodev,
const struct device *sensor,
const struct sensor_chan_spec *channels,
Expand Down
4 changes: 4 additions & 0 deletions drivers/sensor/st/lsm6dso16is/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ menuconfig LSM6DSO16IS

if LSM6DSO16IS

config LSM6DSO16IS_ISPU_ENABLE
bool "ISPU Enable"
select USE_ST_MEMS_ISPU

choice LSM6DSO16IS_TRIGGER_MODE
prompt "Trigger mode"
help
Expand Down
26 changes: 26 additions & 0 deletions drivers/sensor/st/lsm6dso16is/lsm6dso16is.c
Original file line number Diff line number Diff line change
Expand Up @@ -710,13 +710,39 @@
return 0;
}

static int lsm6dso16is_upload_ispu(const struct device *dev,
const void *fw_buf,
size_t fw_len)
{
const struct lsm6dso16is_config *cfg = dev->config;
stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx;
const struct mems_conf_op *bufp = (const struct mems_conf_op *)fw_buf;
int i;

/* Load ISPU configuration */
for ( i = 0; i < fw_len; i++ ) {

Check failure on line 723 in drivers/sensor/st/lsm6dso16is/lsm6dso16is.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

SPACING

drivers/sensor/st/lsm6dso16is/lsm6dso16is.c:723 space prohibited before that close parenthesis ')'

Check failure on line 723 in drivers/sensor/st/lsm6dso16is/lsm6dso16is.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

SPACING

drivers/sensor/st/lsm6dso16is/lsm6dso16is.c:723 space prohibited after that open parenthesis '('
switch(bufp[i].type) {

Check failure on line 724 in drivers/sensor/st/lsm6dso16is/lsm6dso16is.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

SPACING

drivers/sensor/st/lsm6dso16is/lsm6dso16is.c:724 space required before the open parenthesis '('
case MEMS_CONF_OP_TYPE_DELAY:
k_msleep(bufp[i].data);
break;

case MEMS_CONF_OP_TYPE_WRITE:
ctx->write_reg(ctx->handle, bufp[i].address, (uint8_t *)&bufp[i].data, 1);
break;
}
}

return 0;
}

static DEVICE_API(sensor, lsm6dso16is_driver_api) = {
.attr_set = lsm6dso16is_attr_set,
#if CONFIG_LSM6DSO16IS_TRIGGER
.trigger_set = lsm6dso16is_trigger_set,
#endif
.sample_fetch = lsm6dso16is_sample_fetch,
.channel_get = lsm6dso16is_channel_get,
.upload_fw = lsm6dso16is_upload_ispu,
};

static int lsm6dso16is_init_chip(const struct device *dev)
Expand Down
1 change: 1 addition & 0 deletions drivers/sensor/st/lsm6dso16is/lsm6dso16is.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <zephyr/sys/util.h>
#include <stmemsc.h>
#include "lsm6dso16is_reg.h"
#include "mems_conf_shared_types.h"

#if DT_ANY_INST_ON_BUS_STATUS_OKAY(spi)
#include <zephyr/drivers/spi.h>
Expand Down
30 changes: 30 additions & 0 deletions include/zephyr/drivers/sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,9 @@ struct sensor_read_config {
/* Used to submit an RTIO sqe to the sensor's iodev */
typedef void (*sensor_submit_t)(const struct device *sensor, struct rtio_iodev_sqe *sqe);

/* Used to provide a driver specific callback to upload a f/w in the sensor */
typedef int (*sensor_upload_fw_t)(const struct device *dev, const void *fw_buf, size_t fw_len);

/* The default decoder API */
extern const struct sensor_decoder_api __sensor_default_decoder;

Expand All @@ -719,6 +722,7 @@ __subsystem struct sensor_driver_api {
sensor_channel_get_t channel_get;
sensor_get_decoder_t get_decoder;
sensor_submit_t submit;
sensor_upload_fw_t upload_fw;
};

/**
Expand Down Expand Up @@ -1004,6 +1008,32 @@ static inline int z_impl_sensor_get_decoder(const struct device *dev,
return api->get_decoder(dev, decoder);
}

/**
* @brief Upload a Firmware to the sensor
*
* @param[in] dev The sensor device
* @param[in] fw_buf Pointer to the Firmware buffer
* @param[in] fw_len Length of Firmware
* @return 0 on success
* @return < 0 on error
*/
__syscall int sensor_upload_fw(const struct device *dev,
const void *fw_buf, size_t fw_len);

static inline int z_impl_sensor_upload_fw(const struct device *dev,
const void *fw_buf, size_t fw_len)
{
const struct sensor_driver_api *api = (const struct sensor_driver_api *)dev->api;

__ASSERT_NO_MSG(api != NULL);

if (api->upload_fw == NULL) {
return -ENOSYS;
}

return api->upload_fw(dev, fw_buf, fw_len);
}

/**
* @brief Reconfigure a reading iodev
*
Expand Down
3 changes: 3 additions & 0 deletions modules/hal_st/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,6 @@ config USE_STDC_STTS751
bool

endif # HAS_STMEMSC

config USE_ST_MEMS_ISPU
bool
1 change: 1 addition & 0 deletions samples/shields/x_nucleo_iks4a1/standard/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CONFIG_LIS2MDL_TRIGGER_OWN_THREAD=y
CONFIG_LPS2XDF_TRIGGER_OWN_THREAD=y
CONFIG_LSM6DSO16IS_TRIGGER_NONE=y
CONFIG_LSM6DSO16IS_ENABLE_TEMP=y
CONFIG_LSM6DSO16IS_ISPU_ENABLE=y
CONFIG_LSM6DSV16X_TRIGGER_OWN_THREAD=y
CONFIG_LSM6DSV16X_ENABLE_TEMP=y
CONFIG_LIS2DUX12_TRIGGER_OWN_THREAD=y
Expand Down
9 changes: 9 additions & 0 deletions samples/shields/x_nucleo_iks4a1/standard/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,19 @@ static void lis2mdl_config(const struct device *lis2mdl)
#endif
}

#include "norm.h"

static void lsm6dso16is_config(const struct device *lsm6dso16is)
{
struct sensor_value odr_attr, fs_attr, mode_attr;

/* upload norm ISPU example */
if (sensor_upload_fw(lsm6dso16is, ispu_conf_conf_0,
(sizeof(ispu_conf_conf_0) / sizeof(struct mems_conf_op))) < 0) {
printk("Cannot upload ISPU\n");
return;
}

mode_attr.val1 = 0; /* HP */

if (sensor_attr_set(lsm6dso16is, SENSOR_CHAN_ACCEL_XYZ,
Expand Down
3 changes: 2 additions & 1 deletion west.yml
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,9 @@ manifest:
groups:
- hal
- name: hal_st
revision: 9f81b4427e955885398805b7bca0da3a8cd9109c
revision: pull/26/head
path: modules/hal/st
submodules: true
groups:
- hal
- name: hal_stm32
Expand Down
Loading