Page 1 of 1

PCNT units 4-7 cause compile/runtime errors on esp32

Posted: Wed Jan 06, 2021 10:47 pm
by TinkerBearNZ
Not quite sure what's going on here - using "stable", v4.2. The esp32s2 only has 4 PCNT units - but I'm not building for the esp32s2, I'm building for the regular old esp32, which has 8 units.

Test case: build examples/peripherals/pcnt
Builds fine, presumably works (haven't tested that far)

Now edit pcnt/main/pcnt_example_main.c to switch from PCNT_UNIT_0 to PCNT_UNIT_4 (or 5, 6, 7) and try to compile.
Compile fails. (If you use hard-coded numbers, then it fails at runtime instead.)

Clearly components/soc/include/hal/pcnt_hal.h is intended to switch between 4 and 8 units. It makes the switch based on a value from components/soc/soc/esp32/include/soc/pcnt_caps.h (or components/soc/soc/esp32s2/include/soc/pcnt_caps.h).

I can't find any other header file that includes pcnt_caps.h, so it must be included independently? The documentation doesn't mention this, so I'm guessing it's an error?

The driver file components/driver/pcnt.c includes pcnt_caps.h, but only after pcnt_hal.h... so it has no effect.

So... is this a bug?

Re: PCNT units 4-7 cause compile/runtime errors on esp32

Posted: Thu Jan 07, 2021 1:22 am
by ESP-Marius
Yup, seems like a bug, I'll make a MR for it.

Seems like the issue is present on master as well, but it doesnt manifest itself due to the include order of the headers.

Thanks for reporting this!