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.62k stars 6.5k forks source link

SMT32: incorrect internal temperature value #50152

Closed TDhaouST closed 2 years ago

TDhaouST commented 2 years ago

Describe the bug Fix the internal temperature sensor value (Die temp) incorrect when reading internal temperature from ADC.

This ticket is to fix the incorrect temperature sensor (Die temp) value in the ADC device-tree node for the stm32 series below:

Acquired values seems inconsistent and not compatible. Example for the stm32U5 (b_u585i_iot02a), here is the required configuration of the ADC and the die temp nodes:

adc1: adc@42028000 {
        compatible = "st,stm32-adc";
        reg = <0x42028000 0x400>;
        clocks = <&rcc STM32_CLOCK_BUS_AHB2 0x00000400>;
        interrupts = <37 0>;
        status = "disabled";
        vref-mv = <3300>;
        #io-channel-cells = <1>;
        has-temp-channel;
        has-vref-channel;
        has-vbat-channel;
    };

die_temp: dietemp {
    compatible = "st,stm32-temp-cal";
    ts-cal1-addr = <0x0BFA0710>;
    ts-cal2-addr = <0x0BFA0742>;
    ts-cal1-temp = <30>;
    ts-cal2-temp = <130>;
    ts-cal-vrefanalog = <3000>;
    ts-cal-resolution = <14>;
    io-channels = <&adc1 19>;
};

On running sample we get:

Booting Zephyr OS build v3.2.0-rc1-18-g687816ba42c9 STM32 Die temperature sensor test Current temperature: -173.3 �°C Current temperature: -126.2 �°C Current temperature: -128.2 �°C Current temperature: -128.8 �°C Current temperature: -128.8 �°C Current temperature: -126.9 �°C Current temperature: -126.2 �°C Current temperature: -126.5 �°C Current temperature: -126.9 �°C

To Reproduce

  1. west build -p auto -b nucleo_wl55jc samples/sensor/stm32_temp_sensor/
  2. west flash
  3. see error

Logs and console output see description

Environment (please complete the following information):

erwango commented 2 years ago

Removing STM32WL as this is a specific case. See #49897

FRASTM commented 2 years ago

Regarding the stm32F3 disco. The mcu is stm32F303VCT6 which refman is RM0316 Rev 8.0 and product spec is DS9118 Rev 14 The Temperature sensor is available on channel 16 of the ADC1 The Ref Manual gives in § 15.3.30 Temperature sensor the way to measure the die temperature with the formula Temperature (in °C) = {(V25 – V TS) / Avg_Slope} + 25 Additionnaly the Datasheet gives value for the TS characteristics in the Table 78 but also gives TS_CAL1& TS_CAL2 in Table 79. Based on the ref man formula and Table 78, the die-temp of the stm32f3_disco has

        compatible = "st,stm32-temp";
        avgslope = <43>;
        v25 = <1430>;

--> Current temperature: 57.3 °C ( raw ADC1 data is 0x79b)

On the other hand, when using the compatible = "st,stm32-temp-cal"; for the die-temp of the stm32f3_disco :

    compatible = "st,stm32-temp-cal";
    ts-cal1-addr = <0x1FFFF7B8>;
    ts-cal2-addr = <0x1FFFF7C2>;
    ts-cal1-temp = <30>;
    ts-cal2-temp = <110>;
    ts-cal-vrefanalog = <3300>;

--> Current temperature: ~32 °C ( raw ADC1 data is 0x79e)
Note that on the stm32F3disco the Vref = 3v (not 3.3V) even if calibration was done at 3.3V)