Skip to content

Staging/eval cn0391 ardz#2989

Open
MirceaVlasin wants to merge 5 commits intomainfrom
staging/eval-cn0391-ardz
Open

Staging/eval cn0391 ardz#2989
MirceaVlasin wants to merge 5 commits intomainfrom
staging/eval-cn0391-ardz

Conversation

@MirceaVlasin
Copy link
Copy Markdown
Collaborator

@MirceaVlasin MirceaVlasin commented Mar 11, 2026

Pull Request Description

Create a project for TypeK thermocouple (TC) data acquisition (Embedded World 2026 demo scope), based on EVAL-ADIN1110EBZ and EVAL-CN0391-ARDZ boards.

Add CN0391 board support driver (cn0391.c/h) with full temperature measurement: thermocouple voltage, CJC RTD resistance, cold junction compensation and hot junction temperature across 4 channels (CH0–CH3).

Add a maximal CN0391 IIO device(iio_cn0391.c/h) exposing 4 full TC temperature channels with hot_junction_temp, cold_junction_temp, tc_voltage and rtd_resistance attributes; the full CN0391 IIO device is optional via CN0391_IIO_SUPPORT=y.

Add a custom AD7124-8 IIO device extension which is used by default, presenting each TC channel as a voltage channel with raw (hot junction temperature in °C) and scale attributes matching the requirements related to integration with current SCOPY implementation.

Add two examples: basic (UART temperature readout) and iio_lwip (Ethernet IIO server via ADIN1110 10BASE-T1L, static IP configurable at build time).

Use single conversion mode for AD7124-8 acquisition, enabling only the 3 required ADC channels (TC/R_REF/RTD) per TC read.

Add minimal project documentation that could be subject of updating (eg. after CN0391 IIO device/plugin will be natively supported by SCOPY).

PR Type

  • Bug fix (change that fixes an issue)
  • New feature (change that adds new functionality)
  • Breaking change (has dependencies in other repos or will cause CI to fail)

PR Checklist

  • I have followed the Coding style guidelines
  • I have complied with the Submission Checklist
  • I have performed a self-review of the changes
  • I have commented my code, at least hard-to-understand parts
  • I have build all projects affected by the changes in this PR
  • I have tested in hardware affected projects, at the relevant boards
  • I have signed off all commits from this PR
  • I have updated the documentation (wiki pages, ReadMe etc), if applies

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 11, 2026

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown
Contributor

@amiclaus amiclaus left a comment

Choose a reason for hiding this comment

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

doc build issue seems valid. complaining about the new drivers not having a documentation.

#include <math.h>
#include "no_os_rtd.h"

double no_os_pt1000_resistance_to_temp(double resistance)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe this driver and the thermocouple one belong to util?

sdma_ch->hdma->Init.Channel = sdma_ch->ch_num;
#else
sdma_ch->hdma->Instance = sdma_ch->ch_num;
sdma_ch->hdma->Instance = (DMA_Channel_TypeDef *)sdma_ch->ch_num;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

the changes in stm32_dma should be in separate commit.

* Copyright 2026(c) Analog Devices, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

both no_os_rtd and no_os_thermocouple should have thier own commit.

* @param priv - Unused.
* @return Number of bytes written, or negative error code.
*/
static int cn0391_iio_read_raw_tc(void *device, char *buf, uint32_t len,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this commit should be squashed with the projects commit.

Comment thread drivers/temperature/rtd/no_os_rtd.c Outdated
/**
* @brief Callendar-Van Dusen equation for Pt1000 RTD (IEC 60751).
* Converts RTD resistance to temperature. For T < 0°C a Newton-Raphson
* refinement loop is applied to account for the cubic C term.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we don't create patchfixes for stuff added in the same PR.

Copy link
Copy Markdown
Contributor

@amiclaus amiclaus left a comment

Choose a reason for hiding this comment

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

some comments from my side above, prior to in-depth review.

@MirceaVlasin MirceaVlasin force-pushed the staging/eval-cn0391-ardz branch from 2c04de4 to 70baf5d Compare March 30, 2026 11:52
@MirceaVlasin
Copy link
Copy Markdown
Collaborator Author

v2:

  • commits has been reorganized according to above PR's comments;
  • some previous iterative changes was lost, now we have the final implementation;
  • no HW available to perform a real test

Copy link
Copy Markdown
Contributor

@amiclaus amiclaus left a comment

Choose a reason for hiding this comment

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

some comments on my side.

*/
int stm32_dma_init(struct no_os_dma_desc** desc,
const struct no_os_dma_init_param* param)
struct no_os_dma_init_param* param)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

hmm, why not adding const to the ops signature? the const is correct here we don't want to modify param in the function.

Copy link
Copy Markdown
Collaborator Author

@MirceaVlasin MirceaVlasin Mar 30, 2026

Choose a reason for hiding this comment

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

I agree the "init_params" should be const(the same on CAPI, as a general rule), but in order to remove the compiling error that will be generated beginnig with GCC 14(warnings migrated to errors related to const -> non-const conversion, with the migration to CubeIDE 2.1.0), I've changed the routine definition in this manner bacause:

  1. There is no general rule on No-OS's drivers initialization routines to receive a const init structure(eg. no_os_uart_init, no_os_flash_init, ...).
  2. The other solution(to change init function signature on no_os_dma.h and no_os_dma.c) should affect also the other platforms. and more changes should need.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ack

const struct iio_ch_info *channel,
intptr_t priv)
{
struct cn0391_dev *dev = (struct cn0391_dev *)device;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why are these functions outside CN0391_IIO_SUPPORT ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

These functions exposes the custom AD7124-8 IIO device extension which is used by default, presenting each TC channel as a voltage channel with raw (hot junction temperature in °C) and scale attributes matching the requirements related to integration with current SCOPY implementation for Embedded World Demo.
The IIO device guarded by CN0391_IIO_SUPPORT, will be normally the standard/real IIO profile for CN0391, as soon as the SCOPY will provide a specific plugin for it.

* @param priv - One of cn0391_iio_attr_id.
* @return Number of bytes written, or negative error code.
*/
static int cn0391_iio_read_processed(void *device, char *buf, uint32_t len,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

hmm, this function looks similar to cn0391_iio_read_processed. can we have only one implementation?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

You are refering to cn0391_iio_read_raw_tc?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

yep

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Throug cn0391_iio_read_processed, the IIO client will be able to access any related parameter from the context of TC channel measurement(more parameters versus cn0391_iio_read_raw_tc, covering the custom IIO device with a single parameter). I should keep it for singular split functionality related to CN0391_IIO_SUPPORT.
The IIO device guarded by CN0391_IIO_SUPPORT, will be normally the standard/real IIO profile for CN0391, as soon as the SCOPY will provide a specific plugin for it.

no_os_mdelay(2000);
}

cn0391_remove(dev);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is dead code.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Agree. I'll remove it or I'll integrate it on an exit condition(eg. if more than X consecutive failed reads).

#endif
};

memcpy(adin1110_ip.mac_address, adin1110_mac_address, NETIF_MAX_HWADDR_LEN);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this requires string.h

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Agree. There was no warning because it is included,I suppose, in one of the lwip headers.

*rtd_resistance = r_rtd;

return 0;
} No newline at end of file
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: new line at EOF missing, detected by github.

*/
int stm32_dma_init(struct no_os_dma_desc** desc,
const struct no_os_dma_init_param* param)
struct no_os_dma_init_param* param)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ack

Fix some compiling errors related to GCC 14 toolchain, part of the last CubeIDE 2.1.0.
The changes have impact only on STM32 platform and should't affect the other platforms.

Signed-off-by: MirceaVlasin <mirceavlasin@yahoo.com>
Add utility modules, to cover conversion for PT1000 RTD and TypeK
thermocouple, following the no-OS util convention for platform-agnostic
utilities.

Signed-off-by: MirceaVlasin <mirceavlasin@yahoo.com>
Add CN0391 board support driver (cn0391.c/h) with full temperature
measurement: thermocouple voltage, CJC RTD resistance, cold junction
compensation and hot junction temperature across 4 channels (CH0–CH3).

Add a maximal CN0391 IIO device(iio_cn0391.c/h) exposing 4 full TC
temperature channels with hot_junction_temp, cold_junction_temp,
tc_voltage and rtd_resistance attributes. The full CN0391 IIO device is
optional via CN0391_IIO_SUPPORT=y.

Add a custom AD7124-8 IIO device extension which is used by default,
presenting each TC channel as a voltage channel with raw (hot junction
temperature in °C) and scale attributes matching the requirements
related to integration with current SCOPY implementation.

Use single conversion mode for AD7124-8 acquisition, enabling only the
3 required ADC channels (TC/R_REF/RTD) per TC read.

Add two build examples:
-basic: continuous UART print of CH3 measurements at 2s interval.
-iio_lwip: Ethernet IIO server via ADIN1110. Static IP is configurable
at build time with ADIN1110_STATIC_IP (default: 192.168.97.60/255.255.0.0).

Signed-off-by: MirceaVlasin <mirceavlasin@yahoo.com>
Add minimal project documentation that could be subject of updating (eg.
after CN0391 IIO device/plugin will be natively supported by SCOPY).

Signed-off-by: MirceaVlasin <mirceavlasin@yahoo.com>
Signed-off-by: MirceaVlasin <mirceavlasin@yahoo.com>
@MirceaVlasin MirceaVlasin force-pushed the staging/eval-cn0391-ardz branch from 70baf5d to 937028b Compare April 20, 2026 14:42
@MirceaVlasin
Copy link
Copy Markdown
Collaborator Author

v3:

  • addressing of PR's comments
  • retested with real CN0391 board

Copy link
Copy Markdown
Contributor

@amiclaus amiclaus left a comment

Choose a reason for hiding this comment

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

  • one inline comment
  • 937028b should be dropped and the review adjustments should be in their afferent commits.
  • nit: I'd go for the @analog.com signature

#include "no_os_rtd.h"

#define CN0391_ADC_RESOLUTION 24
#define CN0391_ADC_HALF_RESOLUTION (1 << (CN0391_ADC_RESOLUTION - 1))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is misleading for 2 reasons:

  • #define CN0391_ADC_HALF_RESOLUTION (1 << (CN0391_ADC_RESOLUTION - 1)). are we using only the bipolar mode? or why are we using half resolution?
  • #define CN0391_ADC_RESOLUTION 24 should be 1 << 24 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants