Quadrature Decoder Failing to build on NCS v2.1

Hello,

When enabling the Sensor system and having a qdec device enabled in my dts I get the following error:

/home/ee/ncs/zephyr/drivers/sensor/qdec_nrfx/qdec_nrfx.c:98:21: error: expression in static assertion is not constant
   98 |  BUILD_ASSERT(steps > 0, "only positive number valid");
      |               ~~~~~~^~~
/home/ee/ncs/zephyr/drivers/sensor/qdec_nrfx/qdec_nrfx.c:99:21: error: expression in static assertion is not constant
   99 |  BUILD_ASSERT(steps <= 2048, "overflow possible");
      |               ~~~~~~^~~~~~~

This seems to be a bug with the Zephyr code checking a const local var at compile time. Has anyone else had this issue?

Best,

Archie

Parents Reply Children
  • It has been configured as shown below:

    &qdec0{
    	compatible = "nordic,nrf-qdec";
    	status = "okay";
    	led-pre = <0>;
    	steps = <12>;
    
    	pinctrl-0 = <&qdec0_default>;
    	pinctrl-1 = <&qdec0_sleep>;
    	pinctrl-names = "default", "sleep";	
    };


    It seems to be the qdec code that is wrong as it's saying the expression isn't constant.

    Modifying the code to this:

    static int qdec_nrfx_channel_get(const struct device *dev,
    				 enum sensor_channel  chan,
    				 struct sensor_value *val)
    {
    	struct qdec_nrfx_data *data = &qdec_nrfx_data;
    	unsigned int key;
    	int32_t acc;
    	const int32_t steps = DT_INST_PROP(0, steps);
    
    	ARG_UNUSED(dev);
    	LOG_DBG("");
    
    	if (chan != SENSOR_CHAN_ROTATION) {
    		return -ENOTSUP;
    	}
    
    	key = irq_lock();
    	acc = data->acc;
    	data->acc = 0;
    	irq_unlock(key);
    
    	BUILD_ASSERT(DT_INST_PROP(0, steps) > 0, "only positive number valid");
    	BUILD_ASSERT(DT_INST_PROP(0, steps) <= 2048, "overflow possible");
    
    	val->val1 = (acc * FULL_ANGLE) / steps;
    	val->val2 = (acc * FULL_ANGLE) - (val->val1 * steps);
    	if (val->val2 != 0) {
    		val->val2 *= 1000000;
    		val->val2 /= steps;
    	}
    
    	return 0;
    }

    Fixes the error as now the value is a compile-time constant.

  • Hi,

    I'm not able to reproduce this error. I tried adding QDEC to a simple example, but there are no build errors.

    The QDEC is also used in our nrf_desktop mouse application, so it should have been tested and builds with our tests.

    Can you upload a simple application that we can use to reproduce this error?

    Best regards,
    Jørgen

  • Hi Jørgen

    It seems to be an issue when enabling CPLUSPLUS. Could you add `CONFIG_CPLUSPLUS=y` to your proj.conf in your test up and see if it errors? 

    Edit: Actually it seems to be the `CONFIG_NO_OPTIMIZATIONS=y` option.

    Also, how do I report an issue with the DevZone website? I have noticed that the "Reply", "Verify Answer" and "More" buttons do not appear next to posts unless I interact with those buttons on a post a level above the one I want to interact with. I can provide a video if that helps. 


    Thanks,

    Archie

  • Hi,

    I was able to reproduce the issue with `CONFIG_NO_OPTIMIZATIONS=y` config set. I have reported it internally.

    We do not have any other methods to report DevZone issues than creating a ticket. We are aware of the issues you have seen, F5 usually helps with showing the buttons.

    Best regards,
    Jørgen

Related