lis2mdl magnetometer in microbit v2 #i2c #driver #lis2dw12


Frank Duignan
 

I have been experimenting with the microbit v2 and zephyr.  Everything seems to work ok except for the magnetometer.  The values it produces do not change when you re-orient the device.  If you re-orient the device and power cycle it you will see a new set of values which will remain unchanged until the next power cycle. My build version is zephyr-v2.6.0-535-gbd09d4ff3f81
The accelerometer, bluetooth and digital i/o all work fine.
While wandering through the code and experimenting with various configuration options I came across an error in lis2mdl.c on line 453:
const struct lis2mdl_config *cfg = dev->config;
There is no 'dev' parameter passed to this function however there is a "config" parameter and this modification works:
const struct lis2mdl_config *cfg = config;// dev->config;
 


Bolivar, Marti
 

Hi,

+Armando

"frank.duignan via lists.zephyrproject.org"
<frank.duignan=gmail.com@lists.zephyrproject.org> writes:

I have been experimenting with the microbit v2 and zephyr.  Everything seems to work ok except for the magnetometer.  The values it produces do not change when you re-orient the device.  If you re-orient the device and power cycle it you will see a new set of values which will remain unchanged until the next power cycle. My build version is zephyr-v2.6.0-535-gbd09d4ff3f81
The accelerometer, bluetooth and digital i/o all work fine.
While wandering through the code and experimenting with various configuration options I came across an error in lis2mdl.c on line 453:
const struct lis2mdl_config *cfg = dev->config;
There is no 'dev' parameter passed to this function however there is a "config" parameter and this modification works:
const struct lis2mdl_config *cfg = config;// dev->config;
Did you send a pull request with the fix? If not, please do. Although
I'm confused about how this builds with no 'dev' in scope.

Martí




Armando VISCONTI <armando.visconti@...>
 

Hi Marti,

On 7/14/21 9:15 PM, Bolivar, Marti wrote:
Hi,
+Armando
"frank.duignan via lists.zephyrproject.org"
<frank.duignan=gmail.com@lists.zephyrproject.org> writes:

I have been experimenting with the microbit v2 and zephyr.  Everything seems to work ok except for the magnetometer.  The values it produces do not change when you re-orient the device.  If you re-orient the device and power cycle it you will see a new set of values which will remain unchanged until the next power cycle. My build version is zephyr-v2.6.0-535-gbd09d4ff3f81
The accelerometer, bluetooth and digital i/o all work fine.
While wandering through the code and experimenting with various configuration options I came across an error in lis2mdl.c on line 453:
const struct lis2mdl_config *cfg = dev->config;
There is no 'dev' parameter passed to this function however there is a "config" parameter and this modification works:
const struct lis2mdl_config *cfg = config;// dev->config;
Did you send a pull request with the fix? If not, please do. Although
I'm confused about how this builds with no 'dev' in scope.
I confirm that, in case CONFIG_PM_DEVICE is enabled, the driver does not
build correctly.
I just created a pull request with the fix (#36975) as suggested by
Frank.

Having said that, I doubt this PR will fix the original issue of the
reporter ("The values it produces do not change when you re-orient the
device"), as the lis2mdl pm_control init routine was never called (in
the PR I fixed also this).

I suggest to open a specific bug for it and I'll look into it.
Thanks for reporting this build bug!

Armando


William Fish
 
Edited

I've had a quick look and am confused as there is reference to a file:
#include "lis2mdl_reg.h"

It appears that when this driver was created they may have forgotten to include both lis2mdl_reg.c and lis2mdl_reg.h, eg like these:
https://os.mbed.com/teams/ST/code/LIS2MDL//file/8562ae1a0534/lis2mdl_reg.c/https://github.com/tencentyun/qcloud-iot-c-sdk-porting-examples/blob/master/Tencent_icube_based_Nucleol476_FreeRTOS/Drivers/BSP/Components/lis2mdl/lis2mdl_reg.c

Billy..