Page 1 of 1

Bug in header file ulp_riscv_gpio.h

Posted: Mon Apr 01, 2024 11:20 am
by cbaurtx

Code: ulp_riscv_gpio.h Select all

static inline void ulp_riscv_gpio_output_level(gpio_num_t gpio_num, uint8_t level)
{
if (level) {
REG_SET_FIELD(RTC_GPIO_OUT_W1TS_REG, RTC_GPIO_OUT_DATA_W1TS, BIT(gpio_num));
} else {
REG_SET_FIELD(RTC_GPIO_OUT_W1TC_REG, RTC_GPIO_OUT_DATA_W1TS, BIT(gpio_num));
}
}
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?

Re: Bug in header file ulp_riscv_gpio.h

Posted: Mon Apr 01, 2024 9:47 pm
by MicroController
Code for if(level) and else is identical.
Luckily it's not.

Re: Bug in header file ulp_riscv_gpio.h

Posted: Tue Apr 02, 2024 8:32 pm
by MicroController
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.

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

Posted: Thu Apr 04, 2024 8:13 pm
by cbaurtx
I was a complete fool, yes the code is not identical and it does work as intended.

Re: Bug in header file ulp_riscv_gpio.h

Posted: Thu Apr 04, 2024 8:57 pm
by MicroController
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...