lm-sensors in embedded systems: from schematics to management from linux

24
Павел Курочкин General R&D, 2017 lm-sensors в embedded От схемотехники до управления в linux LM -- Linux Monitoring

Transcript of lm-sensors in embedded systems: from schematics to management from linux

Page 1: lm-sensors in embedded systems: from schematics to management from linux

Павел Курочкин General R&D, 2017

lm-sensors в embeddedОт схемотехники до управления в linux

LM -- Linux Monitoring

Page 2: lm-sensors in embedded systems: from schematics to management from linux

Павел Курочкин General R&D, 2017

О чём пойдёт речь?● Какую проблему решаем● Схема, архитектура● Чип сенсора в device-tree● Детектим чип сенсора в linux● hwmon userspace-интерфейс● Конфигурируем sensors● Конфигурируем управление вентиляторами● Демо на живом устройстве

2

Page 3: lm-sensors in embedded systems: from schematics to management from linux

Павел Курочкин General R&D, 2017

Какую задачу решаем?● Мониторинг напряжений на плате (3.3 В, 2.5 В, 5 В) ● Мониторинг напряжений БП (12 В)● Мониторинг температуры (процессор, БП, среднее)● Автоматическое управление вентиляторами

Нужен контроль подсистемы из linux!

3

Page 4: lm-sensors in embedded systems: from schematics to management from linux

Павел Курочкин General R&D, 2017

Блок-схема устройства

4

Page 5: lm-sensors in embedded systems: from schematics to management from linux

Павел Курочкин General R&D, 2017

Компоненты схемы● adt7463 -- аналог National lm85● ads7830 -- многоканальный АЦП● Температурные сенсоры: 2N3906 и NTC-термистор● AC/DC -- адаптер ~220V в 12V● Power supply -- источники питания

5

Page 6: lm-sensors in embedded systems: from schematics to management from linux

Павел Курочкин General R&D, 2017

adt7463Схемотехника:

● Мониторинг напряжений и температуры● Автономное управление вентиляторами● https://www.onsemi.com/pub/Collateral/ADT7463-D.PDF

Linux:

● https://www.kernel.org/doc/Documentation/hwmon/lm85● modprobe lm85

6

Page 7: lm-sensors in embedded systems: from schematics to management from linux

Павел Курочкин General R&D, 2017

ads7830Схемотехника:

● Мониторинг напряжений● 8-ми канальный АЦП (8 бит)● http://www.ti.com/lit/ds/symlink/ads7830.pdf

Linux:

● modprobe ads7828● https://www.kernel.org/doc/Documentation/hwmon/ads7828

7

Page 8: lm-sensors in embedded systems: from schematics to management from linux

Павел Курочкин General R&D, 2017

Загрузка Linux на SoC1. Первичный загрузчик (preloader)2. Вторичный загрузчик (u-boot)3. Linux kernel4. init/systemd

Нужен корректный device-tree

8

Page 9: lm-sensors in embedded systems: from schematics to management from linux

Павел Курочкин General R&D, 2017

Добавляем чипы в device-treelm85@2d {

compatible = "national,adt7463";reg = <0x2d>;status = "okay";

};

adc@48 { compatible = "at,ads7830"; reg = <0x48>; status = "okay";};

Поддерживается модулем ads7828.ko

~$ /sbin/modinfo ads7828 | grep ads7830alias: i2c:ads7830

Поддерживается модулем lm85.ko

~$ /sbin/modinfo lm85 | grep adt7463alias: i2c:adt7463

9

Page 10: lm-sensors in embedded systems: from schematics to management from linux

Павел Курочкин General R&D, 2017

Инструменты для i2c● apt-get install i2c-tools● Чтение-запись регистров: i2cget, i2cset● Сканирование шины: i2cdetect, i2cdump

10

Page 11: lm-sensors in embedded systems: from schematics to management from linux

Павел Курочкин General R&D, 2017

Дебажим i2c# i2cdetect -r 0... 0 1 2 3 4 5 6 7 8 9 a b c d e f00: -- -- -- -- -- -- -- -- -- 0c -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- UU -- -- -- -- -- 2d 2e -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- 48 -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- UU -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- --

используется драйвером

не используется драйвером

11

Page 12: lm-sensors in embedded systems: from schematics to management from linux

Павел Курочкин General R&D, 2017

Загружаем модули# modprobe lm85

# modprobe ads7828 # i2cdetect -r 0... 0 1 2 3 4 5 6 7 8 9 a b c d e f00: -- -- -- -- -- -- -- -- -- 0c -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- UU -- -- -- -- -- UU UU -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- UU -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- --

12

Page 14: lm-sensors in embedded systems: from schematics to management from linux

Павел Курочкин General R&D, 2017

hwmon sysfs interface● Напряжение● Ток● Мощность● Температура● Вторжение● Обороты вентиляторов● PWM● Можно использовать без sensors● Documentation/hwmon/sysfs-interface

Наш случай

14

Page 15: lm-sensors in embedded systems: from schematics to management from linux

Павел Курочкин General R&D, 2017

adt7463 sysfs contents# ls /sys/class/hwmon/hwmon1/alarms in0_max in4_min pwm3_auto_pwm_minctl temp2_auto_temp_offcpu0_vid in0_min name pwm3_enable temp2_inputdevice in1_alarm pwm1 pwm3_freq temp2_maxfan1_alarm in1_input pwm1_auto_channels subsystem temp2_minfan1_input in1_max pwm1_auto_pwm_min temp1_alarm temp3_alarmfan1_min in1_min pwm1_auto_pwm_minctl temp1_auto_temp_crit temp3_auto_temp_critfan2_alarm in2_alarm pwm1_enable temp1_auto_temp_max temp3_auto_temp_maxfan2_input in2_input pwm1_freq temp1_auto_temp_min temp3_auto_temp_minfan2_min in2_max pwm2 temp1_auto_temp_off temp3_auto_temp_offfan3_alarm in2_min pwm2_auto_channels temp1_fault temp3_faultfan3_input in3_alarm pwm2_auto_pwm_min temp1_input temp3_inputfan3_min in3_input pwm2_auto_pwm_minctl temp1_max temp3_maxfan4_alarm in3_max pwm2_enable temp1_min temp3_minfan4_input in3_min pwm2_freq temp2_alarm ueventfan4_min in4_alarm pwm3 temp2_auto_temp_crit vrmin0_alarm in4_input pwm3_auto_channels temp2_auto_temp_maxin0_input in4_max pwm3_auto_pwm_min temp2_auto_temp_min

15

Page 16: lm-sensors in embedded systems: from schematics to management from linux

Павел Курочкин General R&D, 2017

ads7830 sysfs interface# ls /sys/class/hwmon/hwmon2/device in1_input in3_input in5_input in7_input subsystemin0_input in2_input in4_input in6_input name uevent

16

Page 17: lm-sensors in embedded systems: from schematics to management from linux

Павел Курочкин General R&D, 2017

Checkpoint 1Имеем:

● Возможность настраивать и измерять● Полный доступ к чипам по i2c

Ещё нужно:

● Дать мнемонические названия● Конвертировать попугаев в Вольты и градусы ● Настроить пределы● Настроить автоматическое управление вентиляторами

17

Page 18: lm-sensors in embedded systems: from schematics to management from linux

Павел Курочкин General R&D, 2017

sensors без конфига# sensors adt7463-i2c-0-2dAdapter: Synopsys DesignWare I2C adapterin0: +0.00 V (min = +0.00 V, max = +3.32 V) ALARMin1: +0.01 V (min = +0.00 V, max = +2.99 V) ALARMin2: +3.30 V (min = +2.97 V, max = +3.63 V)in3: +0.00 V (min = +4.50 V, max = +5.50 V) ALARMin4: +0.00 V (min = +0.00 V, max = +15.94 V) ALARMfan1: 15000 RPM (min = 0 RPM)fan2: 15000 RPM (min = 0 RPM)fan3: 0 RPM (min = 0 RPM)fan4: 15000 RPM (min = 0 RPM)temp1: +32.0 C (low = +5.0 C, high = +50.0 C)temp2: +34.5 C (low = +5.0 C, high = +50.0 C)temp3: +63.0 C (low = +5.0 C, high = +85.0 C)cpu0_vid: +0.000 V

18

Page 19: lm-sensors in embedded systems: from schematics to management from linux

Павел Курочкин General R&D, 2017

Конфигурируем sensors● Каталог для конфигов /etc/sensors.d/● Можно:

○ Назначить alias○ Настроить min/max○ Математические операции○ Игнорировать поля

● ‘sensors -s’ применяет настройки

19

Page 20: lm-sensors in embedded systems: from schematics to management from linux

Павел Курочкин General R&D, 2017

sensors c конфигурацией# sensorsadt7463-i2c-0-2dAdapter: Synopsys DesignWare I2C adapter3.3V: +3.30 V (min = +2.97 V, max = +3.63 V)PSB1FAN: 15000 RPM (min = 0 RPM)PSB0FAN: 15000 RPM (min = 0 RPM)CHTEMP: +32.0 C (low = +5.0 C, high = +50.0 C)INTTEMP: +34.5 C (low = +5.0 C, high = +50.0 C)SOMTEMP: +62.0 C (low = +5.0 C, high = +85.0 C)

ads7830-i2c-0-48Adapter: Synopsys DesignWare I2C adapterPSB0TEMP: -1.87 V PSB1TEMP: +39.69 V 3V3: +3.32 V 5V: +4.98 V PSB0VIN: +5.74 V PSB1VIN: +12.19 V SYS12V: +12.07 V

20

Page 21: lm-sensors in embedded systems: from schematics to management from linux

Павел Курочкин General R&D, 2017

А кто будет управлять вентиляторами?# export DEVPATH=/sys/class/hwmon/hwmon1

# echo 1 > $DEVPATH/pwm1_auto_channels

# echo 0 > $DEVPATH/pwm1_auto_pwm_min

# echo 20000 > $DEVPATH/temp1_auto_temp_min

# echo 19000 > $DEVPATH/temp1_auto_temp_off

# echo 35000 > $DEVPATH/temp1_auto_temp_max

pwm1 работает от первого канала измерения температуры

При низкой температуре вентиляторы не крутятся

Настраиваем границы температурного диапазона

21

Page 22: lm-sensors in embedded systems: from schematics to management from linux

Павел Курочкин General R&D, 2017

Нюансы (грабли)● При двухпроводном подключении вентиляторов PID-регулятор работать

не будет● Требуется ручная настройка (i2cget/i2cset)● Точность измерения низкая

22

Page 23: lm-sensors in embedded systems: from schematics to management from linux

Павел Курочкин General R&D, 2017

Итого● Выбираем чип● Находим его в Documentation/hwmon● Прописываем в device-tree● Находим на шине i2c● Загружаем модуль● Конфигурируем sensors● Настраиваем через sysfs управление вентиляторами

23

Page 24: lm-sensors in embedded systems: from schematics to management from linux

Павел Курочкин General R&D, 2017

Ссылки● https://www.kernel.org/doc/Documentation/hwmon/ ● https://www.onsemi.com/pub/Collateral/ADT7463-D.PDF● http://www.ti.com/lit/ds/symlink/ads7830.pdf

24