Post links and attach files for documentation here, also chat about these docs freely

User avatar
By duparq
#33979 Hello everybody,

I'm in the process of writing a hardware abstraction tool for the ESPs. In fact, I already have one version available a few Atmel AVRs and I'd like to be able to use the same approach for programming with the ESPs as I do not want to play with bits, masks and shifts anymore and also because it makes the source code far more readable. For those interested, it is here: https://github.com/duparq/hwa.

After a few hours of investigation on how do the GPIOs work, I've arrived to a question about the definition of the PIN_FUNC_SELECT().

What causes me troubles is that the document http://esp8266.ru/esp8266-pin-register-strapping displays 5 possible functions per pin, being coded from 0 to 4. That requires 3 bits.

In the file eagle_soc.h, we can find:
Code: Select all#define PERIPHS_IO_MUX_FUNC             0x13

that let's suppose that the function is actually coded into a 3-bit value with the highest not consecutive to the others.

So, in the definition of PIN_FUNC_SELECT():
Code: Select all#define PIN_FUNC_SELECT(PIN_NAME, FUNC)  do {            \
    WRITE_PERI_REG(PIN_NAME,                  \
         READ_PERI_REG(PIN_NAME)            \
         &  (~(PERIPHS_IO_MUX_FUNC<<PERIPHS_IO_MUX_FUNC_S))   \
         |( (((FUNC&BIT2)<<2)|(FUNC&0x3))<<PERIPHS_IO_MUX_FUNC_S) ); \
  } while (0)

do not you think that (FUNC&BIT2)<<2 should be (FUNC&BIT2)<<4?

Best regards.
User avatar
By martinayotte
#33989 According to the link you mentioned above, the pins registers are 9 bits, from bit8 to bit0.
bit8 = Function Select[2] while bit5 = Function Select[1] and bit4 = Function Select[0].
bit7 is for pullup, and some other bits are written "reserved".
Using small python script, I've simulate the macro PIN_FUNC_SELECT bit shifting, and it was matching what was required, ie: even if function7 doesn't exist, the macro is producing the register value of 0x130, which are the good bit pattern. If I'm trying what you said with the << 4, it will produce 0x430, placing the Select[2] at bit10, which doesn't not exist in this register.
So, in conclusion, the current PIN_FUNC_SELECT macro has no bug ... ;)
User avatar
By duparq
#33998 Thanks for your reply. You're right. I should have tried the macro with some values first.
(FUNC&BIT2) only keeps the bit 2 of FUNC in position 2, then (FUNC&BIT2)<<2 places it in position 4.
All is OK. I go to sleep.

Hmm, by the way, do you know what is PULLUP2?
User avatar
By martinayotte
#34003
duparq wrote:Hmm, by the way, do you know what is PULLUP2?

According to eagle_soc.h, PULLUP2 is bit6 (while PULLUP is bit7), but according to the link you've provided, bit6 is "reserved", so probably undocumented, I don't even know if anyone use it.