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

modules: hal_nordic: nrfx: update API version to 3.2.0 #64476

Merged

Conversation

nika-nordic
Copy link
Collaborator

Updated API version enables multi-instance GPIOTE driver.

Additionally obsolete symbol that was used to specify API version in the past was removed.

@nika-nordic
Copy link
Collaborator Author

@anangl CI seems to be green, can we proceed with review and merging?

@masz-nordic masz-nordic force-pushed the update_nrfx_api_to_3_2_0 branch 4 times, most recently from ebe5cce to 0dfdbd2 Compare November 27, 2023 15:05
@nika-nordic
Copy link
Collaborator Author

Rebased the PR. Hopefully now the unrelated:

FAILED: zephyr/subsys/net/CMakeFiles/subsys__net.dir/lib/tls_credentials/tls_credentials_trusted.c.obj
ccache /opt/toolchains/zephyr-sdk-0.16.3/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc -DKERNEL -DNRF5340_XXAA_APPLICATION -DNRF_SKIP_FICR_NS_COPY_TO_RAM -DNRF_TRUSTZONE_NONSECURE -DPICOLIBC_LONG_LONG_PRINTF_SCANF -DTC_RUNID=9473c3a39eb23922342372ed882ae5f4 -D_FORTIFY_SOURCE=1 -D_POSIX_C_SOURCE=200809 -D__LINUX_ERRNO_EXTENSIONS__ -D__PROGRAM_START -D__ZEPHYR__=1 -I/__w/zephyr/zephyr/subsys/net/lib/tls_credentials/. -I/__w/zephyr/zephyr/include -I/__w/zephyr/zephyr/twister-out/thingy53_nrf5340_cpuapp_ns/tests/net/lib/tls_credentials/net.tls_credentials.trusted_tfm/zephyr/include/generated -I/__w/zephyr/zephyr/soc/arm/nordic_nrf/nrf53 -I/__w/zephyr/zephyr/soc/arm/nordic_nrf/common/. -I/__w/zephyr/zephyr/subsys/testsuite/include -I/__w/zephyr/zephyr/subsys/testsuite/ztest/include -I/__w/zephyr/zephyr/subsys/usb/device -I/__w/zephyr/zephyr/subsys/net/lib/dns/. -I/__w/zephyr/zephyr/drivers/usb/common/nrf_usbd_common/. -I/__w/zephyr/modules/hal/cmsis/CMSIS/Core/Include -I/__w/zephyr/zephyr/modules/cmsis/. -I/__w/zephyr/modules/hal/nordic/nrfx -I/__w/zephyr/modules/hal/nordic/nrfx/drivers/include -I/__w/zephyr/modules/hal/nordic/nrfx/mdk -I/__w/zephyr/zephyr/modules/hal_nordic/nrfx/. -I/__w/zephyr/zephyr/twister-out/thingy53_nrf5340_cpuapp_ns/tests/net/lib/tls_credentials/net.tls_credentials.trusted_tfm/tfm/generated/interface/include -isystem /__w/zephyr/zephyr/lib/libc/common/include -Wshadow -fno-strict-aliasing -Werror -Os -imacros /__w/zephyr/zephyr/twister-out/thingy53_nrf5340_cpuapp_ns/tests/net/lib/tls_credentials/net.tls_credentials.trusted_tfm/zephyr/include/generated/autoconf.h -fno-printf-return-value -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=cortex-m33 -mthumb -mabi=aapcs -mfp16-format=ieee -mtp=soft --sysroot=/opt/toolchains/zephyr-sdk-0.16.3/arm-zephyr-eabi/arm-zephyr-eabi -imacros /__w/zephyr/zephyr/include/zephyr/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wno-pointer-sign -Wpointer-arith -Wexpansion-to-defined -Wno-unused-but-set-variable -Werror=implicit-int -fno-pic -fno-pie -fno-asynchronous-unwind-tables -ftls-model=local-exec -fno-reorder-functions --param=min-pagesize=0 -fno-defer-pop -fmacro-prefix-map=/__w/zephyr/zephyr/tests/net/lib/tls_credentials=CMAKE_SOURCE_DIR -fmacro-prefix-map=/__w/zephyr/zephyr=ZEPHYR_BASE -fmacro-prefix-map=/__w/zephyr=WEST_TOPDIR -ffunction-sections -fdata-sections --specs=picolibc.specs -std=c99 -MD -MT zephyr/subsys/net/CMakeFiles/subsys__net.dir/lib/tls_credentials/tls_credentials_trusted.c.obj -MF zephyr/subsys/net/CMakeFiles/subsys__net.dir/lib/tls_credentials/tls_credentials_trusted.c.obj.d -o zephyr/subsys/net/CMakeFiles/subsys__net.dir/lib/tls_credentials/tls_credentials_trusted.c.obj -c /__w/zephyr/zephyr/subsys/net/lib/tls_credentials/tls_credentials_trusted.c
/__w/zephyr/zephyr/subsys/net/lib/tls_credentials/tls_credentials_trusted.c:12:10: fatal error: psa/protected_storage.h: No such file or directory
12 | #include <psa/protected_storage.h>

will be fixed

@@ -18,7 +18,7 @@

/** @brief Symbol specifying minor version of the nrfx API to be used. */
#ifndef NRFX_CONFIG_API_VER_MINOR
#define NRFX_CONFIG_API_VER_MINOR 0
#define NRFX_CONFIG_API_VER_MINOR 2
Copy link
Member

Choose a reason for hiding this comment

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

To preserve bisectability, it would be good to make all related changes in drivers in the same commit.

Copy link
Collaborator

Choose a reason for hiding this comment

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

That would make that one commit huge, combining multiple areas - is it really better?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, because otherwise the code does not build. Any commit that does not build is significantly slowing down bisect because you have to skip one, or more, commits which significantly increases the required number of checks. The required number of checks, when all commits in history do build correctly, is log2(N) where N is the number of commits in between good and bad revisions.

Copy link
Contributor

Choose a reason for hiding this comment

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

The commits should really be:

  • Update nrfx API version with all drivers adjusted for new API. No actual functional changes (if possible).
  • Any subsequent commits are the functional changes related to things that were not possible with earlier nrfx version.

@@ -7,6 +7,7 @@
#define ADC_CONTEXT_USES_KERNEL_TIMER
#include "adc_context.h"
#include <hal/nrf_saadc.h>
#include <nrfx_saadc.h>
Copy link
Member

Choose a reason for hiding this comment

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

The nrfx_saadc driver is not used here, so it's a bit weird and misleading to include this header just to use one macro that is defined there. Also the commit message is misleading.

Copy link
Collaborator

Choose a reason for hiding this comment

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

NRFX_SAADC_SAMPLES_TO_BYTES is used.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, and in my opinion this is wrong.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Dropped whole SAADC

@@ -17,6 +17,7 @@ LOG_MODULE_REGISTER(adc_nrfx_saadc);

#define DT_DRV_COMPAT nordic_nrf_saadc

#if !(NRF_SAADC_HAS_AIN_AS_PIN)
Copy link
Member

Choose a reason for hiding this comment

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

The changes in adc_nrfx_saadc.c are not related to the API update to 3.2.0. I think it would be better to process them in a separate PR.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Dropped whole SAADC

Comment on lines 85 to 94
#if defined(NRF_TRUSTZONE_NONSECURE)
#define NRF_GPIOTE1 NRF_GPIOTE1_NS
#else
#if !defined(NRF_TRUSTZONE_NONSECURE)
#define NRF_CACHE NRF_CACHE_S
#define NRF_CACHEINFO NRF_CACHEINFO_S
#define NRF_CACHEDATA NRF_CACHEDATA_S
#define NRF_CRYPTOCELL NRF_CRYPTOCELL_S
#define NRF_CTI NRF_CTI_S
#define NRF_FICR NRF_FICR_S
#define NRF_GPIOTE0 NRF_GPIOTE0_S
Copy link
Member

Choose a reason for hiding this comment

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

These changes should be dropped, for nRF91 as well.

Comment on lines 24 to 26
#define BUTTON_PORT DT_GPIO_CTLR(DT_ALIAS(sw0), gpios)
#define GPIOTE_PHANDLE DT_PHANDLE(BUTTON_PORT, gpiote_instance)
#define GPIOTE_IDX DT_PROP(GPIOTE_PHANDLE, instance)
Copy link
Member

Choose a reason for hiding this comment

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

The code below is not related to the sw0 button so these changes in the current form are misleading. I'd propose to use instead:

Suggested change
#define BUTTON_PORT DT_GPIO_CTLR(DT_ALIAS(sw0), gpios)
#define GPIOTE_PHANDLE DT_PHANDLE(BUTTON_PORT, gpiote_instance)
#define GPIOTE_IDX DT_PROP(GPIOTE_PHANDLE, instance)
#define GPIOTE_IDX DT_PROP(DT_NODELABEL(gpiote), instance)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Changed

Comment on lines 143 to 147
CHECK_DT_REG(gpiote, NRF_GPIOTE);
#if defined(NRF_GPIOTE)
CHECK_DT_REG(gpiote0, NRF_GPIOTE);
#else
CHECK_DT_REG(gpiote0, NRF_GPIOTE0);
#endif
Copy link
Member

Choose a reason for hiding this comment

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

Why?
IMO it should be:

Suggested change
CHECK_DT_REG(gpiote, NRF_GPIOTE);
#if defined(NRF_GPIOTE)
CHECK_DT_REG(gpiote0, NRF_GPIOTE);
#else
CHECK_DT_REG(gpiote0, NRF_GPIOTE0);
#endif
CHECK_DT_REG(gpiote, NRF_GPIOTE);
CHECK_DT_REG(gpiote0, NRF_GPIOTE0);

with

#if !defined(NRF_GPIOTE0) && defined(NRF_GPIOTE)
#define NRF_GPIOTE0 NRF_GPIOTE
#endif

added at the top of the file.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This still causes compilation error on nrf5340_cpuapp as it has both gpiote and gpiote0 nodes defined, but only NRF_GPIOTE0. Adding #define NRF_GPIOTE NRF_GPIOTE0 would fix it but I'm not sure if this is a better solution than what we have now.

#define INPUT_PIN DT_GPIO_PIN(DT_ALIAS(sw0), gpios)
#define INPUT_PORT DT_GPIO_CTLR(DT_ALIAS(sw0), gpios)
#define GPIOTE_PHANDLE DT_PHANDLE(INPUT_PORT, gpiote_instance)
#define GPIOTE_IDX DT_PROP(GPIOTE_PHANDLE, instance)
Copy link
Member

Choose a reason for hiding this comment

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

This does not make much sense as the sample will anyway work only with GPIOTE0 (only this one is enabled in Kconfig). Since only nrf52840dk_nrf52840 and nrf9160dk_nrf9160 are allowed platforms here, I'd rather go with hardcoded instance 0 in the code.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Reworked Kconfig to take into account any GPIOTE instance.

Comment on lines 60 to 62
#define GPIO_NODE(pin) DT_GPIO_CTLR_BY_IDX(DT_DRV_INST(0), channel_gpios, pin)
#define GPIOTE_PHANDLE(pin) DT_PHANDLE(GPIO_NODE(pin), gpiote_instance)
#define GPIOTE_IDX(pin) DT_PROP(GPIOTE_PHANDLE(pin), instance)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#define GPIO_NODE(pin) DT_GPIO_CTLR_BY_IDX(DT_DRV_INST(0), channel_gpios, pin)
#define GPIOTE_PHANDLE(pin) DT_PHANDLE(GPIO_NODE(pin), gpiote_instance)
#define GPIOTE_IDX(pin) DT_PROP(GPIOTE_PHANDLE(pin), instance)
#define GPIO_NODE(channel) DT_GPIO_CTLR_BY_IDX(DT_DRV_INST(0), \
channel_gpios, channel)
#define GPIOTE_PHANDLE(channel) DT_PHANDLE(GPIO_NODE(channel), gpiote_instance)
#define GPIOTE_IDX(channel) DT_PROP(GPIOTE_PHANDLE(channel), instance)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Removed unnecessary whitespaces, but breaking line 60 is not needed.

#define GPIOTE_PHANDLE(pin) DT_PHANDLE(GPIO_NODE(pin), gpiote_instance)
#define GPIOTE_IDX(pin) DT_PROP(GPIOTE_PHANDLE(pin), instance)

static nrfx_gpiote_t gpiote = NRFX_GPIOTE_INSTANCE(GPIOTE_IDX(col_gpios));
Copy link
Member

Choose a reason for hiding this comment

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

This should not assume a single GPIOTE instance. I think that a similar scheme as in pwm_nrf_sw.c should be used instead.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Done

};

#ifdef CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58
static const nrfx_gpiote_t gpiote = NRFX_GPIOTE_INSTANCE(0);
Copy link
Member

Choose a reason for hiding this comment

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

It would be better to move this to anomaly_58_workaround_init() as it is needed only there. In other places NRF_GPIOTE can be used as it is now.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Done

@masz-nordic masz-nordic force-pushed the update_nrfx_api_to_3_2_0 branch 3 times, most recently from 2d151ad to f7d640d Compare December 11, 2023 16:11
modules/hal_nordic/nrfx/nrfx_config_nrf5340_application.h Outdated Show resolved Hide resolved
modules/hal_nordic/nrfx/nrfx_config_nrf5340_application.h Outdated Show resolved Hide resolved
dts/arm/nordic/nrf5340_cpuapp.dtsi Outdated Show resolved Hide resolved
drivers/spi/spi_nrfx_common.h Outdated Show resolved Hide resolved
drivers/spi/spi_nrfx_common.h Outdated Show resolved Hide resolved
samples/boards/nrf/nrfx/Kconfig Outdated Show resolved Hide resolved
drivers/display/display_nrf_led_matrix.c Outdated Show resolved Hide resolved
@jaz1-nordic jaz1-nordic force-pushed the update_nrfx_api_to_3_2_0 branch 2 times, most recently from e6385cd to 8f2a74c Compare January 5, 2024 09:58
samples/boards/nrf/nrfx/Kconfig Outdated Show resolved Hide resolved
scripts/kconfig/kconfigfunctions.py Outdated Show resolved Hide resolved
soc/arm/nordic_nrf/common/soc_nrf_common.h Outdated Show resolved Hide resolved
samples/boards/nrf/nrfx/src/main.c Outdated Show resolved Hide resolved
samples/boards/nrf/nrfx/src/main.c Outdated Show resolved Hide resolved
Change the GPIOTE driver to HAL to prevent instantiation
issues with a multi-instance GPIOTE driver.

Signed-off-by: Jakub Zymelka <[email protected]>
drivers/display/display_nrf_led_matrix.c Outdated Show resolved Hide resolved
drivers/gpio/gpio_nrfx.c Outdated Show resolved Hide resolved
soc/arm/nordic_nrf/common/soc_nrf_common.h Outdated Show resolved Hide resolved
drivers/spi/spi_nrfx_spi.c Outdated Show resolved Hide resolved
@jaz1-nordic jaz1-nordic force-pushed the update_nrfx_api_to_3_2_0 branch 2 times, most recently from 7a980f9 to d655294 Compare January 5, 2024 17:56
dts/bindings/gpio/nordic,nrf-gpio.yaml Outdated Show resolved Hide resolved
dts/bindings/gpio/nordic,nrf-gpiote.yaml Outdated Show resolved Hide resolved
soc/arm/nordic_nrf/common/soc_nrf_common.h Show resolved Hide resolved
Added GPIOTE0, GPIOTE1 instances for legacy devices,
GPIOTE20, GPIOTE30 for Moonlight and GPIOTE130,
GPIOTE131 instances for Haltium.

Signed-off-by: Jakub Zymelka <[email protected]>
After adding new GPIOTE instances, there is a need
to enable the instance for individual boards.

Signed-off-by: Jakub Zymelka <[email protected]>
Updated API version enables multi-instance GPIOTE driver.
Additionally obsolete symbol that was used to specify
API version in the past was removed.
Affected drivers have been adjusted and appropriate changes
in affected files have been made.

Signed-off-by: Jakub Zymelka <[email protected]>
@carlescufi carlescufi merged commit ade49f0 into zephyrproject-rtos:main Jan 8, 2024
24 checks passed
@jaz1-nordic jaz1-nordic deleted the update_nrfx_api_to_3_2_0 branch February 8, 2024 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: ADC Analog-to-Digital Converter (ADC) platform: nRF Nordic nRFx
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants