Discuss here different C compiler set ups, and compiling executables for the ESP8266
User avatar
By Sylvain Bissonnette
#44677 Hi,

Did you know if there is a way to use Code Blocks IDE for Arduino to work with ESP MCU? Code Blocks is a very good light weigth IDE that already work for almost all Arduino board .

Thanks for your time
Sylvain Bissonnette
User avatar
By hadipic
#69417 hi
Installation code blocks
Installation xtensa-esp108-elf
Installation pyton2.7


save code and project file name is esp32_heloo.cbp

Code: Select all<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
   <FileVersion major="1" minor="6" />
   <Project>
      <Option title="heloo" />
      <Option makefile_is_custom="1" />
      <Option pch_mode="2" />
      <Option compiler="gnu_gcc_xtensa" />
      <Build>
         <Target title="all">
            <Option output="bin/Debug/esp8226_relay" prefix_auto="1" extension_auto="1" />
            <Option object_output="obj/Debug/" />
            <Option type="1" />
            <Option compiler="gnu_gcc_xtensa" />
            <Compiler>
               <Add option="-g" />
            </Compiler>
         </Target>
         <Target title="clean">
            <Option output="esp8226_relay" prefix_auto="1" extension_auto="1" />
            <Option type="1" />
            <Option compiler="gnu_gcc_xtensa" />
         </Target>
         <Target title="flash_app">
            <Option output="esp8226_relay" prefix_auto="1" extension_auto="1" />
            <Option type="1" />
            <Option compiler="gnu_gcc_xtensa" />
         </Target>
         <Target title="htmlflash">
            <Option output="esp8226_relay" prefix_auto="1" extension_auto="1" />
            <Option type="1" />
            <Option compiler="gnu_gcc_xtensa" />
         </Target>
         <Target title="rebuild">
            <Option output="esp8226_relay" prefix_auto="1" extension_auto="1" />
            <Option type="1" />
            <Option compiler="gnu_gcc_xtensa" />
         </Target>
         <Target title="flash_blank">
            <Option output="esp8226_relay" prefix_auto="1" extension_auto="1" />
            <Option type="1" />
            <Option compiler="gnu_gcc_xtensa" />
         </Target>
         <Target title="flash_all">
            <Option output="esp8226_relay" prefix_auto="1" extension_auto="1" />
            <Option type="1" />
            <Option compiler="gnu_gcc_xtensa" />
         </Target>
         <Target title="flash_boot">
            <Option output="esp8226_relay" prefix_auto="1" extension_auto="1" />
            <Option type="1" />
            <Option compiler="gnu_gcc_xtensa" />
         </Target>
      </Build>
      <Compiler>
         <Add option="-Wall" />
      </Compiler>
      <Unit filename="Makefile" />
      <Unit filename="include/esp_common.h" />
      <Unit filename="include/user_config.h" />
      <Unit filename="user/user_main.c">
         <Option compilerVar="CC" />
      </Unit>
      <Extensions>
         <code_completion>
            <search_path add="C:\Espressif\ESP8266_SDK\include" />
         </code_completion>
         <envvars />
         <debugger />
         <lib_finder disable_auto="1" />
      </Extensions>
   </Project>
</CodeBlocks_project_file>




save code name is make file

Code: Select all
#############################################################
#    -u --no-compress
# ESP32 Root Level Makefile
#
# Version 2.1
#
# (c) 2017 by hadi bashniji
#
#############################################################

# ESP32_RTOS_SDK Makfile supported parameters
# You should modify some parameters according to your needs.

# 1. esptool parameters

# serial port, depend on your platform, default /dev/ttyUSB0
ESP_PORT = COM1

# serial baudrate, default 230400
#ESP_BAUD = 230400
ESP_BAUD = 921600


# spi flash size: 1MB/2MB/4MB/8MB/16MB, default 1MB
ESP_FS = 4MB

# spi flash freq: 40m/26m/20m/80m, default 40m
ESP_FF = 40m

# spi flash mode: qio/qout/dio/dout, default qio
ESP_FM = dio

# 2. compile & link parameters

# ld folder location choose: 0/1, default 0
#   0: use ld folder at sdk.
#   1: use local ld folder at your project.
#   NOTICE: you can copy ld folder from sdk to your project, then do some modifications.
ESP_LOCAL_LD = 0

# ld file name
#   NOTICE: if ESP_LOCAL_LD is set to 1, ESP_LD_NAME MUST be set.
# ESP_LD_FILE = pro.map.ld

# ram map mode, default 1.1
#   1.1: not use app cpu's iram, use drom0(dcache) to store rodata.
#   1.2: not use app cpu's iram, not use drom0(dcache).
#   2.1: use all app cpu's iram as pro cpu's dram, use drom0(dcache) to store rodata.
#   2.2: use all app cpu's iram as pro cpu's dram, not use drom0(dcache).
#   3.1: reverse 16K for app cpu, other as pro cpu's dram, use drom0(dcache) to store rodata.
#   3.2: reverse 16K for app cpu, other as pro cpu's dram, not use drom0(dcache).
#   NOTICE: if ESP_LOCAL_LD is set to 0, ESP_MAP_MODE CAN be set.
ESP_MAP_MODE = 1.1


#COMPILE=xcc

BUILD_BASE   = build
FW_BASE      = firmware


CPP_TOOLS_ROOT ?= C:/Espressif/xtensa-esp108-elf/xtensa-esp108-elf/bin


# Base directory for the compiler
XTENSA_TOOLS_ROOT ?= c:/Espressif/1xtensa-esp108-elf/bin


# base directory of the ESP32 SDK package, absolute
SDK_BASE   ?= c:/Espressif/ESP32_RTOS_SDK
SDK_TOOLS   ?= c:/Espressif/utils/ESP32

# esptool path and port
#ESP_TOOL ?= $(SDK_TOOLS)/esptool_esp32.exe
ESP_TOOL ?= $(SDK_TOOLS)/esptool.exe



#FLAVOR = release
FLAVOR = debug

# Verbose build output
VERBOSE = 0

ESP_COMPILE_APP_CPU ?= 0
ESP_COMBINE_APP_CPU_BIN ?= 0

# 1MB spi Flash
ifeq ($(ESP_FS), 1MB)
ESP_RFINIT_ADDR = 0xFC000
ESP_SYSPARAM_ADDR = 0xFE000
endif

# 2MB spi Flash
ifeq ($(ESP_FS), 2MB)
ESP_RFINIT_ADDR = 0x1FC000
ESP_SYSPARAM_ADDR = 0x1FE000
endif

# 4MB spi Flash
ifeq ($(ESP_FS), 4MB)
ESP_RFINIT_ADDR = 0x3FC000
ESP_SYSPARAM_ADDR = 0x3FE000
endif

# 8MB spi Flash
ifeq ($(ESP_FS), 8MB)
ESP_RFINIT_ADDR = 0x7FC000
ESP_SYSPARAM_ADDR = 0x7FE000
endif

# 16MB spi Flash
ifeq ($(ESP_FS), 16MB)
ESP_RFINIT_ADDR = 0xFFC000
ESP_SYSPARAM_ADDR = 0xFFE000
endif

ifeq ($(ESP_COMPILE_APP_CPU), 1)
   LD_FILE_CORE = $(SDK_BASE)/ld/app.map.ld
   LD_FILE = $(SDK_BASE)/ld/app.map.ld $(SDK_BASE)/ld/app.rom.addr.ld
else
   ifeq ($(ESP_LOCAL_LD), 1)
      LD_FILE_CORE = ./ld/$(ESP_LD_FILE)
      LD_FILE = $(LD_FILE_CORE) $(SDK_BASE)/ld/pro.rom.addr.ld
   else
      LD_FILE_CORE = $(SDK_BASE)/ld/pro.map$(ESP_MAP_MODE).ld
      LD_FILE = $(LD_FILE_CORE) $(SDK_BASE)/ld/pro.rom.addr.ld
   endif
endif

ifeq ($(FLAVOR),debug)
    TARGET_LDFLAGS += -g -O2
endif

ifeq ($(FLAVOR),release)
    TARGET_LDFLAGS += -g -O0
endif

# name for the target project
TARGET = eagle

# which modules (subdirectories) of the project to include in compiling
MODULES   = user
EXTRA_INCDIR = include $(SDK_BASE)/extra_include $(SDK_BASE)/third_party/include $(SDK_BASE)/third_party/include/freertos $(SDK_BASE)/third_party/include/cjson $(SDK_BASE)/third_party/include/ssl $(SDK_BASE)/third_party/include/lwip $(SDK_BASE)/third_party/include/lwip/ipv4 $(SDK_BASE)/third_party/include/lwip/ipv6

# libraries used in this project, mainly provided by the SDK
LIBS = c gcc hal m crypto freertos lwip main net80211 phy pp rtc wpa

# compiler flags using during compilation of source files -Werror
CFLAGS += $(TARGET_LDFLAGS)
CFLAGS += -Os -std=gnu90 -Wpointer-arith -Wundef  -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -mno-serialize-volatile -D__ets__ -DICACHE_FLASH

# linker flags used to generate the main object file
LDFLAGS += $(TARGET_LDFLAGS)
LDFLAGS += -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static

# various paths from the SDK used in this project
SDK_LIBDIR   = lib
SDK_LDDIR   = ld
SDK_INCDIR   = include include/esp32 include/freertos include/lwip



ifeq ($(COMPILE), xcc)
    AR := $(CPP_TOOLS_ROOT)/ar
    CC := $(CPP_TOOLS_ROOT)/c++
    LD := $(CPP_TOOLS_ROOT)/ld
    NM := $(CPP_TOOLS_ROOT)/nm
    CPP := $(CPP_TOOLS_ROOT)/g++
    OBJCOPY := $(CPP_TOOLS_ROOT)/objcopy
    OBJDUMP := $(CPP_TOOLS_ROOT)/objdump
else
  # select which tools to use as compiler, librarian and linker
 #CC   := $(XTENSA_TOOLS_ROOT)/xtensa-esp108-elf-gcc
 #AR   := $(XTENSA_TOOLS_ROOT)/xtensa-esp108-elf-ar
 #LD   := $(XTENSA_TOOLS_ROOT)/xtensa-esp108-elf-gcc
 #NM  := $(XTENSA_TOOLS_ROOT)/xtensa-esp108-elf-nm
 #cpp :=$(XTENSA_TOOLS_ROOT)/xtensa-esp108-elf-g++
 #OBJCOPY := $(XTENSA_TOOLS_ROOT)/xtensa-esp108-elf-objcopy
 #OBJDUMP := $(XTENSA_TOOLS_ROOT)/xtensa-esp108-elf-objdump

 # select which tools to use as compiler, librarian and linker
CC   := $(XTENSA_TOOLS_ROOT)/xtensa-esp32-elf-gcc
AR   := $(XTENSA_TOOLS_ROOT)/xtensa-esp32-elf-ar
LD   := $(XTENSA_TOOLS_ROOT)/xtensa-esp32-elf-gcc
NM  := $(XTENSA_TOOLS_ROOT)/xtensa-esp32-elf-nm
cpp :=$(XTENSA_TOOLS_ROOT)/xtensa-esp32-elf-g++
OBJCOPY := $(XTENSA_TOOLS_ROOT)/xtensa-esp32-elf-objcopy
OBJDUMP := $(XTENSA_TOOLS_ROOT)/xtensa-esp32-elf-objdump



endif

# no user configurable options below here
SRC_DIR      := $(MODULES)
BUILD_DIR   := $(addprefix $(BUILD_BASE)/,$(MODULES))
SDK_LIBDIR   := $(addprefix $(SDK_BASE)/,$(SDK_LIBDIR))
SDK_INCDIR   := $(addprefix -I$(SDK_BASE)/,$(SDK_INCDIR))
SRC         := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.c))
OBJ         := $(patsubst %.c,$(BUILD_BASE)/%.o,$(SRC))
LIBS      := $(addprefix -l,$(LIBS))
APP_AR      := $(addprefix $(BUILD_BASE)/,$(TARGET)_app.a)
TARGET_OUT   := $(addprefix $(BUILD_BASE)/,$(TARGET).out)
INCDIR      := $(addprefix -I,$(SRC_DIR))
EXTRA_INCDIR   := $(addprefix -I,$(EXTRA_INCDIR))
MODULE_INCDIR   := $(addsuffix /include,$(INCDIR))

V ?= $(VERBOSE)
ifeq ("$(V)","1")
Q :=
vecho := @true
else
Q := @
vecho := @echo
endif

vpath %.c $(SRC_DIR)

define compile-objects
$1/%.o: %.c
   $(vecho) "CC $$<"
   $(Q) $(CC) $(INCDIR) $(MODULE_INCDIR) $(EXTRA_INCDIR) $(SDK_INCDIR) $(CFLAGS)  -c $$< -o $$@
endef

.PHONY: all checkdirs clean fflash_all flash_boot flash_app flash_blank rebuild

all: checkdirs $(TARGET_OUT)

$(TARGET_OUT): $(APP_AR)
   $(Q) $(RM) -r $(FW_BASE)/user.S $(FW_BASE)/user.dump
   $(Q) $(OBJDUMP) -x -s $< > $(FW_BASE)/user.dump
   $(Q) $(OBJDUMP) -S $< > $(FW_BASE)/user.S
   $(vecho) "LD $@"
   $(Q) $(LD) -L$(SDK_LIBDIR) -T$(LD_FILE) $(LDFLAGS) -Wl,--start-group $(LIBS) $(APP_AR) -Wl,--end-group -o $@
   $(vecho) "Run objcopy, please wait..."
   $(Q) $(OBJCOPY) --only-section .text -O binary $@ eagle.app.v7.text.bin
   $(Q) $(OBJCOPY) --only-section .data -O binary $@ eagle.app.v7.data.bin
   $(Q) $(OBJCOPY) --only-section .rodata -O binary $@ eagle.app.v7.rodata.bin
   $(Q) $(OBJCOPY) --only-section .irom0.text -O binary $@ eagle.app.v7.irom0text.bin
   $(Q) $(OBJCOPY) --only-section .drom0.text -O binary $@ eagle.app.v7.drom0text.bin
   $(vecho) "objcopy done"
   $(vecho) "Run gen_appbin_esp32.exe"
ifeq ($(ESP_COMPILE_APP_CPU), 0)
   $(Q) $(RM) -r $(FW_BASE)/irom0_flash.bin $(FW_BASE)/drom0.bin
   $(Q) $(RM) -r $(FW_BASE)/user.ota
   $(Q) $(SDK_TOOLS)/gen_appbin_esp32.exe $@ $(LD_FILE_CORE) $(ESP_COMPILE_APP_CPU) $(ESP_COMBINE_APP_CPU_BIN) $(SDK_BASE)/bin/app_cpu.bin $(FW_BASE)
else
   @$(RM) -r $(FW_BASE)/app_cpu.bin
   $(Q) $(SDK_TOOLS)/gen_appbin_esp32.exe $@ $(LD_FILE_CORE) $(ESP_COMPILE_APP_CPU) $(ESP_COMBINE_APP_CPU_BIN) $(FW_BASE)/app_cpu.bin $(FW_BASE)
endif
   $(Q) $(RM) -f eagle.app.v7.*
   $(vecho) "$(SDK_BASE)/bin/blank.bin ----------------->$(ESP_SYSPARAM_ADDR)"

$(APP_AR): $(OBJ)
   $(vecho) "AR $@"
   $(Q) $(AR) cru $@ $^

checkdirs: $(BUILD_DIR) $(FW_BASE)

$(BUILD_DIR):
   $(Q) mkdir.exe -p $@

$(FW_BASE):
   $(Q) mkdir.exe -p $@

flash_all:
   $(ESP_TOOL) -c esp32 -p $(ESP_PORT) -b $(ESP_BAUD) write_flash  -u --no-compress -fs $(ESP_FS) -fm $(ESP_FM) -ff $(ESP_FF)   \
   0x0 $(SDK_BASE)/bin/boot.bin   \
   0x04000 $(FW_BASE)/drom0.bin 0x40000 $(FW_BASE)/irom0_flash.bin   \
   $(ESP_SYSPARAM_ADDR) $(SDK_BASE)/bin/blank.bin

flash_boot:
   $(ESP_TOOL) -c esp32 -p $(ESP_PORT) -b $(ESP_BAUD) write_flash  -fs $(ESP_FS) -fm $(ESP_FM) -ff $(ESP_FF)   \
   0x1000 $(SDK_BASE)/bin/boot.bin

flash_app:
   $(ESP_TOOL) -c esp32 -p $(ESP_PORT) -b $(ESP_BAUD) write_flash     -u --no-compress  \
    0x1000 boot1.bin 0x78000 $(FW_BASE)/drom0.bin  0x80000 $(FW_BASE)/irom0_flash.bin

flash_app1:
   $(ESP_TOOL) -c esp32 -p $(ESP_PORT) -b $(ESP_BAUD) write_flash     \
   0x10000 $(FW_BASE)/irom0_flash.bin




flash_blank:
   $(ESP_TOOL) -c esp32 -p $(ESP_PORT) -b $(ESP_BAUD) write_flash    -u --no-compress \
   $(ESP_SYSPARAM_ADDR) $(SDK_BASE)/bin/blank.bin

rebuild: clean all

clean:
   $(Q) rm -f $(APP_AR)
   $(Q) rm -f $(TARGET_OUT)
   $(Q) rm -rf $(BUILD_DIR)
   $(Q) rm -rf $(BUILD_BASE)
   $(Q) rm -rf $(FW_BASE)

$(foreach bdir,$(BUILD_DIR),$(eval $(call compile-objects,$(bdir))))