A note about how to setup project esp32 use platformio and nix
1mkdir -p ~/test/esp32
2cd ~/test/esp32
3nix flake initflake.nix in project. This is a example i use for my project.1{
2 description = "ESP32 + PlatformIO devshell";
3 inputs = {
4 nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
5 };
6
7 outputs = {
8 self,
9 nixpkgs,
10 }: let
11 system = "x86_64-linux";
12 pkgs = import nixpkgs {inherit system;};
13 in {
14 devShells.${system}.default = pkgs.mkShell {
15 packages = with pkgs; [
16 platformio
17 python3
18 gcc
19 gnumake
20 pkg-config
21 picocom
22 clang-tools # this for my setup lsp and formatter
23 ];
24
25 shellHook = ''
26 if [ -z "$ZSH_VERSION" ]; then
27 export SHELL=${pkgs.zsh}/bin/zsh
28 exec ${pkgs.zsh}/bin/zsh -l
29 fi
30 '';
31 };
32 };
33}nix develop in project.arduino framework:1pio project init --board esp32dev --project-option "framework=arduino"espidf framework:1pio project init --board esp32dev --project-option "framework=espidf"1pio run -t compiledb.clangd in root of project.1CompileFlags:
2 Add:
3 - "-ferror-limit=0"
4 - "-Wno-unknown-attributes"
5 - "-Wno-ignored-attributes"
6 Remove:
7 # Xtensa-specific flags unsupported by clang
8 - "-mlongcalls"
9 - "-mtext-section-literals"
10 - "-fstrict-volatile-bitfields"
11 - "-fno-tree-switch-conversion"
12 - "-fno-jump-tables"
13 # ESP-IDF specific
14 - "-fno-rtti"
15 - "-fno-exceptions"
16 - "-mfix-esp32-psram-cache-issue"
17 - "-mfix-esp32-psram-cache-strategy=*"
18 # GCC-specific warnings clang doesn't know
19 - "-Wno-frame-address"
20 - "-Wno-error=unused-but-set-variable"
21 - "-freorder-blocks"
22 Compiler: clang++
23Diagnostics:
24 Suppress:
25 # Missing Arduino/ESP headers (framework quirks)
26 - pp_file_not_found
27 # Arduino Print class overload resolution
28 - ovl_no_viable_member_function_in_call
29 - ovl_no_viable_function_in_call
30 # Template issues with Arduino libraries
31 - typecheck_invalid_operands
32 - typecheck_nonviable_condition
33 # ESP-IDF macro expansions
34 - builtin_requires_header
35 - implicit_function_decl
36 UnusedIncludes: None
37 MissingIncludes: None1pio run # run project
2pio run -t upload # upload project
3pio device monitor # monitor deviceplatformio.ini after use pio lib install.1# use command
2pio lib install <LIB_NAME>1[env:esp32dev]
2platform = espressif32
3board = esp32dev
4framework = arduino
5monitor_speed = 115200
6
7lib_deps =
8 adafruit/Adafruit SSD1306
9 adafruit/Adafruit GFX LibraryGet notified when I publish new articles, tutorials, and project updates. Subscribe for insights and actionable content.