Questions about libraries

mresdras10
Posts: 1
Joined: Sat Dec 23, 2017 6:18 am

Questions about libraries

Postby mresdras10 » Sat Dec 23, 2017 6:37 am

I'm a newbie in programming embedded systems, therefore I have so many questions :( . When I opened the codes examples code from from GitHub (e.g. Hello World)(I'm using PlatformIO Atom), I saw many #includes that I don't understand why they are there, like: #include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "nvs_flash.h"
this example is for the hello world. Then, there is any pdf archive or list of the all ESP32 libraries, how they works and when I have to use them ?

I'm so sorry for the english, I'm learning english too.

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Questions about libraries

Postby kolban » Sun Dec 24, 2017 6:04 am

When you want to call logic (functions) that aren't defined in your own application, you typically perform a #include which brings in the contents of the named file as though it existed within your own code. This included material includes such things as the declarations of functions that you can then call.

You would not include a header file if you weren't planning on calling the functions contained within.

Typically if you don't include a needed header file you will be told there is a problem at compile time and with some experience, you will start to recognize the errors as having missed include files.

The documentation for the ESP-IDF APIs can be found here:

http://esp-idf.readthedocs.io/en/latest/

Take a look at this one for example:

http://esp-idf.readthedocs.io/en/latest ... flash.html

As you become familiar with reading such documentation you will find that it names the header file you have to include:

http://esp-idf.readthedocs.io/en/latest ... eader-file

along with the functions and constants defined within.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

User avatar
Gfast2
Posts: 182
Joined: Fri Aug 11, 2017 1:52 am

Re: Questions about libraries

Postby Gfast2 » Thu Dec 28, 2017 9:48 am

Hello guys,

I have a some how the similar question:
In my understanderation in "*.h" files there are most of the time only "function prototypes" and "variable definitions". The real definitions of functions and declaration&initializations of variables are actually happend in "*.c" files. During the walk through of precompiler, all "#include <*.h>" will be replaced by the content of this header file. Say at last this would be a HUGE single file of nearlly all the source codes in it.

But how the "*.c" file get linked-in during this compile time?

Does that mean no matter I did or do not use the code in a "*.c" (which exist in my project directory), all the "*.c" will get compiled to its "*.o" version (Just like the ESP-IDF did for the first build) and later get "merged" (or just is appended to the end of the HUGE file)? :?:

User avatar
urbanze
Posts: 301
Joined: Sat Jun 10, 2017 9:55 pm
Location: Brazil

Re: Questions about libraries

Postby urbanze » Thu Dec 28, 2017 11:42 am

I declare all the libraries I can use someday, so visual studio will always have the functions in Auto-Complete. This is very good because the libraries are only compiled into the code when using any, so declare them all and do not use them, it does not interfere with the final size of the file.

Caution: Flood libraries :lol:
Note: You need to change directory of ESP-IDF/Components if necessary.
Note 2: Here is probably all the files we will be using for a long time, including most of the core registry and library (IDF-API Reference) settings.

Code: Select all

//REG libraries
#include <C:/msys32/ESP32/esp-idf/components/soc/esp32/include/soc/apb_ctrl_reg.h>
#include <C:/msys32/ESP32/esp-idf/components/soc/esp32/include/soc/efuse_reg.h>
#include <C:/msys32/ESP32/esp-idf/components/soc/esp32/include/soc/dport_reg.h>
#include <C:/msys32/ESP32/esp-idf/components/soc/esp32/include/soc/gpio_sd_reg.h>
#include <C:/msys32/ESP32/esp-idf/components/soc/esp32/include/soc/emac_ex_reg.h>
#include <C:/msys32/ESP32/esp-idf/components/soc/esp32/include/soc/emac_reg_v2.h>
#include <C:/msys32/ESP32/esp-idf/components/soc/esp32/include/soc/frc_timer_reg.h>
#include <C:/msys32/ESP32/esp-idf/components/soc/esp32/include/soc/gpio_reg.h>
#include <C:/msys32/ESP32/esp-idf/components/soc/esp32/include/soc/mcpwm_reg.h>
#include <C:/msys32/ESP32/esp-idf/components/soc/esp32/include/soc/hwcrypto_reg.h>
#include <C:/msys32/ESP32/esp-idf/components/soc/esp32/include/soc/i2c_reg.h>
#include <C:/msys32/ESP32/esp-idf/components/soc/esp32/include/soc/io_mux_reg.h>
#include <C:/msys32/ESP32/esp-idf/components/soc/esp32/include/soc/ledc_reg.h>
#include <C:/msys32/ESP32/esp-idf/components/soc/esp32/include/soc/rmt_reg.h>
#include <C:/msys32/ESP32/esp-idf/components/soc/esp32/include/soc/pcnt_reg.h>
#include <C:/msys32/ESP32/esp-idf/components/soc/esp32/include/soc/rtc_cntl_reg.h>
#include <C:/msys32/ESP32/esp-idf/components/soc/esp32/include/soc/rtc_io_reg.h>
#include <C:/msys32/ESP32/esp-idf/components/soc/esp32/include/soc/sdmmc_reg.h>
#include <C:/msys32/ESP32/esp-idf/components/soc/esp32/include/soc/sens_reg.h>
#include <C:/msys32/ESP32/esp-idf/components/soc/esp32/include/soc/spi_reg.h>
#include <C:/msys32/ESP32/esp-idf/components/soc/esp32/include/soc/timer_group_reg.h>
#include <C:/msys32/ESP32/esp-idf/components/soc/esp32/include/soc/uart_reg.h>
//Arduino libraries
#include <C:/msys32/ESP32/ESP32/components/arduino/cores/esp32/Arduino.h>
#include <C:/msys32/ESP32/ESP32/components/arduino/libraries/WiFi/src/WiFi.h>
#include <C:/msys32/ESP32/ESP32/components/arduino/libraries/WiFi/src/WiFiClient.h>
#include <C:/msys32/ESP32/ESP32/components/arduino/libraries/WiFiClientSecure/src/WiFiClientSecure.h>
//IDF libraries
#include <C:/msys32/ESP32/esp-idf/components/esp32/include/esp_wifi.h>
#include <C:/msys32/ESP32/esp-idf/components/driver/include/driver/adc.h>
#include <C:/msys32/ESP32/esp-idf/components/driver/include/driver/dac.h>
#include <C:/msys32/ESP32/esp-idf/components/driver/include/driver/gpio.h>
#include <C:/msys32/ESP32/esp-idf/components/driver/include/driver/rtc_io.h>
#include <C:/msys32/ESP32/esp-idf/components/driver/include/driver/i2c.h>
#include <C:/msys32/ESP32/esp-idf/components/driver/include/driver/i2s.h>
#include <C:/msys32/ESP32/esp-idf/components/driver/include/driver/ledc.h>
#include <C:/msys32/ESP32/esp-idf/components/driver/include/driver/mcpwm.h>
#include <C:/msys32/ESP32/esp-idf/components/driver/include/driver/pcnt.h>
#include <C:/msys32/ESP32/esp-idf/components/driver/include/driver/rmt.h>
#include <C:/msys32/ESP32/esp-idf/components/driver/include/driver/sigmadelta.h>
#include <C:/msys32/ESP32/esp-idf/components/driver/include/driver/spi_common.h>
#include <C:/msys32/ESP32/esp-idf/components/driver/include/driver/spi_slave.h>
#include <C:/msys32/ESP32/esp-idf/components/driver/include/driver/timer.h>
#include <C:/msys32/ESP32/esp-idf/components/driver/include/driver/touch_pad.h>
#include <C:/msys32/ESP32/esp-idf/components/driver/include/driver/uart.h>
#include <C:/msys32/ESP32/esp-idf/components/esp32/include/esp_wifi.h>
#include <C:/msys32/ESP32/esp-idf/components/nvs_flash/include/nvs_flash.h>
#include <C:/msys32/ESP32/esp-idf/components/vfs/include/esp_vfs.h>
#include <C:/msys32/ESP32/esp-idf/components/fatfs/src/esp_vfs_fat.h>
#include <C:/msys32/ESP32/esp-idf/components/spiffs/include/esp_spiffs.h>
#include <C:/msys32/ESP32/esp-idf/components/freertos/include/freertos/task.h>
#include <C:/msys32/ESP32/esp-idf/components/freertos/include/freertos/FreeRTOS.h>
#include <C:/msys32/ESP32/esp-idf/components/esp32/include/esp_intr_alloc.h>
#include <C:/msys32/ESP32/esp-idf/components/esp32/include/esp_task_wdt.h>
#include <C:/msys32/ESP32/esp-idf/components/esp32/include/esp_int_wdt.h>
#include <C:/msys32/ESP32/esp-idf/components/app_update/include/esp_ota_ops.h>
#include <C:/msys32/ESP32/esp-idf/components/esp32/include/esp_system.h>
#include <C:/msys32/ESP32/esp-idf/components/esp32/include/rom/rtc.h>
#include <C:/msys32/ESP32/esp-idf/components/soc/esp32/include/soc/soc.h>
#include <C:/msys32/ESP32/esp-idf/components/soc/esp32/include/soc/rtc.h>
#include <C:/msys32/ESP32/esp-idf/components/esp32/include/esp_attr.h>
#include <C:/msys32/ESP32/esp-idf/components/mbedtls/include/mbedtls/bignum.h>
#include <C:/msys32/ESP32/esp-idf/components/ulp/ulp.c>

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Questions about libraries

Postby WiFive » Thu Dec 28, 2017 11:50 am

Gfast2 wrote: But how the "*.c" file get linked-in during this compile time?
https://www.lurklurk.org/linkers/linkers.html#ccompiler

User avatar
Gfast2
Posts: 182
Joined: Fri Aug 11, 2017 1:52 am

Re: Questions about libraries

Postby Gfast2 » Thu Dec 28, 2017 8:24 pm

WiFive wrote:
Gfast2 wrote: But how the "*.c" file get linked-in during this compile time?
https://www.lurklurk.org/linkers/linkers.html#ccompiler
Hi WiFive,

This one is pretty neat! I've learned really TONS of things from there! Now I got another (meaningless) question:

Since command "nm" can list all contents in *.o file with their original name appeared in its source code respectively. Is that means if I decided to use very long names for those variables and functions in the *.o to "describe" what are in do, I have to live with a larger "*.o" or "*.bin" only for this?

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Questions about libraries

Postby WiFive » Fri Dec 29, 2017 12:49 am


User avatar
Gfast2
Posts: 182
Joined: Fri Aug 11, 2017 1:52 am

Re: Questions about libraries

Postby Gfast2 » Fri Dec 29, 2017 10:45 am

Hi WiFive,

Another awesome knowledge o file for "myBrain.elf" :lol: You are my linker!

But, I have another two extra questions:

1. How to fine tune these compiler flags in esp-idf. I know there are some simple ones can be found in make menuconfig. But how to add these "finer ones"

2. I understand gcc for different plattform is near identical. But for example for the bugs in rev.0 of esp32, man invent compiler flag to work around. Does some doc out there list all available flags for the esp32?

Cheers

Gfast2

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Questions about libraries

Postby WiFive » Fri Dec 29, 2017 11:12 am


User avatar
Gfast2
Posts: 182
Joined: Fri Aug 11, 2017 1:52 am

Re: Questions about libraries

Postby Gfast2 » Fri Dec 29, 2017 7:23 pm

Hi WiFive,

For different reasons, I've read that page +3 times. It looks like I still not picked up all what I should in "myBrain.elf" :lol:

Nice feeling. I really appreciate & enjoy your awesome jobs!!!

Cheers

Gfast2

Who is online

Users browsing this forum: Bing [Bot] and 57 guests