die_temp: STM32: add capability to ask for die_temp#516
Conversation
Built
|
| Artifact | Board | Core | Tests | RAM | Sketches | Warnings | Errors |
|---|---|---|---|---|---|---|---|
✅* zephyr_contrib |
ek_ra8d1
| 📗 | ✅* |
11.9% |
2 | 2 | - |
frdm_mcxn947
| 7 🏷️ | ✅* |
58.0% |
2 | 2 | - | |
frdm_rw612
| 2 🏷️ | ✅* |
83.0% |
2 | 2 | - | |
✔️* zephyr_main |
giga
| 5 🏷️ | ✅* |
39.4% |
68 | 26 | - |
nano33ble
| 1 🏷️ | ✅* |
78.8% |
30 | 8 | - | |
nano_matter
| 1 🏷️ | ✅* |
|
22 | 8 | - | |
nicla_sense
| 2 🏷️ | ✅* |
|
18 | 8 | - | |
nicla_vision
| 5 🏷️ | ✔️* |
41.7% |
52 | 16 | (2*) | |
opta
| 5 🏷️ | ✅* |
42.4% |
62 | 18 | - | |
portentac33
| 3 🏷️ | ✅* |
80.6% |
66 | 16 | - | |
portentah7
| 4 🏷️ | ✅* |
43.2% |
80 | 22 | - | |
✅* zephyr_unoq |
unoq
| 📗 | ✅* |
43.6% |
56 | 8 | - |
Legend
Board Test Status description 🔥 🔥 Test run failed to complete. ❌ 🔴 Test completed with unexpected errors. ⁉️ ⁉️ Test was expected to fail but passed; exception entry is outdated. ✔️* 🚫 Test completed with errors, but all are known/expected. ✅* 🟡 Test completed with some warnings; no errors detected. ✅ 🟢 Test passed successfully, with no warnings or errors. 🌑 🌑 Test was skipped.
|
This relies on the changes made to arduino/zephyr |
|
@facchinm @pennam - I am marking this as ready for review, ditto for the change for Zephyr where it tries to recover the die-temp and the like object if the underlying ADC is marked as deferred-init. So far I have not created a library to call it, only the sketch, although could easily extract the stuff from the test sketch |
Built
|
| Artifact | Board | Core | Tests | RAM | Sketches | Warnings | Errors |
|---|---|---|---|---|---|---|---|
✅* zephyr_contrib |
ek_ra8d1
| 📗 | ✅* |
11.9% |
2 | 2 | - |
frdm_mcxn947
| 7 🏷️ | ✅* |
58.0% |
2 | 2 | - | |
frdm_rw612
| 2 🏷️ | ✅* |
83.0% |
2 | 2 | - | |
✔️* zephyr_main |
giga
| 5 🏷️ | ✅* |
39.4% |
68 | 26 | - |
nano33ble
| 1 🏷️ | ✅* |
78.8% |
30 | 8 | - | |
nano_matter
| 1 🏷️ | ✅* |
|
22 | 8 | - | |
nicla_sense
| 2 🏷️ | ✅* |
|
18 | 8 | - | |
nicla_vision
| 5 🏷️ | ✔️* |
41.7% |
52 | 16 | (2*) | |
opta
| 5 🏷️ | ✅* |
42.4% |
62 | 18 | - | |
portentac33
| 3 🏷️ | ✅* |
80.6% |
66 | 16 | - | |
portentah7
| 4 🏷️ | ✅* |
43.2% |
80 | 22 | - | |
✅* zephyr_unoq |
unoq
| 📗 | ✅* |
43.6% |
56 | 8 | - |
Legend
Board Test Status description 🔥 🔥 Test run failed to complete. ❌ 🔴 Test completed with unexpected errors. ⁉️ ⁉️ Test was expected to fail but passed; exception entry is outdated. ✔️* 🚫 Test completed with errors, but all are known/expected. ✅* 🟡 Test completed with some warnings; no errors detected. ✅ 🟢 Test passed successfully, with no warnings or errors. 🌑 🌑 Test was skipped.
Enabled the die_temp sensor code for the STM32 boards, which include:
Uno Q, Portenta H7, Giga, Nicla Vision.
There is an issue that this requires an ADC to be "Ready", and some
of our boards are setup that these are defer-init. Two easy possible
fixes, remove the defer-init form the correct ADC object(s). Or
I patched the zephyr drivers:
```
modified: drivers/sensor/st/stm32_temp/stm32_temp.c
modified: drivers/sensor/st/stm32_vref/stm32_vref.c
```
Where if the ADC object device is not ready I call device_init on it.
I have run the sketch:
```
IF_ENABLED(DT_NODE_EXISTS(DIE_TEMP_ALIAS(i)), (DEVICE_DT_GET(DIE_TEMP_ALIAS(i)), ))
/* support up to 16 cpu die temperature sensors */
static const struct device *const sensors[] = { LISTIFY(16, DIE_TEMPERATURE_SENSOR, ()) };
static int get_die_temperature(const struct device *dev) {
struct sensor_value val;
int rc;
//printk("get_die_temperature: %p\n", dev);
/* fetch sensor samples */
rc = sensor_sample_fetch(dev);
//printk("sensor_sample_fetch: %d\n", rc);
if (rc) {
printk("Failed to fetch sample (%d)\n", rc);
return rc;
}
rc = sensor_channel_get(dev, SENSOR_CHAN_DIE_TEMP, &val);
//printk("sensor_channel_get: %d\n", rc);
if (rc) {
printk("Failed to get data (%d)\n", rc);
return rc;
}
printk("CPU Die temperature[%s]: %.1f °C\n", dev->name, sensor_value_to_double(&val));
return 0;
}
double CPUTemperature(uint8_t sensor_index = 0) {
if (sensor_index >= ARRAY_SIZE(sensors)) return 0.0 / 0.0;
const struct device *dev = sensors[0];
struct sensor_value val;
int rc;
//printk("get_die_temperature: %p\n", dev);
/* fetch sensor samples */
rc = sensor_sample_fetch(dev);
//printk("sensor_sample_fetch: %d\n", rc);
if (rc) return 0.0 / 0.0;
rc = sensor_channel_get(dev, SENSOR_CHAN_DIE_TEMP, &val);
if (rc) return 0.0 / 0.0;
return sensor_value_to_double(&val);
}
void setup() {
Serial.begin(115200);
while (!Serial && millis() < 5000) {}
delay(2000);
Serial.print("Test DIE_TEMP count: ");
Serial.println(ARRAY_SIZE(sensors));
for (size_t i = 0; i < ARRAY_SIZE(sensors); i++) {
int rc = get_die_temperature(sensors[i]);
if (rc < 0) {
return;
}
}
}
void loop() {
double temp = CPUTemperature();
Serial.print("CPU Temp C:");
Serial.print(temp, 2);
if (!isnan(temp)) {
Serial.print(" F:");
Serial.print(temp * 1.8 + 32.0, 2);
}
Serial.println();
delay(5000);
}
```
On all of these boards mentioned:
Last one I tried was Nicla Vision:
Serial Monitor window:
```
Test DIE_TEMP count: 1
CPU Temp C:33.59 F:92.47
CPU Temp C:33.59 F:92.47
CPU Temp C:33.27 F:91.88
CPU Temp C:32.94 F:91.29
CPU Temp C:32.94 F:91.29
CPU Temp C:32.61 F:90.70
CPU Temp C:32.61 F:90.70
CPU Temp C:33.27 F:91.88
CPU Temp C:33.27 F:91.88
CPU Temp C:32.61 F:90.70
CPU Temp C:32.94 F:91.29
```
Debug Window:
```
WLAN MAC Address : FC:84:A7:FA:A9:85
WLAN Firmware : wl0: Jan 30 2020 21:41:53 version 7.45.98.95 (r724303 CY) FWID 01-5afc8c1e
WLAN CLM : API: 12.2 Data: 9.10.39 Compiler: 1.29.4 ClmImport: 1.36.3 Creation: 2020-01-30 21:30:05
WHD VERSION : 3.3.2.25168 : v3.3.2 : GCC 12.2 : 2024-12-06 06:53:17 +0000
CPU Die temperature[dietemp]: 33.3 °C
```
To correspond to the marking of the underlying ADC modules
07f6242 to
a8b7b36
Compare
Not sure the best place for this. Could be a library included like this, or could be built-in or external library. But Added it here, as for testing and review. Tested it so far with: UnoQ, Nicla Vision, Giga. WIll recheck again on Portenta H7, but worked before
Built
|
| Artifact | Board | Core | Tests | RAM | Sketches | Warnings | Errors |
|---|---|---|---|---|---|---|---|
✅* zephyr_contrib |
ek_ra8d1
| 📗 | ✅* |
11.9% |
2 | 2 | - |
frdm_mcxn947
| 7 🏷️ | ✅* |
58.0% |
2 | 2 | - | |
frdm_rw612
| 2 🏷️ | ✅* |
83.0% |
2 | 2 | - | |
✔️* zephyr_main |
giga
| 5 🏷️ | ✅* |
39.4% |
70 | 26 | - |
nano33ble
| 1 🏷️ | ✅* |
78.8% |
32 | 10 | - | |
nano_matter
| 1 🏷️ | ✅* |
|
24 | 10 | - | |
nicla_sense
| 2 🏷️ | ✅* |
|
20 | 10 | - | |
nicla_vision
| 5 🏷️ | ✔️* |
41.7% |
54 | 16 | (2*) | |
opta
| 5 🏷️ | ✅* |
42.4% |
64 | 18 | - | |
portentac33
| 3 🏷️ | ✅* |
80.6% |
68 | 18 | - | |
portentah7
| 4 🏷️ | ✅* |
43.2% |
82 | 22 | - | |
✅* zephyr_unoq |
unoq
| 📗 | ✅* |
43.6% |
58 | 8 | - |
Legend
Board Test Status description 🔥 🔥 Test run failed to complete. ❌ 🔴 Test completed with unexpected errors. ⁉️ ⁉️ Test was expected to fail but passed; exception entry is outdated. ✔️* 🚫 Test completed with errors, but all are known/expected. ✅* 🟡 Test completed with some warnings; no errors detected. ✅ 🟢 Test passed successfully, with no warnings or errors. 🌑 🌑 Test was skipped.
|
Memory usage change @ 473958d
Click for full report table
Click for full report CSV |
|
Yesterday, I updated this PR again. I removed the requirement for needing changes at the zephyr level. Instead I also split out the test code to retrieve this information, to it's own library: CPUTemperature, which I added as another I have, updated and tested it on: Uno Q, Giga, Portenta H7, Nicla Vision. Not sure if there are any other Arduino Zephyr boards that have the die_temp support currently built in |
|
Just rebuilt the core with this PR incorporated along with analog frequency updated both the IDE and on the Q4. Ran your CPU temp app that you posted and all seem to be working: |
Enabled the die_temp sensor code for the STM32 boards, which include: Uno Q, Portenta H7, Giga, Nicla Vision.
There is an issue that this requires an ADC to be "Ready", and some of our boards are setup that these are defer-init. Two easy possible fixes, remove the defer-init form the correct ADC object(s). Or I patched the zephyr drivers:
Where if the ADC object device is not ready I call device_init on it.
I have run the sketch:
On all of these boards mentioned:
Last one I tried was Nicla Vision:
Serial Monitor window:
Debug Window: