Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a STM32 Digital Temperature Sensor and add it to STM32H7 family DTS #72982

Merged
merged 3 commits into from
Jun 4, 2024

Conversation

aurel32
Copy link
Collaborator

@aurel32 aurel32 commented May 18, 2024

Tested on a Nucleo h7a3zi board, it gives similar results as the analog temperature sensor.

drivers/sensor/st/Kconfig Outdated Show resolved Hide resolved
drivers/sensor/st/stm32_dts/stm32_dts.c Outdated Show resolved Hide resolved
dts/bindings/sensor/st,stm32-dts.yaml Outdated Show resolved Hide resolved
Copy link
Member

@erwango erwango left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this addition @aurel32.
To be complete, we'd need a way to at least build this driver in CI (using samples/sensor/die_temp_polling ?)

drivers/sensor/st/stm32_dts/stm32_dts.c Outdated Show resolved Hide resolved
dts/bindings/sensor/st,stm32-dts.yaml Outdated Show resolved Hide resolved
@aurel32
Copy link
Collaborator Author

aurel32 commented May 21, 2024

I have just pushed a new version renaming the sensor to stm32_digi_temp, the device tree compat to st,stm32-digi-temp and the node label to digi_die_temp.

I have added a board overlay for the die_temp_polling sample. It outputs:

*** Booting Zephyr OS build v3.6.0-4233-gefac3ef4f2b8 ***
CPU Die temperature[digi_dietemp@58006800]: 30.4 °C
CPU Die temperature[digi_dietemp@58006800]: 30.1 °C
CPU Die temperature[digi_dietemp@58006800]: 30.1 °C

...

Copy link
Collaborator

@FRASTM FRASTM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for adding this new driver !
It's a interesting enhancement

dts/arm/st/h7/stm32h7.dtsi Outdated Show resolved Hide resolved
Copy link
Member

@erwango erwango left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few late comments that I forgot to commit, sorry.

drivers/sensor/st/stm32_digi_temp/Kconfig Outdated Show resolved Hide resolved
drivers/sensor/st/stm32_digi_temp/stm32_digi_temp.c Outdated Show resolved Hide resolved
drivers/sensor/st/stm32_digi_temp/stm32_digi_temp.c Outdated Show resolved Hide resolved
Copy link
Member

@erwango erwango left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes!

One very last request and this will be fine to me:
Unless I'm wrong, you'll need to add nucleo_h7a3zi_q as integration platform to the sample to ensure it is taken into account in test campaigns.

(We'll also need to tune this later on to get it ran on our test bench, but we'll take care of it).

@aurel32
Copy link
Collaborator Author

aurel32 commented May 28, 2024

One very last request and this will be fine to me: Unless I'm wrong, you'll need to add nucleo_h7a3zi_q as integration platform to the sample to ensure it is taken into account in test campaigns.

That should be done now.

erwango
erwango previously approved these changes May 29, 2024
Copy link
Member

@erwango erwango left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Comment on lines +74 to +85
while (READ_BIT(dts->SR, DTS_SR_TS1_RDY) == 0) {
k_yield();
}

/* Trigger a measurement */
SET_BIT(dts->CFGR1, DTS_CFGR1_TS1_START);
CLEAR_BIT(dts->CFGR1, DTS_CFGR1_TS1_START);

/* Wait for interrupt */
k_sem_take(&data->sem_isr, K_FOREVER);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocker suggestion: should we have a fail-safe on the while-loop and k_sem_take()? I'm thinking of returning -ETIMEDOUT or similar in case the happy-path does not work.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to do that with K_FOREVER. Looking at the documentation, it could return:

  • 0 – Semaphore taken.
  • -EBUSY – Returned without waiting.
  • -EAGAIN – Waiting period timed out, or the semaphore was reset during the waiting period.

It seems that the -EBUSY case can only happens when using K_NO_WAIT. For -EAGAIN, the period timeout can't happen as K_FOREVER is used, and the semaphore reset also can't happened as it is only initialized in stm32_digi_temp_init as part of the driver initialization.

Therefore I don't think we need to add a while loop around it. In addition, I haven't found such a structure (with K_FOREVER) elsewhere in the Zephyr's code.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps I didn't explain myself:

WRT the while-loop: I'm referring to

	while (READ_BIT(dts->SR, DTS_SR_TS1_RDY) == 0) {
		k_yield();
	}

WRT the semaphore: I'm alluding of a scenario where the semaphore is not given, therefore the execution path is blockde. Handling such case involves changing the semaphore from K_FOREVER to a specific timeout and handling the error-codes you described.

ubieda
ubieda previously approved these changes May 29, 2024
This add basic support for the STM32 Digital Temperature Sensor found
notably on the STM32H7 series. It work in interrupt mode and support
basic power device management.

It does not support the more advanced features like using the
temperature threshold, triggers from LPTIM or using the LSE clock in
during sleep or stop.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
Add a digi_dietemp node for the STM32 Digital Temperature Sensor into
stm32h723.dtsi (used as a base for H723, H725, H730 and H735) and
stm32h7a3.dtsi (used as a base for H7A3, H7B0 and H7B3).

The sensor is not available on other H7 SoCs.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
Added board nucleo_h7a3zi_q overlay file to permit testing the STM32
Digital Temperature Sensor.

Also added the board as integration platform to the sample.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
@aescolar aescolar merged commit 460169d into zephyrproject-rtos:main Jun 4, 2024
23 checks passed
@aurel32 aurel32 deleted the stm32-dts branch June 4, 2024 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Devicetree Binding PR modifies or adds a Device Tree binding area: Samples Samples area: Sensors Sensors platform: STM32 ST Micro STM32
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants