Can we include Microchip MCC generated code as a library?

Hey there.
I’m stumbling in the dark, and I started thinking that maybe this is not actually feasible but didn’t want to quit without asking first.
And at the end of the day, I’m using this project as an excuse to learn platformio’s structure.

  • I created a blink LED project in MPLABX and generated code with MCC Melody
  • copy/pasted that code outside and created a library with it
  • packaged the library with pio pkg pack . while being in the library directory, and obtained a .zip file
  • used the zip file to install it while being in the root of my simple project with pio pkg install file://path_to_the_zip_file
  • this succesfully created automatically a lib_deps entry in my platformio.ini file
  • When tried to compile I get an error saying that can’t find one of the defines used in the MCC generated code, which lives in the file ioavr128da48.h which in turn is part of the XC8 extended includes.
Processing AVR128DA48 (platform: avr128da; board: curiosity_nano_da; framework: arduino)
-----------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/avr128da/curiosity_nano_da.html
PLATFORM: AVR 128DA MCU Platform (0.0.1) > Curiosity Nano AVR128DA48
HARDWARE: AVR128DA48 24MHz, 16KB RAM, 128KB Flash
PACKAGES:
 - framework-arduino-megaavr-dxcore @ 1.4.10
 - toolchain-atmelavr @ 3.70300.220127 (7.3.0)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 18 compatible libraries
Scanning dependencies...
Dependency Graph
|-- Hola_LED_AVR128_MCHP_MCC @ 0.0.6
Building in release mode
Compiling .pio\build\AVR128DA48\libdb0\Hola_LED_AVR128_MCHP_MCC\mcc_generated_files\system\src\clock.c.o
Compiling .pio\build\AVR128DA48\libdb0\Hola_LED_AVR128_MCHP_MCC\mcc_generated_files\system\src\config_bits.c.o
Compiling .pio\build\AVR128DA48\libdb0\Hola_LED_AVR128_MCHP_MCC\mcc_generated_files\system\src\interrupt.c.o
Compiling .pio\build\AVR128DA48\libdb0\Hola_LED_AVR128_MCHP_MCC\mcc_generated_files\system\src\pins.c.o
.pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC\src\mcc_generated_files\system\src\pins.c: In function '__vector_29':
.pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC\src\mcc_generated_files\system\src\pins.c:152:26: error: 'PORT_INT6_bm' undeclared (first use in this function); did you mean 'PORT_ISC2_bm'?
     if(VPORTC.INTFLAGS & PORT_INT6_bm)
                          ^~~~~~~~~~~~
                          PORT_ISC2_bm
.pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC\src\mcc_generated_files\system\src\pins.c:152:26: note: each undeclared identifier is reported only once for each function it appears in
Compiling .pio\build\AVR128DA48\libdb0\Hola_LED_AVR128_MCHP_MCC\mcc_generated_files\system\src\protected_io.S.o
*** [.pio\build\AVR128DA48\libdb0\Hola_LED_AVR128_MCHP_MCC\mcc_generated_files\system\src\pins.c.o] Error 1
============================== [FAILED] Took 2.62 seconds ==============================

Now, this error relates a lot to this entry Build_flags with -I and dependant libraries and maybe even with AVR programming without arduino framework , but using lib_extra_dirs didn’t seem to be the actual issue I have (I think)

I aknowledge that my current library.json is not very good, and is poiting a -I to an absolute path, and that it should be relative to the root directory where library.json is, but then, still not part of the solution.

However, this being a somewhat specific subject (using MCC generated code) I wanted create a topic about it, and hear you out.

Thank you so much for everything.

I think you’re missing a macro definition that identifiers your chip. Copying all files of a reference project is half the rent, all the compiler invocations should be the same too (at least regarding -mmcu, -D flags, -I etc.).

Open a CLI and execute pio run -j1 -v to get the compiler invocation + error and post it here.

Can you equivalently do a verbose compilation in the reference project where all avr-gcc invocations are visible, and post that log here too?

2 Likes

Sorry for the delay, weekdays are crazy for me.
OK

  • First, reference project is using xc8 not avr-gcc
  • Second, here’s the result of pio run -j1 -v:
Processing AVR128DA48 (platform: avr128da; board: curiosity_nano_da; framework: arduino; lib_deps: file://C:\Users\rafae\global_packages\Hola_LED_AVR128_MCHP_MCC-0.0.6.tar.gz)
----------------------------------------------------------------------------------------------------------------------------
CONFIGURATION: https://docs.platformio.org/page/boards/avr128da/curiosity_nano_da.html
PLATFORM: AVR 128DA MCU Platform (0.0.1) (file://C:\Users\rafae\OneDrive\Documents\platform-avr128da) > Curiosity Nano AVR128DA48
HARDWARE: AVR128DA48 24MHz, 16KB RAM, 128KB Flash
PACKAGES:
 - framework-arduino-megaavr-dxcore @ 1.4.10
 - toolchain-atmelavr @ 3.70300.220127 (7.3.0)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 18 compatible libraries
Scanning dependencies...
Dependency Graph
|-- Hola_LED_AVR128_MCHP_MCC @ 0.0.6 (License: Apache-2.0, URI: file://C:\Users\rafae\global_packages\Hola_LED_AVR128_MCHP_MCC-0.0.6.tar.gz, Path: C:\Users\rafae\OneDrive\Documents\PIO_ws\blink_led_test_mod_platform\.pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC)
Building in release mode
avr-gcc -o .pio\build\AVR128DA48\libdb0\Hola_LED_AVR128_MCHP_MCC\mcc_generated_files\system\src\clock.c.o -c -std=gnu11 -fno-fat-lto-objects -mmcu=avr128da48 -Os -w -ffunction-sections -fdata-sections -flto -mrelax -DPLATFORMIO=60105 -DARDUINO_AVR_AVR128DA48 -DARDUINO_avrda -DLED_BUILTIN=PIN_PC6 -DF_CPU=24000000L -DARDUINO_ARCH_MEGAAVR -DARDUINO=10808 -DCLOCK_SOURCE=0 -DDXCORE=\"1.4.10\" -DDXCORE_MAJOR=1UL -DDXCORE_MINOR=4UL -DDXCORE_PATCH=10UL -DDXCORE_RELEASED=1 -DCORE_ATTACH_ALL -DTWI_MORS_SINGLE -DMILLIS_USE_TIMERB2 -I.pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC -I.pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC\src -IC:\Users\rafae\.platformio\packages\framework-arduino-megaavr-dxcore\cores\dxcore\api\deprecated -IC:\Users\rafae\.platformio\packages\framework-arduino-megaavr-dxcore\cores\dxcore -IC:\Users\rafae\.platformio\packages\framework-arduino-megaavr-dxcore\variants\48pin-standard -IC:\Program .pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC\src\mcc_generated_files\system\src\clock.c
avr-gcc -o .pio\build\AVR128DA48\libdb0\Hola_LED_AVR128_MCHP_MCC\mcc_generated_files\system\src\config_bits.c.o -c -std=gnu11 -fno-fat-lto-objects -mmcu=avr128da48 -Os -w -ffunction-sections -fdata-sections -flto -mrelax -DPLATFORMIO=60105 -DARDUINO_AVR_AVR128DA48 -DARDUINO_avrda -DLED_BUILTIN=PIN_PC6 -DF_CPU=24000000L -DARDUINO_ARCH_MEGAAVR -DARDUINO=10808 -DCLOCK_SOURCE=0 -DDXCORE=\"1.4.10\" -DDXCORE_MAJOR=1UL -DDXCORE_MINOR=4UL -DDXCORE_PATCH=10UL -DDXCORE_RELEASED=1 -DCORE_ATTACH_ALL -DTWI_MORS_SINGLE -DMILLIS_USE_TIMERB2 -I.pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC -I.pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC\src -IC:\Users\rafae\.platformio\packages\framework-arduino-megaavr-dxcore\cores\dxcore\api\deprecated -IC:\Users\rafae\.platformio\packages\framework-arduino-megaavr-dxcore\cores\dxcore -IC:\Users\rafae\.platformio\packages\framework-arduino-megaavr-dxcore\variants\48pin-standard -IC:\Program .pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC\src\mcc_generated_files\system\src\config_bits.c
avr-gcc -o .pio\build\AVR128DA48\libdb0\Hola_LED_AVR128_MCHP_MCC\mcc_generated_files\system\src\interrupt.c.o -c -std=gnu11 -fno-fat-lto-objects -mmcu=avr128da48 -Os -w -ffunction-sections -fdata-sections -flto -mrelax -DPLATFORMIO=60105 -DARDUINO_AVR_AVR128DA48 -DARDUINO_avrda -DLED_BUILTIN=PIN_PC6 -DF_CPU=24000000L -DARDUINO_ARCH_MEGAAVR -DARDUINO=10808 -DCLOCK_SOURCE=0 -DDXCORE=\"1.4.10\" -DDXCORE_MAJOR=1UL -DDXCORE_MINOR=4UL -DDXCORE_PATCH=10UL -DDXCORE_RELEASED=1 -DCORE_ATTACH_ALL -DTWI_MORS_SINGLE -DMILLIS_USE_TIMERB2 -I.pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC -I.pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC\src -IC:\Users\rafae\.platformio\packages\framework-arduino-megaavr-dxcore\cores\dxcore\api\deprecated -IC:\Users\rafae\.platformio\packages\framework-arduino-megaavr-dxcore\cores\dxcore -IC:\Users\rafae\.platformio\packages\framework-arduino-megaavr-dxcore\variants\48pin-standard -IC:\Program .pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC\src\mcc_generated_files\system\src\interrupt.c
avr-gcc -o .pio\build\AVR128DA48\libdb0\Hola_LED_AVR128_MCHP_MCC\mcc_generated_files\system\src\pins.c.o -c -std=gnu11 -fno-fat-lto-objects -mmcu=avr128da48 -Os -w -ffunction-sections -fdata-sections -flto -mrelax -DPLATFORMIO=60105 -DARDUINO_AVR_AVR128DA48 -DARDUINO_avrda -DLED_BUILTIN=PIN_PC6 -DF_CPU=24000000L -DARDUINO_ARCH_MEGAAVR -DARDUINO=10808 -DCLOCK_SOURCE=0 -DDXCORE=\"1.4.10\" -DDXCORE_MAJOR=1UL -DDXCORE_MINOR=4UL -DDXCORE_PATCH=10UL -DDXCORE_RELEASED=1 -DCORE_ATTACH_ALL -DTWI_MORS_SINGLE -DMILLIS_USE_TIMERB2 -I.pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC -I.pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC\src -IC:\Users\rafae\.platformio\packages\framework-arduino-megaavr-dxcore\cores\dxcore\api\deprecated -IC:\Users\rafae\.platformio\packages\framework-arduino-megaavr-dxcore\cores\dxcore -IC:\Users\rafae\.platformio\packages\framework-arduino-megaavr-dxcore\variants\48pin-standard -IC:\Program .pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC\src\mcc_generated_files\system\src\pins.c
.pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC\src\mcc_generated_files\system\src\pins.c: In function '__vector_29':
.pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC\src\mcc_generated_files\system\src\pins.c:152:26: error: 'PORT_INT6_bm' undeclared (first use in this function); did you mean 'PORT_ISC2_bm'?
     if(VPORTC.INTFLAGS & PORT_INT6_bm)
                          ^~~~~~~~~~~~
                          PORT_ISC2_bm
.pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC\src\mcc_generated_files\system\src\pins.c:152:26: note: each undeclared identifier is reported only once for each function it appears in
*** [.pio\build\AVR128DA48\libdb0\Hola_LED_AVR128_MCHP_MCC\mcc_generated_files\system\src\pins.c.o] Error 1

And this is the trace of the reference project, in MPLABX 6:

CLEAN SUCCESSFUL (total time: 47ms)
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory 'C:/Users/rafae/MPLAB_ws/basic_mcc_blink.X'
make  -f nbproject/Makefile-default.mk dist/default/production/basic_mcc_blink.X.production.hex
make[2]: Entering directory 'C:/Users/rafae/MPLAB_ws/basic_mcc_blink.X'
"C:\Program Files\Microchip\xc8\v2.40\bin\xc8-cc.exe"  -mcpu=AVR128DA48 -c  -x c -D__AVR128DA48__   -mdfp="C:/Program Files/Microchip/MPLABX/v6.00/packs/Microchip/AVR-Dx_DFP/1.10.124/xc8"  -Wl,--gc-sections -O1 -ffunction-sections -fdata-sections -fshort-enums -fno-common -funsigned-char -funsigned-bitfields -Wall -DXPRJ_default=default    -gdwarf-3     -MD -MP -MF "build/default/production/mcc_generated_files/system/src/pins.o.d" -MT "build/default/production/mcc_generated_files/system/src/pins.o.d" -MT build/default/production/mcc_generated_files/system/src/pins.o -o build/default/production/mcc_generated_files/system/src/pins.o mcc_generated_files/system/src/pins.c 
"C:\Program Files\Microchip\xc8\v2.40\bin\xc8-cc.exe"  -mcpu=AVR128DA48 -c  -x c -D__AVR128DA48__   -mdfp="C:/Program Files/Microchip/MPLABX/v6.00/packs/Microchip/AVR-Dx_DFP/1.10.124/xc8"  -Wl,--gc-sections -O1 -ffunction-sections -fdata-sections -fshort-enums -fno-common -funsigned-char -funsigned-bitfields -Wall -DXPRJ_default=default    -gdwarf-3     -MD -MP -MF "build/default/production/mcc_generated_files/system/src/clock.o.d" -MT "build/default/production/mcc_generated_files/system/src/clock.o.d" -MT build/default/production/mcc_generated_files/system/src/clock.o -o build/default/production/mcc_generated_files/system/src/clock.o mcc_generated_files/system/src/clock.c 
"C:\Program Files\Microchip\xc8\v2.40\bin\xc8-cc.exe"  -mcpu=AVR128DA48 -c  -x c -D__AVR128DA48__   -mdfp="C:/Program Files/Microchip/MPLABX/v6.00/packs/Microchip/AVR-Dx_DFP/1.10.124/xc8"  -Wl,--gc-sections -O1 -ffunction-sections -fdata-sections -fshort-enums -fno-common -funsigned-char -funsigned-bitfields -Wall -DXPRJ_default=default    -gdwarf-3     -MD -MP -MF "build/default/production/mcc_generated_files/system/src/interrupt.o.d" -MT "build/default/production/mcc_generated_files/system/src/interrupt.o.d" -MT build/default/production/mcc_generated_files/system/src/interrupt.o -o build/default/production/mcc_generated_files/system/src/interrupt.o mcc_generated_files/system/src/interrupt.c 
"C:\Program Files\Microchip\xc8\v2.40\bin\xc8-cc.exe"  -mcpu=AVR128DA48 -c  -x c -D__AVR128DA48__   -mdfp="C:/Program Files/Microchip/MPLABX/v6.00/packs/Microchip/AVR-Dx_DFP/1.10.124/xc8"  -Wl,--gc-sections -O1 -ffunction-sections -fdata-sections -fshort-enums -fno-common -funsigned-char -funsigned-bitfields -Wall -DXPRJ_default=default    -gdwarf-3     -MD -MP -MF "build/default/production/mcc_generated_files/system/src/config_bits.o.d" -MT "build/default/production/mcc_generated_files/system/src/config_bits.o.d" -MT build/default/production/mcc_generated_files/system/src/config_bits.o -o build/default/production/mcc_generated_files/system/src/config_bits.o mcc_generated_files/system/src/config_bits.c 
"C:\Program Files\Microchip\xc8\v2.40\bin\xc8-cc.exe" -c  -mcpu=AVR128DA48  -x assembler-with-cpp -D__AVR128DA48__   -mdfp="C:/Program Files/Microchip/MPLABX/v6.00/packs/Microchip/AVR-Dx_DFP/1.10.124/xc8"  -Wl,--gc-sections -O1 -ffunction-sections -fdata-sections -fshort-enums -fno-common -funsigned-char -funsigned-bitfields -Wall -DXPRJ_default=default  -gdwarf-3 -Wa,--defsym=__MPLAB_BUILD=1   -MD -MP -MF "build/default/production/mcc_generated_files/system/src/protected_io.o.d" -MT "build/default/production/mcc_generated_files/system/src/protected_io.o.d" -MT build/default/production/mcc_generated_files/system/src/protected_io.o -o build/default/production/mcc_generated_files/system/src/protected_io.o  mcc_generated_files/system/src/protected_io.S 
"C:\Program Files\Microchip\xc8\v2.40\bin\xc8-cc.exe"  -mcpu=AVR128DA48 -c  -x c -D__AVR128DA48__   -mdfp="C:/Program Files/Microchip/MPLABX/v6.00/packs/Microchip/AVR-Dx_DFP/1.10.124/xc8"  -Wl,--gc-sections -O1 -ffunction-sections -fdata-sections -fshort-enums -fno-common -funsigned-char -funsigned-bitfields -Wall -DXPRJ_default=default    -gdwarf-3     -MD -MP -MF "build/default/production/mcc_generated_files/system/src/system.o.d" -MT "build/default/production/mcc_generated_files/system/src/system.o.d" -MT build/default/production/mcc_generated_files/system/src/system.o -o build/default/production/mcc_generated_files/system/src/system.o mcc_generated_files/system/src/system.c 
"C:\Program Files\Microchip\xc8\v2.40\bin\xc8-cc.exe"  -mcpu=AVR128DA48 -c  -x c -D__AVR128DA48__   -mdfp="C:/Program Files/Microchip/MPLABX/v6.00/packs/Microchip/AVR-Dx_DFP/1.10.124/xc8"  -Wl,--gc-sections -O1 -ffunction-sections -fdata-sections -fshort-enums -fno-common -funsigned-char -funsigned-bitfields -Wall -DXPRJ_default=default    -gdwarf-3     -MD -MP -MF "build/default/production/main.o.d" -MT "build/default/production/main.o.d" -MT build/default/production/main.o -o build/default/production/main.o main.c 
"C:\Program Files\Microchip\xc8\v2.40\bin\xc8-cc.exe"  -mcpu=AVR128DA48 -c  -x c -D__AVR128DA48__   -mdfp="C:/Program Files/Microchip/MPLABX/v6.00/packs/Microchip/AVR-Dx_DFP/1.10.124/xc8"  -Wl,--gc-sections -O1 -ffunction-sections -fdata-sections -fshort-enums -fno-common -funsigned-char -funsigned-bitfields -Wall -DXPRJ_default=default    -gdwarf-3     -MD -MP -MF "build/default/production/mcc_generated_files/timer/src/delay.o.d" -MT "build/default/production/mcc_generated_files/timer/src/delay.o.d" -MT build/default/production/mcc_generated_files/timer/src/delay.o -o build/default/production/mcc_generated_files/timer/src/delay.o mcc_generated_files/timer/src/delay.c 
"C:\Program Files\Microchip\xc8\v2.40\bin\xc8-cc.exe"  -mcpu=AVR128DA48 -Wl,-Map=dist/default/production/basic_mcc_blink.X.production.map  -DXPRJ_default=default  -Wl,--defsym=__MPLAB_BUILD=1   -mdfp="C:/Program Files/Microchip/MPLABX/v6.00/packs/Microchip/AVR-Dx_DFP/1.10.124/xc8"  -Wl,--gc-sections -O1 -ffunction-sections -fdata-sections -fshort-enums -fno-common -funsigned-char -funsigned-bitfields -Wall -gdwarf-3      -Wl,--memorysummary,dist/default/production/memoryfile.xml -o dist/default/production/basic_mcc_blink.X.production.elf  -o dist/default/production/basic_mcc_blink.X.production.elf  build/default/production/mcc_generated_files/system/src/pins.o build/default/production/mcc_generated_files/system/src/clock.o build/default/production/mcc_generated_files/system/src/protected_io.o build/default/production/mcc_generated_files/system/src/interrupt.o build/default/production/mcc_generated_files/system/src/config_bits.o build/default/production/mcc_generated_files/system/src/system.o build/default/production/mcc_generated_files/timer/src/delay.o build/default/production/main.o      -Wl,--start-group  -Wl,-lm -Wl,--end-group 
Info: Loading file: c:\program files\microchip\xc8\v2.40\avr\avr\bin\../lib\ldscripts/avrxmega4.xn
"C:\Program Files\Microchip\xc8\v2.40\bin"\\avr-objcopy -O ihex "dist/default/production/basic_mcc_blink.X.production.elf" "dist/default/production/basic_mcc_blink.X.production.hex"
make[2]: Leaving directory 'C:/Users/rafae/MPLAB_ws/basic_mcc_blink.X'
make[1]: Leaving directory 'C:/Users/rafae/MPLAB_ws/basic_mcc_blink.X'

BUILD SUCCESSFUL (total time: 7s)

Maybe I need to configure my platform to build with XC8 first?
If that’s the acse, would you have any information/posts related to that?

Thank you

So when you look at the -D defines that PlatformIO uses

and the real project uses

There’s -D__AVR128DA48__ missing, just as I predicted in

You can e.g. add it to your board’s JSON file in the extra_flags.

I have been bashing my head against the wall with this for quite some time, I can include the D__AVR128DA48__ in the definitions (I added it to the board in my modified platform)

Processing AVR128DA48 (platform: avr128da; board: curiosity_nano_da; framework: arduino; lib_deps: file://C:\Users\rafae\global_packages\Hola_LED_AVR128_MCHP_MCC-0.0.7.tar.gz)
----------------------------------------------------------------------------------------------
CONFIGURATION: https://docs.platformio.org/page/boards/avr128da/curiosity_nano_da.html
PLATFORM: AVR 128DA MCU Platform (0.0.3) (file://C:\Users\rafae\OneDrive\Documents\platform-avr128da) > Curiosity Nano AVR128DA48
HARDWARE: AVR128DA48 24MHz, 16KB RAM, 128KB Flash
PACKAGES:
 - framework-arduino-megaavr-dxcore @ 1.4.10
 - toolchain-atmelavr @ 3.70300.220127 (7.3.0)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 18 compatible libraries
Scanning dependencies...
Dependency Graph
|-- Hola_LED_AVR128_MCHP_MCC @ 0.0.7 (License: Apache-2.0, URI: file://C:\Users\rafae\global_packages\Hola_LED_AVR128_MCHP_MCC-0.0.7.tar.gz, Path: C:\Users\rafae\OneDrive\Documents\PIO_ws\blink_led_test_mod_platform\.pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC)
Building in release mode
avr-gcc -o .pio\build\AVR128DA48\libdb0\Hola_LED_AVR128_MCHP_MCC\mcc_generated_files\system\src\clock.c.o -c -std=gnu11 -fno-fat-lto-objects -std=c99 -mmcu=avr128da48 -Os -w -ffunction-sections -fdata-sections -flto -mrelax -DPLATFORMIO=60105 -DARDUINO_AVR_AVR128DA48 -DARDUINO_avrda -DLED_BUILTIN=PIN_PC6 -D__AVR128DA48__ -DF_CPU=24000000L -DARDUINO_ARCH_MEGAAVR -DARDUINO=10808 -DCLOCK_SOURCE=0 -DDXCORE=\"1.4.10\" -DDXCORE_MAJOR=1UL -DDXCORE_MINOR=4UL -DDXCORE_PATCH=10UL -DDXCORE_RELEASED=1 -DCORE_ATTACH_ALL -DTWI_MORS_SINGLE -DMILLIS_USE_TIMERB2 -I.pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC -I.pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC\src -IC:\Users\rafae\.platformio\packages\framework-arduino-megaavr-dxcore\cores\dxcore\api\deprecated -IC:\Users\rafae\.platformio\packages\framework-arduino-megaavr-dxcore\cores\dxcore -IC:\Users\rafae\.platformio\packages\framework-arduino-megaavr-dxcore\variants\48pin-standard .pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC\src\mcc_generated_files\system\src\clock.c
avr-gcc -o .pio\build\AVR128DA48\libdb0\Hola_LED_AVR128_MCHP_MCC\mcc_generated_files\system\src\config_bits.c.o -c -std=gnu11 -fno-fat-lto-objects -std=c99 -mmcu=avr128da48 -Os -w -ffunction-sections -fdata-sections -flto -mrelax -DPLATFORMIO=60105 -DARDUINO_AVR_AVR128DA48 -DARDUINO_avrda -DLED_BUILTIN=PIN_PC6 -D__AVR128DA48__ -DF_CPU=24000000L -DARDUINO_ARCH_MEGAAVR -DARDUINO=10808 -DCLOCK_SOURCE=0 -DDXCORE=\"1.4.10\" -DDXCORE_MAJOR=1UL -DDXCORE_MINOR=4UL -DDXCORE_PATCH=10UL -DDXCORE_RELEASED=1 -DCORE_ATTACH_ALL -DTWI_MORS_SINGLE -DMILLIS_USE_TIMERB2 -I.pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC -I.pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC\src -IC:\Users\rafae\.platformio\packages\framework-arduino-megaavr-dxcore\cores\dxcore\api\deprecated -IC:\Users\rafae\.platformio\packages\framework-arduino-megaavr-dxcore\cores\dxcore -IC:\Users\rafae\.platformio\packages\framework-arduino-megaavr-dxcore\variants\48pin-standard .pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC\src\mcc_generated_files\system\src\config_bits.c
avr-gcc -o .pio\build\AVR128DA48\libdb0\Hola_LED_AVR128_MCHP_MCC\mcc_generated_files\system\src\interrupt.c.o -c -std=gnu11 -fno-fat-lto-objects -std=c99 -mmcu=avr128da48 -Os -w -ffunction-sections -fdata-sections -flto -mrelax -DPLATFORMIO=60105 -DARDUINO_AVR_AVR128DA48 -DARDUINO_avrda -DLED_BUILTIN=PIN_PC6 -D__AVR128DA48__ -DF_CPU=24000000L -DARDUINO_ARCH_MEGAAVR -DARDUINO=10808 -DCLOCK_SOURCE=0 -DDXCORE=\"1.4.10\" -DDXCORE_MAJOR=1UL -DDXCORE_MINOR=4UL -DDXCORE_PATCH=10UL -DDXCORE_RELEASED=1 -DCORE_ATTACH_ALL -DTWI_MORS_SINGLE -DMILLIS_USE_TIMERB2 -I.pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC -I.pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC\src -IC:\Users\rafae\.platformio\packages\framework-arduino-megaavr-dxcore\cores\dxcore\api\deprecated -IC:\Users\rafae\.platformio\packages\framework-arduino-megaavr-dxcore\cores\dxcore -IC:\Users\rafae\.platformio\packages\framework-arduino-megaavr-dxcore\variants\48pin-standard .pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC\src\mcc_generated_files\system\src\interrupt.c
avr-gcc -o .pio\build\AVR128DA48\libdb0\Hola_LED_AVR128_MCHP_MCC\mcc_generated_files\system\src\pins.c.o -c -std=gnu11 -fno-fat-lto-objects -std=c99 -mmcu=avr128da48 -Os -w -ffunction-sections -fdata-sections -flto -mrelax -DPLATFORMIO=60105 -DARDUINO_AVR_AVR128DA48 -DARDUINO_avrda -DLED_BUILTIN=PIN_PC6 -D__AVR128DA48__ -DF_CPU=24000000L -DARDUINO_ARCH_MEGAAVR -DARDUINO=10808 -DCLOCK_SOURCE=0 -DDXCORE=\"1.4.10\" -DDXCORE_MAJOR=1UL -DDXCORE_MINOR=4UL -DDXCORE_PATCH=10UL -DDXCORE_RELEASED=1 -DCORE_ATTACH_ALL -DTWI_MORS_SINGLE -DMILLIS_USE_TIMERB2 -I.pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC -I.pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC\src -IC:\Users\rafae\.platformio\packages\framework-arduino-megaavr-dxcore\cores\dxcore\api\deprecated -IC:\Users\rafae\.platformio\packages\framework-arduino-megaavr-dxcore\cores\dxcore -IC:\Users\rafae\.platformio\packages\framework-arduino-megaavr-dxcore\variants\48pin-standard .pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC\src\mcc_generated_files\system\src\pins.c
.pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC\src\mcc_generated_files\system\src\pins.c: In function '__vector_29':
.pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC\src\mcc_generated_files\system\src\pins.c:152:26: error: 'PORT_INT6_bm' undeclared (first use in this function); did you mean 'PORT_ISC2_bm'?
     if(VPORTC.INTFLAGS & PORT_INT6_bm)
                          ^~~~~~~~~~~~
                          PORT_ISC2_bm
.pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC\src\mcc_generated_files\system\src\pins.c:152:26: note: each undeclared identifier is reported only once for each function it appears in   
*** [.pio\build\AVR128DA48\libdb0\Hola_LED_AVR128_MCHP_MCC\mcc_generated_files\system\src\pins.c.o] Error 1
================================= [FAILED] Took 3.24 seconds =================================

The error persists, and since PORT_INT6_bm and it’s definition live in ioavr128da48.h (which gets installed in theXC8 <root_of_installation>\Microchip\xc8\v2.40\dfp\xc8\avr\include\avr), I included that file into the library build.flags:

"flags": "-std=c99 -include include/ioavr128da48.h",

But then I have an unexpected error instead (which I have seen before in other cases where the inculsion directories are wrongly configured, but could be other reason)

#  error "Include <avr/io.h> instead of this file."

Because avr/io.h is included in the system/utils/compiler.h within that library, and the order in which the functions are included suggests that the inclusions should happen in the correct sequence, I started thinking, that may be the order in which those files are being compiled is not correct?, do I need to specify dependencies between them somehow?

For the test’s sake, I added the places where avr/io.h and ioavr128da48.h.h are, as -I in the library’s build.flags (as the -D earlier)
The original paths were something like this:

<Installation base>/Microchip/xc8/v2.40/avr/lib/gcc/avr/5.4.0/include
<Installation base>/Microchip/xc8/v2.40/dfp/xc8/avr/include/avr
<Installation base>/Microchip/xc8/v2.40/avr/avr/include/avr

Then I copied them into a directory path that doesn’t have the ‘space’ that ‘Program Files’ does, so they ended up as one string:

Processing AVR128DA48 (platform: avr128da; board: curiosity_nano_da; framework: arduino; lib_deps: file://C:\Users\rafae\global_packages\Hola_LED_AVR128_MCHP_MCC-0.0.7.tar.gz)
----------------------------------------------------------------------------------------------
CONFIGURATION: https://docs.platformio.org/page/boards/avr128da/curiosity_nano_da.html
PLATFORM: AVR 128DA MCU Platform (0.0.3) (file://C:\Users\rafae\OneDrive\Documents\platform-avr128da) > Curiosity Nano AVR128DA48
HARDWARE: AVR128DA48 24MHz, 16KB RAM, 128KB Flash
PACKAGES:
 - framework-arduino-megaavr-dxcore @ 1.4.10
 - toolchain-atmelavr @ 3.70300.220127 (7.3.0)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 18 compatible libraries
Scanning dependencies...
Dependency Graph
|-- Hola_LED_AVR128_MCHP_MCC @ 0.0.7 (License: Apache-2.0, URI: file://C:\Users\rafae\global_packages\Hola_LED_AVR128_MCHP_MCC-0.0.7.tar.gz, Path: C:\Users\rafae\OneDrive\Documents\PIO_ws\blink_led_test_mod_platform\.pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC)
Building in release mode
avr-gcc -o .pio\build\AVR128DA48\libdb0\Hola_LED_AVR128_MCHP_MCC\mcc_generated_files\system\src\pins.c.o -c -std=gnu11 -fno-fat-lto-objects -std=c99 -mmcu=avr128da48 -Os -w -ffunction-sections -fdata-sections -flto -mrelax -DPLATFORMIO=60105 -DARDUINO_AVR_AVR128DA48 -DARDUINO_avrda -DLED_BUILTIN=PIN_PC6 -D__AVR128DA48__ -DF_CPU=24000000L -DARDUINO_ARCH_MEGAAVR -DARDUINO=10808 -DCLOCK_SOURCE=0 -DDXCORE=\"1.4.10\" -DDXCORE_MAJOR=1UL -DDXCORE_MINOR=4UL -DDXCORE_PATCH=10UL -DDXCORE_RELEASED=1 -DCORE_ATTACH_ALL -DTWI_MORS_SINGLE -DMILLIS_USE_TIMERB2 -I.pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC -I.pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC\src -IC:\Users\rafae\.platformio\packages\framework-arduino-megaavr-dxcore\cores\dxcore\api\deprecated -IC:\Users\rafae\.platformio\packages\framework-arduino-megaavr-dxcore\cores\dxcore -IC:\Users\rafae\.platformio\packages\framework-arduino-megaavr-dxcore\variants\48pin-standard -IC:\tmp\gcc_avr_5.4.0_include -IC:\tmp\dfp_xc8_avr_include -IC:\tmp\avr_include .pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC\src\mcc_generated_files\system\src\pins.c
.pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC\src\mcc_generated_files\system\src\pins.c: In function '__vector_29':
.pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC\src\mcc_generated_files\system\src\pins.c:152:26: error: 'PORT_INT6_bm' undeclared (first use in this function); did you mean 'PORT_ISC2_bm'?
     if(VPORTC.INTFLAGS & PORT_INT6_bm)
                          ^~~~~~~~~~~~
                          PORT_ISC2_bm
.pio\libdeps\AVR128DA48\Hola_LED_AVR128_MCHP_MCC\src\mcc_generated_files\system\src\pins.c:152:26: note: each undeclared identifier is reported only once for each function it appears in   
*** [.pio\build\AVR128DA48\libdb0\Hola_LED_AVR128_MCHP_MCC\mcc_generated_files\system\src\pins.c.o] Error 1
================================= [FAILED] Took 2.03 seconds =================================

Thanks for all your help

Can you upload all needed files for the project for reproduction?

Sure thing, all what you need to replicate what I did in my last comment:

  • Modified platform
  • The library (that contains the MCC generated code)
  • The external includes
    • The /tmp/gcc_avr_5.4.0_include (coming from /Microchip/xc8/v2.40/avr/lib/gcc/avr/5.4.0/include)
    • The /tmp/dfp_xc8_avr_include (coming from /Microchip/xc8/v2.40/dfp/xc8/avr/include/avr)
    • The /tmp/avr_include (coming from /Microchip/xc8/v2.40/avr/avr/include/avr)
  • The main project where the platform and library are installed in.

Steps I took to create the above files:

  1. Created a new project with the AVR128DA48 board, under atmelmegaavr platform using PIO Home UI
  2. Modified the platformio.ini in the main project blink_led_test_moded_platform to use curiosity_nano_da board instaed of the avr128da48
  3. Cloned the library and the modified platform
  4. Install the platform with pio pkg install --platform <path_to_platform> while in the root directory of the project
  5. Pack the library with pio pkg pack ., while being in the libraries root directory
  6. Copy the .zip file (packed library) into a known location that can be used to install them into the project
  7. Install library into project blink_led_test_moded_platform with pio pkg install --library <path_to_zip_library>.zip while being in the root folder of the said project
  8. Copied the external includes into the C:\tmp directory

Please let me know any questions

I’m starting to think that maybe I tried to address too many things at a time.
I’ll try to compile the project including the files in it, instead of using an external library, and an added HAL naming layer (which is a very thin one, but still could bring confusion and problems)

I’ll let you know how that goes

Masive headache, I can’t make the project to see the files in libs, with certain directory structure.
I checked Directory structure and organization and Correct organization and linking of multiple cpp and h files as well as platform-atmelavr/examples/arduino-blink/lib at develop · platformio/platform-atmelavr · GitHub, but I can’t make it to work, still seeing the linker error message:

<artificial>:(.text.startup+0x0): undefined reference to `my_function'

Then I have a very basic lib structure, as follows (my_local_lib)
image

My platformio.ini

[env:AVR128DA48]
platform = avr128da
board = curiosity_nano_da
framework = arduino
build_flags = -Ilib/

My main

#include <my_local_lib/my_system.h>

int main()
{
  my_function();
}

my_system.h

void my_function();

my_system.c

#include "../my_system.h"
#include <stdint.h>

#define MY_VALUE 4
void my_function()
{
    uint16_t set_my_value = MY_VALUE;
}

I made it work (the contrived test with my_function(), if I put the .h file in include, and .c file in the src, but that wouldn’t help much, my MCC library code has this separated directory structure.