-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Save 16 bytes RAM by placing esp8266_gpioToFn (core_esp8266_wiring_digital.cpp) array in PROGMEM #6703
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
For regression considerations, in The Official Arduino AVR core ArduinoCore-avr,
So that's also in flash, not RAM. |
I do agree on your opinion about that, but do you expect there are sketches out there using pinMode() from ISR? Another point against this PR may be that this does probably have an effect on timing when bit-banging pins. |
@TD-er I've to correct myself, because obviously |
I've looked through the libraries included in ESPEasy and it seems BlynkApi does do a lot of pinMode switching. (no idea why though) template<class Proto>
BLYNK_FORCE_INLINE
void BlynkApi<Proto>::processCmd(const void* buff, size_t len) Also NewPingESP8266 does switch a lot between pin modes. Our own implementation of the Dallas 1wire code does have a lot of switches between pin modes (I really don't like that implementation, since it appears to be way too time critical) Reading the DHT11/22 is also based on switching pin mode. Our implementation of SHT1x also uses pin mode switching for reading the sensor. Reading the P1 interface of a smart meter is using the pin mode switching. PMSx003 (PlanTower dust particle meters) in our code is also using pin mode switching during initialization. Our code for TTP229 key pad uses pin mode for reading. Our code for HX711 load cell uses pin mode switching at init of the sensor. Our code for Kamstrup 401 uses pin mode switching during read. That's just a quick grep over my code base. |
@TD-er Please check this out. Everything is better than without patch - just why doesn't the extra size of the array in flash show in the build logs...
|
@dok-net |
It will have to be the smaller macro expansion vs. the larger table size. |
I'm not sure about the array in PROGMEM, I can't help thinking about the 1-wire protocols like OneWire or single-wire uart (like the dynamixel bus). In such cases, the usage is usually as follows:
Which would be ok, except for async incoming data. In such cases, the sequence would be as follows:
That means that async incoming data could be implemented with pinMode changes within the ISR, which I guess would mean the esp8266_gpioToFn table would need to be in RAM? |
@devyte But I noted above, that calling pinMode() from ISR is illegal to begin with - it's not pinned to IRAM. Why would any library use this and keep crashing :-) That besides the obvious mistake of doing time consuming stuff directly from an ISR. |
There are macros for each of the GPIO pin function registers GPF0 - GPF15, and there is also a macro that takes the GPIO # as argument. This latter macros uses a lookup table. From global grep over the source tree, there seems to be no other use of this except in the
pinMode()
function, that IMHO would not be called from an ISR - therefore, no IRAM_ATTR constraint seems to exists.In this case, 16 bytes in RAM can be saved by marking the array PROGMEM, and using the alignment correction function in the macro.