Discuss here different C compiler set ups, and compiling executables for the ESP8266

User avatar
By eriksl
#96364
davydnorris wrote:Yeah I have ANSIfied the headers in the NonOS SDK and have stripped almost everything out of c_types.h and instead add the stdbool, stdint, etc, headers.

The real reason I am trying to compile the latest toolchain is to try and move to the RTOS and some common code between ESP8266 and ESP32 chips. But I need to be able to get my existing code to work first.

The super annoying thing about the whole change to 32bit integers in the latest toolchains is that you need to replace all your *printf formatting, but if you use the supposedly agnostic PRIxxx macros, they break on the earlier toolchains because the definitions inside GCC itself rely on the size of long not int :-(

Are you really considering using the RTOS SDK? That means even more Espressif code. Opaque and badly documented as well as badly written. Are you sure? What is the advantage? I have found that using the three (or even one) task queues you can very well do time slicing yourself, for background tasks. Using RTOS means you will have even less direct access to the hardware or CPU.

BTW the integers were always 32 bit (and signed by default), that's dictated by the xtensa platform. The thing you're running into is that more recent gcc compilers are more strictly enforcing the "uint32_t is the same as an unsigned int, but the name is different so it's an error". Which I think is a good thing. Newer gcc's also warn about using a bool as an int and vice versa.

BTW2 did you know the lx106 (as many other modern cpu's) has very little 8- and 16-bit specific instructions? So if you declare a variable to be 8 or 16 bit wide (something Espressif does very now and then), it just carries out all operations in 32 bit and then chops off the upper 24 or 16 bits. One extra instruction that in most cases isn't really necessary. This is most important in function parameters, never declare them as char, unsigned char, uint8_t, int8_t, short, unsigned short, uint16_t or int16_t unless really necessary. They'll get expanded to 32 bits and afterwards truncated.
User avatar
By eriksl
#96365
davydnorris wrote:Yes - again newlib 3.x onwards has a newlib-nano version available which is even smaller, and crosstool for the ESP chips builds this, as well as versions of the libraries with no RTTI, and for working round the PSRAM bugs in the ESP32 chips. You apparently switch usage of these by adding a spec file command to the compiler but I can't see that it's working

Ok, right I see. But I am not going to use ESP32 in the foreseeable future and I have no issues with newlib 2.0.0, so I resolved to reverting the removal of newlib 2.0.0 from crosstool-ng.

They're always talking of "smaller" but in many cases it won't matter. The linker just picks whatever you use. If you're using very little of libc (as in my case) you'll get very little newlib in your image anyway. I am not very concerned about code size, my ESP12F/S modules all have 4 x 1 Mbyte slots available, of which I am now using half of. It's the DRAM and IRAM usage that concerns me.

It would be nice though if Espressif would just send the patches to newlib upstream, then we could use whatever version we'd like.

davydnorris wrote:See my last post - I previously used %x, %d, %u in my code, but the new toolchain now needs these to be %lx, etc. The other option is to use the PRIx32 macro throughout, but when I did this I found the old toolchain breaks because the PRI macros are defined based on the size of long and not size of int! Which is bizarre

The interesting thing is that on the lx106, int = long. But yes, gcc complains. As said, a very simple remedy is to cast all variables declared using uint32_t or int32_t to unsigned int or int (accordingly) when used in printf. The code will be exactly the same and the error is gone.
User avatar
By davydnorris
#96370
eriksl wrote:It would be nice though if Espressif would just send the patches to newlib upstream, then we could use whatever version we'd like.


The latest newlib and newlib nano are used with no local patches, only the overlay, which is required for xtensa chips in general. The latest ESP32 risc chips don't use anything - newlib is used straight out of the box

eriksl wrote:The interesting thing is that on the lx106, int = long. But yes, gcc complains. As said, a very simple remedy is to cast all variables declared using uint32_t or int32_t to unsigned int or int (accordingly) when used in printf. The code will be exactly the same and the error is gone.


This is a great idea - that's what I'll do and then it'll be compatible with both old and new toolchains.
User avatar
By davydnorris
#96371
eriksl wrote:Are you really considering using the RTOS SDK? That means even more Espressif code. Opaque and badly documented as well as badly written. Are you sure? What is the advantage? I have found that using the three (or even one) task queues you can very well do time slicing yourself, for background tasks. Using RTOS means you will have even less direct access to the hardware or CPU.

BTW the integers were always 32 bit (and signed by default), that's dictated by the xtensa platform. The thing you're running into is that more recent gcc compilers are more strictly enforcing the "uint32_t is the same as an unsigned int, but the name is different so it's an error". Which I think is a good thing. Newer gcc's also warn about using a bool as an int and vice versa.


Yes, I've finally given in and am looking to port all my stuff to RTOS based code. The ESP32 chips have some cool features that I want to explore, and hopefully the ESP8266 RTOS will eventually be completely IDF compatible, meaning one code base (or close to) for all chips.

I agree with you on all the above, but the components are all supplied as source - not necessarily good source, but still source, and they are actively maintained by many people now. And a lot of those are people who have been seconded by Espressif and are real coders, such as igrr.

It's not ideal, but I need to be pragmatic, and I need a shorter dev cycle than having to roll my own all the time on a platform they have given up on and refuse to open up :-(