Skip to content

Commit 4c69ced

Browse files
committed
drivers: sensor: adxl345: Fix odr update bus fault
The adxl345 accelerometer driver needs to store the current output data rate (odr) for later use in streaming mode, but the value was incorrectly placed in the constant configuration structure (located in flash) and updating it caused a bus fault. Rework odr update handling to place the current value in RAM instead. The initial value from devicetree is still stored in flash. Signed-off-by: Maureen Helm <[email protected]>
1 parent 4708389 commit 4c69ced

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

drivers/sensor/adi/adxl345/adxl345.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ static int adxl345_attr_set_odr(const struct device *dev,
229229
const struct sensor_value *val)
230230
{
231231
enum adxl345_odr odr;
232-
struct adxl345_dev_config *cfg = (struct adxl345_dev_config *)dev->config;
232+
struct adxl345_dev_data *data = dev->data;
233233

234234
switch (val->val1) {
235235
case 12:
@@ -257,7 +257,7 @@ static int adxl345_attr_set_odr(const struct device *dev,
257257
int ret = adxl345_set_odr(dev, odr);
258258

259259
if (ret == 0) {
260-
cfg->odr = odr;
260+
data->odr = odr;
261261
}
262262

263263
return ret;
@@ -435,9 +435,7 @@ static int adxl345_init(const struct device *dev)
435435
{
436436
int rc;
437437
struct adxl345_dev_data *data = dev->data;
438-
#ifdef CONFIG_ADXL345_TRIGGER
439438
const struct adxl345_dev_config *cfg = dev->config;
440-
#endif
441439
uint8_t dev_id, full_res;
442440

443441
data->sample_number = 0;
@@ -488,17 +486,18 @@ static int adxl345_init(const struct device *dev)
488486
return -EIO;
489487
}
490488

489+
rc = adxl345_set_odr(dev, cfg->odr);
490+
if (rc) {
491+
return rc;
492+
}
493+
491494
#ifdef CONFIG_ADXL345_TRIGGER
492495
rc = adxl345_init_interrupt(dev);
493496
if (rc < 0) {
494497
LOG_ERR("Failed to initialize interrupt!");
495498
return -EIO;
496499
}
497500

498-
rc = adxl345_set_odr(dev, cfg->odr);
499-
if (rc) {
500-
return rc;
501-
}
502501
rc = adxl345_interrupt_config(dev, ADXL345_INT_MAP_WATERMARK_MSK);
503502
if (rc) {
504503
return rc;

drivers/sensor/adi/adxl345/adxl345.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ struct adxl345_dev_data {
153153
struct adxl345_fifo_config fifo_config;
154154
uint8_t is_full_res;
155155
uint8_t selected_range;
156+
enum adxl345_odr odr;
156157
#ifdef CONFIG_ADXL345_TRIGGER
157158
struct gpio_callback gpio_cb;
158159

drivers/sensor/adi/adxl345/adxl345_stream.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ static void adxl345_process_fifo_samples_cb(struct rtio *r, const struct rtio_sq
159159
hdr->int_status = data->status1;
160160
hdr->is_full_res = data->is_full_res;
161161
hdr->selected_range = data->selected_range;
162-
hdr->accel_odr = cfg->odr;
162+
hdr->accel_odr = data->odr;
163163
hdr->sample_set_size = sample_set_size;
164164

165165
uint32_t buf_avail = buf_len;

0 commit comments

Comments
 (0)