Bug in header file ulp_riscv_gpio.h

cbaurtx
Posts: 14
Joined: Sun May 10, 2020 9:24 am

Bug in header file ulp_riscv_gpio.h

Postby cbaurtx » Mon Apr 01, 2024 11:20 am

  1. static inline void ulp_riscv_gpio_output_level(gpio_num_t gpio_num, uint8_t level)
  2. {
  3.     if (level) {
  4.         REG_SET_FIELD(RTC_GPIO_OUT_W1TS_REG, RTC_GPIO_OUT_DATA_W1TS, BIT(gpio_num));
  5.     } else {
  6.         REG_SET_FIELD(RTC_GPIO_OUT_W1TC_REG, RTC_GPIO_OUT_DATA_W1TS, BIT(gpio_num));
  7.     }
  8. }
Code for if(level) and else is identical. Clearly one should be W1TC
ESP-IDF Version 5.1 used with ADF version 2.6

Can you point me to a working example using ESP32-S3 with the riscv ulp controlling an rtcio as output?

MicroController
Posts: 1725
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Bug in header file ulp_riscv_gpio.h

Postby MicroController » Mon Apr 01, 2024 9:47 pm

cbaurtx wrote:
Mon Apr 01, 2024 11:20 am
Code for if(level) and else is identical.
Luckily it's not.

MicroController
Posts: 1725
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Bug in header file ulp_riscv_gpio.h

Postby MicroController » Tue Apr 02, 2024 8:32 pm

But... in fact, REG_WRITE should be used there instead of REG_SET_FIELD, like

Code: Select all

    static inline void ulp_riscv_gpio_output_level(gpio_num_t gpio_num, uint8_t level)
    {
        if (level) {
            REG_WRITE(RTC_GPIO_OUT_W1TS_REG, ((BIT(gpio_num) << RTC_GPIO_OUT_DATA_W1TS_S) & RTC_GPIO_OUT_DATA_W1TS_M));
        } else {
            REG_WRITE(RTC_GPIO_OUT_W1TC_REG, ((BIT(gpio_num) << RTC_GPIO_OUT_DATA_W1TC_S) & RTC_GPIO_OUT_DATA_W1TC_M));
        }
    }
.
Would be faster and, after all, W1TC and W1TS are write-only registers.

cbaurtx
Posts: 14
Joined: Sun May 10, 2020 9:24 am

Re: Bug in header file ulp_riscv_gpio.h (solved)

Postby cbaurtx » Thu Apr 04, 2024 8:13 pm

I was a complete fool, yes the code is not identical and it does work as intended.

MicroController
Posts: 1725
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Bug in header file ulp_riscv_gpio.h

Postby MicroController » Thu Apr 04, 2024 8:57 pm

I wouldn't say that :)
RTC_GPIO_OUT_DATA_W1TS in the "else" branch is actually wrong - it only works because RTC_GPIO_OUT_DATA_W1TS and RTC_GPIO_OUT_DATA_W1TC happen to be the same value...

Who is online

Users browsing this forum: No registered users and 110 guests