Skip to content

Conversation

mstasiaknordic
Copy link

Since nrfx is to remove its custom error codes with 4.0 release, error typedef enum has to be moved to bm if intended to still use the symbols.

With nrfx 4.0, we intend to completely remove nrfx_err_t enum and return errno values in the drivers in order to get rid of costly error translation in Zephyr drivers. I see two solutions

1. Moving the enum (done in this PR, very preferrable)

If nrf-bm is to still use nrfx_err_t enum, it would have to be defined here (I assume that nrf_error.h header is the appropriate location). With nrfx drivers returning errno values (0 or negative e.g. -ECANCELED), these would be mapped to the enum. The errors in nrfx would either be replaced 1:1 (e.g. every return of NRFX_ERROR_INTERNAL would be changed to -ECANCELED) or the specific error could get changed to better reflect meaning associated with errno value. Its drawbacks are imperfect value mapping and potenitally big effort to align the two projects.

2. Using conditional values in nrfx

In current form, nrfx supports usage of custom error codes with NRFX_CUSTOM_ERROR_CODES. If nrf-bm rejects the first variant, we could preserve the error code enum in nrfx which could take both errno values and legacy values to align with both Zephyr drivers and nrf-bm. The drawback would be keeping the layer of abstraction that we want to get rid of.

Also, I see that nrf-bm code uses three variants of error codes :

  • nrfx_err_t in
    /**
    * @brief Send data over LPUARTE.
    *
    * @param[in] lpu Low Power UARTE driver instance structure.
    * @param[in] data Data to transfer.
    * @param[in] length Size of data to transfer.
    * @param[in] timeout TX timeout in milliseconds.
    *
    * @retval NRFX_SUCCESS Initialization of transmission was successful.
    * @retval NRFX_ERROR_BUSY When transfer is already in progress.
    * @retval NRFX_ERROR_NULL @p lpu or @p data is NULL.
    * @retval NRFX_ERROR_INVALID_LENGTH length is zero.
    */
    nrfx_err_t bm_lpuarte_tx(struct bm_lpuarte *lpu, uint8_t const *data, size_t length,
    int32_t timeout);
  • errno on
    int bm_timer_stop(struct bm_timer *timer)
    {
    if (timer == NULL) {
    return -EFAULT;
    }
    k_timer_stop(&timer->timer);
    return 0;
    }
  • nrf-bm specific in
    /**
    * @brief Initialize a storage instance.
    *
    * @note This function can be called multiple times on different storage instances in order to
    * configure each of them separately for initialization.
    *
    * @param[in] storage Storage instance to initialize.
    *
    * @retval NRF_SUCCESS on success.
    * @retval NRF_ERROR_NULL If @p storage is @c NULL.
    * @retval NRF_ERROR_BUSY If the implementation-specific resource is busy.
    * @retval NRF_ERROR_INTERNAL If an implementation-specific internal error occurred.
    */
    uint32_t bm_storage_init(struct bm_storage *storage);

Is there a pattern to it? nrfx_err_t for drivers and errno for libs?

Since nrfx is to remove its custom error codes with 4.0
release, error typedef enum has to be moved to bm if
intended to still use the symbols.

Signed-off-by: Michał Stasiak <[email protected]>
Copy link

You can find the documentation preview for this PR here.

@lemrey
Copy link
Contributor

lemrey commented Sep 1, 2025

I think since nrfx_err_t is going to be dropped from nrfx, we might just as well port our code to use errno directly; that shouldn't be a big deal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants