zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.61k stars 6.5k forks source link

SAM0: Inability to configure ADC for internal temperature sensor #74691

Closed toshbi4 closed 1 month ago

toshbi4 commented 3 months ago

Describe the bug

Controller: SamL21 (samr34j18b)

Problem: Following this condition in SAM0 ADC driver (https://github.com/zephyrproject-rtos/zephyr/blob/main/drivers/adc/adc_sam0.c#L462) we can initialize ADC driver only with the corresponding controller's pins. However, internal ADC temperature measurement in SUPC isn't provided with any controller's pins. Hence, we can't use this ADC driver for reading ADC values with internal temperature measurements.

Testing: A simple and direct solution - to comment out this condition (pinctrl checking) - made a success, so it means that it is redundant for this particular case...

Expected behavior

It seems that the structure of ADC driver should be made in such a way, that we can optionally check providing of pinctrl structure. For example, we can check for specific channels, where there is no need in any pins for adc.

Impact

Without dealing with this problem I can't implement temperature measurement in a device, what is critical feature for functionality.

Environment (please complete the following information):

Additional context

Link to SAM documentation about internal temperature sensor (page 947, "Device Temperature Measurement"): https://ww1.microchip.com/downloads/en/DeviceDoc/SAM_L21_Family_DataSheet_DS60001477C.pdf

github-actions[bot] commented 3 months ago

Hi @toshbi4! We appreciate you submitting your first issue for our open-source project. 🌟

Even though I'm a bot, I can assure you that the whole community is genuinely grateful for your time and effort. 🤖💙

guenzel-kinexon commented 1 month ago

You should be able to achieve what you want with a channel definition and setting the input-positive property to the correct (internal) channel, don't you?

&adc {
// ....
channel@0 {
        reg = <0>;
        zephyr,gain = "ADC_GAIN_1";
        zephyr,reference = "ADC_REF_INTERNAL";
        zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
        zephyr,resolution = <12>;
        zephyr,input-positive = <0x18>;
    };
};
toshbi4 commented 1 month ago

You should be able to achieve what you want with a channel definition and setting the input-positive property to the correct (internal) channel, don't you?

&adc {
// ....
channel@0 {
      reg = <0>;
      zephyr,gain = "ADC_GAIN_1";
      zephyr,reference = "ADC_REF_INTERNAL";
      zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
      zephyr,resolution = <12>;
      zephyr,input-positive = <0x18>;
  };
};

Thank you for your answer! This didn't help, unfortunately

But I dealt with this in another way: To avoid triggering this condition you can just create empty pinctrl definition. For example:

pinctrl.dtsi

adc_pins_default: adc_pins_default {
    };

overlay.dts

&adc {
    label = "ADC_TEMP";
    status = "okay";
    pinctrl-0 = <&adc_pins_default>;
    pinctrl-names = "default";
};