Page 1 of 1

Writing to GPIO_OUT_REG to only specific pins

Posted: Thu May 23, 2019 4:23 pm
by Deouss
Let's say I want to set 12 bits/pins simultaneously with specific values 0/1 to gpio output register but I do not want to change other bits - must be done with one 32bit word write and possibly one write instruction.
Do I have to disable/enable bits with mask first? I don't want to change settings of other pins.
Should it be done with combination of W1TC/W1TS ?
I am looking for fastest possible way - best with asm instructions if possible. Single REG_WRITE is ok too.
Thanks for any suggestions

Re: Writing to GPIO_OUT_REG to only specific pins

Posted: Fri May 24, 2019 3:40 am
by ESP_Sprite
There's no way to mask bits; the way to go would be to either use a read/modify/write on the GPIO value register (but watch out with multitasking there) or use a W1TC/W1TS combo. From an architectural point of view, I'd think W1TS/W1TC would be faster (no reads involved, writes can be queued) but it does have the slight disadvantage that you have an intermediate value on your GPIOs at some point.

Re: Writing to GPIO_OUT_REG to only specific pins

Posted: Fri May 24, 2019 2:10 pm
by Deouss
So operations steps would be:

val => W1TS
val ~= val
val => W1TC

How that would look in asm ?

Re: Writing to GPIO_OUT_REG to only specific pins

Posted: Sat May 25, 2019 11:50 am
by ESP_Sprite
Deouss wrote:
Fri May 24, 2019 2:10 pm
So operations steps would be:

val => W1TS
val ~= val
val => W1TC

How that would look in asm ?
You probably want to mask the bits you don't want to touch.

W1TS <= val & mask
W1TC <= (~val) & mask

I'll leave the assembly to someone else, but chances are it's not going to be that much faster than C. (Maybe a bit because C declares these as volatile; you could work around that though.)

Re: Writing to GPIO_OUT_REG to only specific pins

Posted: Sat May 25, 2019 4:19 pm
by Deouss
Thanks. Well I use whole word only with needed bits so masking is not necessary.
Actually XOR operation might not be needed and data will be precalculated ready to write)
I want to use assembler instructions to repeat inline few times for speeding execution.