Community-PIO-CH32V / platform-ch32v

PlatformIO platform for CH32V RISC-V chips (CH32V003, CH32V103, CH32V20x, CH32V30x, CH32X035) and CH56x, CH57x, CH58x, CH59x
Apache License 2.0
204 stars 34 forks source link

"can't link RVE with other target" when building for CH32V003A4M6 on mac. blinky-none-os example. #25

Closed symonty closed 1 year ago

symonty commented 1 year ago

Otehr boards seem to compile fine. the riscv-non-embed binaries seem to be installed correctly.

At a a loss why this will not link, I am missing something or a bug?

.platformio/packages/toolchain-riscv@src-4a976c8edcf1083542a06c72f741fdf2/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/bin/ld: .platformio/packages/toolchain-riscv@src-4a976c8edcf1083542a06c72f741fdf2/bin/../lib/gcc/riscv-none-embed/8.2.0/libgcc.a(save-restore.o): can't link RVE with other target

same error for

.. muldi3.o ... div.o ... lib_a-init.o

maxgerhardt commented 1 year ago

I've observed this failure too in the CI but only with some examples. Something is definitely wrong there with the used libgcc.a file, for Mac we might need to substitute the one from the Linux Toolchain (which should be fine).I don't have a Mac to test so I'd love for you to do it: Can you go to the official mounriver website, download the IDE for Mac, create s new CH32V003 project (from their new.project template), disable Build->Concise Output, then build and send the log here (via Pastebin.com)?

symonty commented 1 year ago

official mounriver website, download the IDE for Mac,

Sorry I dont think there is an official IDE, however they do offer the toolchain as xPack which looks to be the same as the toolchain i got from the platformio install.

~/.platformio/packages/toolchain-riscv@src-4a976c8edcf1083542a06c72f741fdf2

I can try replace the toolchain with the one downloaded... So I symlinked the lib directory to the downloaded toolchain and I get the same error.. (lib -> ~/Downloads/MRS_Toolchain_MAC_V170/xpack-riscv-none-embed-gcc-8.2.0/lib )

I also compared the libgcc.a and they look same in both... cmp lib/gcc/riscv-none-embed/8.2.0/libgcc.a lib.old/gcc/riscv-none-embed/8.2.0/libgcc.a

ofcourse it could be ( but unlikely ) a rosetta issue since the toolchains are X64 and M1/M2 are ARM?

BTW: Happy to be the mac helper on this, just got the WCH kits and loads of experience with the ESP01/8266/32 and STM32 platformio dev shizzz. Always "exciting" getting your toolchains and flow working!

unixbigot commented 1 year ago

I get the same issue on my intel mac, so Rosetta is off the hook.

symonty commented 1 year ago

I get the same issue on my intel mac, so Rosetta is off the hook.

OK thx for that .... working on getting it running on UTM on my M1 to confirm it aint my project, now I know it aint a ARM vs X86 issue.

unixbigot commented 1 year ago

I've installed the mounriver xpack and tried it out. No IDE (just toolchain) so I grabbed an example command line-friendly project from https://github.com/cjacker/ch32v_evt_makefile_gcc_project_template

This project's setup script does not run on Mac, so I debugged it, making these changes: https://github.com/unixbigot/ch32v_evt_makefile_gcc_project_template/commit/dbcfc5f70f2116741cb8bd091cf66835cbb4c3b9

With all that, building a skeleton app runs these commands:

riscv-none-embed-gcc -c -march=rv32ec -mabi=ilp32e -msmall-data-limit=8    -ICH32V_firmware_library/Peripheral/inc -ICH32V_firmware_library/Debug -ICH32V_firmware_library/Core -IUser -Os -Wall -fdata-sect
ions -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/core_riscv.d"  -Wa,-a,-ad,-alms=build/core_riscv.lst CH32V_firmware_library/Core/core_riscv.c -o build/core_riscv.o
riscv-none-embed-gcc -c -march=rv32ec -mabi=ilp32e -msmall-data-limit=8    -ICH32V_firmware_library/Peripheral/inc -ICH32V_firmware_library/Debug -ICH32V_firmware_library/Core -IUser -Os -Wall -fdata-sect
ions -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/ch32v00x_dma.d"  -Wa,-a,-ad,-alms=build/ch32v00x_dma.lst CH32V_firmware_library/Peripheral/src/ch32v00x_dma.c -o build/ch32v00x_dma.o
riscv-none-embed-gcc -c -march=rv32ec -mabi=ilp32e -msmall-data-limit=8    -ICH32V_firmware_library/Peripheral/inc -ICH32V_firmware_library/Debug -ICH32V_firmware_library/Core -IUser -Os -Wall -fdata-sect
ions -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/ch32v00x_misc.d"  -Wa,-a,-ad,-alms=build/ch32v00x_misc.lst CH32V_firmware_library/Peripheral/src/ch32v00x_misc.c -o build/ch32v00x_misc.o
riscv-none-embed-gcc -c -march=rv32ec -mabi=ilp32e -msmall-data-limit=8    -ICH32V_firmware_library/Peripheral/inc -ICH32V_firmware_library/Debug -ICH32V_firmware_library/Core -IUser -Os -Wall -fdata-sect
ions -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/ch32v00x_adc.d"  -Wa,-a,-ad,-alms=build/ch32v00x_adc.lst CH32V_firmware_library/Peripheral/src/ch32v00x_adc.c -o build/ch32v00x_adc.o
riscv-none-embed-gcc -c -march=rv32ec -mabi=ilp32e -msmall-data-limit=8    -ICH32V_firmware_library/Peripheral/inc -ICH32V_firmware_library/Debug -ICH32V_firmware_library/Core -IUser -Os -Wall -fdata-sect
ions -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/ch32v00x_pwr.d"  -Wa,-a,-ad,-alms=build/ch32v00x_pwr.lst CH32V_firmware_library/Peripheral/src/ch32v00x_pwr.c -o build/ch32v00x_pwr.o
riscv-none-embed-gcc -c -march=rv32ec -mabi=ilp32e -msmall-data-limit=8    -ICH32V_firmware_library/Peripheral/inc -ICH32V_firmware_library/Debug -ICH32V_firmware_library/Core -IUser -Os -Wall -fdata-sect
ions -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/ch32v00x_iwdg.d"  -Wa,-a,-ad,-alms=build/ch32v00x_iwdg.lst CH32V_firmware_library/Peripheral/src/ch32v00x_iwdg.c -o build/ch32v00x_iwdg.o
riscv-none-embed-gcc -c -march=rv32ec -mabi=ilp32e -msmall-data-limit=8    -ICH32V_firmware_library/Peripheral/inc -ICH32V_firmware_library/Debug -ICH32V_firmware_library/Core -IUser -Os -Wall -fdata-sect
ions -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/ch32v00x_wwdg.d"  -Wa,-a,-ad,-alms=build/ch32v00x_wwdg.lst CH32V_firmware_library/Peripheral/src/ch32v00x_wwdg.c -o build/ch32v00x_wwdg.o
riscv-none-embed-gcc -c -march=rv32ec -mabi=ilp32e -msmall-data-limit=8    -ICH32V_firmware_library/Peripheral/inc -ICH32V_firmware_library/Debug -ICH32V_firmware_library/Core -IUser -Os -Wall -fdata-sect
ions -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/ch32v00x_exti.d"  -Wa,-a,-ad,-alms=build/ch32v00x_exti.lst CH32V_firmware_library/Peripheral/src/ch32v00x_exti.c -o build/ch32v00x_exti.o
riscv-none-embed-gcc -c -march=rv32ec -mabi=ilp32e -msmall-data-limit=8    -ICH32V_firmware_library/Peripheral/inc -ICH32V_firmware_library/Debug -ICH32V_firmware_library/Core -IUser -Os -Wall -fdata-sect
ions -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/ch32v00x_flash.d"  -Wa,-a,-ad,-alms=build/ch32v00x_flash.lst CH32V_firmware_library/Peripheral/src/ch32v00x_flash.c -o build/ch32v00x_flash.o
riscv-none-embed-gcc -c -march=rv32ec -mabi=ilp32e -msmall-data-limit=8    -ICH32V_firmware_library/Peripheral/inc -ICH32V_firmware_library/Debug -ICH32V_firmware_library/Core -IUser -Os -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/ch32v00x_dbgmcu.d"  -Wa,-a,-ad,-alms=build/ch32v00x_dbgmcu.lst CH32V_firmware_library/Peripheral/src/ch32v00x_dbgmcu.c -o build/ch32v00x_dbgmcu.o
riscv-none-embed-gcc -c -march=rv32ec -mabi=ilp32e -msmall-data-limit=8    -ICH32V_firmware_library/Peripheral/inc -ICH32V_firmware_library/Debug -ICH32V_firmware_library/Core -IUser -Os -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/ch32v00x_spi.d"  -Wa,-a,-ad,-alms=build/ch32v00x_spi.lst CH32V_firmware_library/Peripheral/src/ch32v00x_spi.c -o build/ch32v00x_spi.o
riscv-none-embed-gcc -c -march=rv32ec -mabi=ilp32e -msmall-data-limit=8    -ICH32V_firmware_library/Peripheral/inc -ICH32V_firmware_library/Debug -ICH32V_firmware_library/Core -IUser -Os -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/ch32v00x_tim.d"  -Wa,-a,-ad,-alms=build/ch32v00x_tim.lst CH32V_firmware_library/Peripheral/src/ch32v00x_tim.c -o build/ch32v00x_tim.o
riscv-none-embed-gcc -c -march=rv32ec -mabi=ilp32e -msmall-data-limit=8    -ICH32V_firmware_library/Peripheral/inc -ICH32V_firmware_library/Debug -ICH32V_firmware_library/Core -IUser -Os -Wall -fdata-sect
ions -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/ch32v00x_usart.d"  -Wa,-a,-ad,-alms=build/ch32v00x_usart.lst CH32V_firmware_library/Peripheral/src/ch32v00x_usart.c -o build/ch32v00x_usart.o
riscv-none-embed-gcc -c -march=rv32ec -mabi=ilp32e -msmall-data-limit=8    -ICH32V_firmware_library/Peripheral/inc -ICH32V_firmware_library/Debug -ICH32V_firmware_library/Core -IUser -Os -Wall -fdata-sect
ions -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/ch32v00x_rcc.d"  -Wa,-a,-ad,-alms=build/ch32v00x_rcc.lst CH32V_firmware_library/Peripheral/src/ch32v00x_rcc.c -o build/ch32v00x_rcc.o
riscv-none-embed-gcc -c -march=rv32ec -mabi=ilp32e -msmall-data-limit=8    -ICH32V_firmware_library/Peripheral/inc -ICH32V_firmware_library/Debug -ICH32V_firmware_library/Core -IUser -Os -Wall -fdata-sect
ions -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/ch32v00x_i2c.d"  -Wa,-a,-ad,-alms=build/ch32v00x_i2c.lst CH32V_firmware_library/Peripheral/src/ch32v00x_i2c.c -o build/ch32v00x_i2c.o
riscv-none-embed-gcc -c -march=rv32ec -mabi=ilp32e -msmall-data-limit=8    -ICH32V_firmware_library/Peripheral/inc -ICH32V_firmware_library/Debug -ICH32V_firmware_library/Core -IUser -Os -Wall -fdata-sect
ions -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/ch32v00x_gpio.d"  -Wa,-a,-ad,-alms=build/ch32v00x_gpio.lst CH32V_firmware_library/Peripheral/src/ch32v00x_gpio.c -o build/ch32v00x_gpio.o
riscv-none-embed-gcc -c -march=rv32ec -mabi=ilp32e -msmall-data-limit=8    -ICH32V_firmware_library/Peripheral/inc -ICH32V_firmware_library/Debug -ICH32V_firmware_library/Core -IUser -Os -Wall -fdata-sect
ions -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/ch32v00x_opa.d"  -Wa,-a,-ad,-alms=build/ch32v00x_opa.lst CH32V_firmware_library/Peripheral/src/ch32v00x_opa.c -o build/ch32v00x_opa.o
riscv-none-embed-gcc -c -march=rv32ec -mabi=ilp32e -msmall-data-limit=8    -ICH32V_firmware_library/Peripheral/inc -ICH32V_firmware_library/Debug -ICH32V_firmware_library/Core -IUser -Os -Wall -fdata-sect
ions -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/debug.d"  -Wa,-a,-ad,-alms=build/debug.lst CH32V_firmware_library/Debug/debug.c -o build/debug.o
riscv-none-embed-gcc -c -march=rv32ec -mabi=ilp32e -msmall-data-limit=8    -ICH32V_firmware_library/Peripheral/inc -ICH32V_firmware_library/Debug -ICH32V_firmware_library/Core -IUser -Os -Wall -fdata-sect
ions -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/system_ch32v00x.d"  -Wa,-a,-ad,-alms=build/system_ch32v00x.lst User/system_ch32v00x.c -o build/system_ch32v00x.o
riscv-none-embed-gcc -c -march=rv32ec -mabi=ilp32e -msmall-data-limit=8    -ICH32V_firmware_library/Peripheral/inc -ICH32V_firmware_library/Debug -ICH32V_firmware_library/Core -IUser -Os -Wall -fdata-sect
ions -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/main.d"  -Wa,-a,-ad,-alms=build/main.lst User/main.c -o build/main.o
User/main.c: In function 'main':
User/main.c:58:24: warning: format '%d' expects argument of type 'int', but argument 2 has type 'uint32_t' {aka 'long unsigned int'} [-Wformat=]
     printf("SystemClk:%d\r\n", SystemCoreClock);
                       ~^       ~~~~~~~~~~~~~~~
                       %ld
riscv-none-embed-gcc -c -march=rv32ec -mabi=ilp32e -msmall-data-limit=8    -ICH32V_firmware_library/Peripheral/inc -ICH32V_firmware_library/Debug -ICH32V_firmware_library/Core -IUser -Os -Wall -fdata-sect
ions -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/ch32v00x_it.d"  -Wa,-a,-ad,-alms=build/ch32v00x_it.lst User/ch32v00x_it.c -o build/ch32v00x_it.o
riscv-none-embed-gcc -x assembler-with-cpp -c -march=rv32ec -mabi=ilp32e -msmall-data-limit=8    -ICH32V_firmware_library/Peripheral/inc -ICH32V_firmware_library/Debug -ICH32V_firmware_library/Core -IUser
 -Os -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/startup_ch32v00x.d"  CH32V_firmware_library/Startup/startup_ch32v00x.S -o build/startup_ch32v00x.o
riscv-none-embed-gcc build/core_riscv.o build/ch32v00x_dma.o build/ch32v00x_misc.o build/ch32v00x_adc.o build/ch32v00x_pwr.o build/ch32v00x_iwdg.o build/ch32v00x_wwdg.o build/ch32v00x_exti.o build/ch32v00
x_flash.o build/ch32v00x_dbgmcu.o build/ch32v00x_spi.o build/ch32v00x_tim.o build/ch32v00x_usart.o build/ch32v00x_rcc.o build/ch32v00x_i2c.o build/ch32v00x_gpio.o build/ch32v00x_opa.o build/debug.o build/
system_ch32v00x.o build/main.o build/ch32v00x_it.o build/startup_ch32v00x.o -march=rv32ec -mabi=ilp32e -msmall-data-limit=8    -mno-save-restore -fmessage-length=0 -fsigned-char -ffunction-sections -fdata
-sections -Wunused -Wuninitialized -T CH32V_firmware_library/Ld/Link.ld  -nostartfiles -Xlinker --gc-sections -Wl,-Map=build/ch32v003f4u6.map --specs=nano.specs -lc -lm -lnosys -o build/ch32v003f4u6.elf
riscv-none-embed-size build/ch32v003f4u6.elf
   text    data     bss     dec     hex filename
   9652     152     276   10080    2760 build/ch32v003f4u6.elf
riscv-none-embed-objcopy -O ihex build/ch32v003f4u6.elf build/ch32v003f4u6.hex
riscv-none-embed-objcopy -O binary -S build/ch32v003f4u6.elf build/ch32v003f4u6.bin

The complete steps to replicate my process are:

  cd /opt && unzip ~/Downloads/MRS_Toolchain_MAC_V170/xpack-riscv-none-embed-gcc-8.2.0.zip
  export PATH=/opt/xpack-riscv-none-embed-gcc-8.2.0/bin:$PATH
  git clone https://github.com/unixbigot/ch32v_evt_makefile_gcc_project_template.git -b macos_generate_fix
  cd ch32v_evt_makefile_gcc_project_template
  ./generate_project_from_evt.sh ch32v003f4u6
  make
unixbigot commented 1 year ago

Comparing the link stage arguments, pio is using -march=rv32ecxw while mounriver is using -march=rv32ec.

Amending the pio link command to use the same argument makes it appear to succeed.

unixbigot commented 1 year ago

Following that back to the board file, the following change (applied in ~/platformio/platforms/ch32v) gives me a successful pio run -t upload, and code that runs on the device:

diff --git a/boards/genericCH32V003F4U6.json b/boards/genericCH32V003F4U6.json
index 4bba765..98d915c 100644
--- a/boards/genericCH32V003F4U6.json
+++ b/boards/genericCH32V003F4U6.json
@@ -9,7 +9,7 @@
       ]
     ],
     "mabi": "ilp32e",
-    "march": "rv32ecxw",
+    "march": "rv32ec",
     "mcu": "ch32v003f4u6",
     "series": "ch32v003"
   },

But why does it comple OK on on Linux with -march=rc32ecxw?

symonty commented 1 year ago

Confirmed my code for the A4M6 now compiles.

Will try and upload tomorrow ( PST time here, not AEST ) Thx.

manually removed xw from march in ./platforms/ch32v/boards/genericCH32V003A4M6.json

maxgerhardt commented 1 year ago

That's... but the MounRiver IDE uses this exact architecture. The xw architecture part is for the custom extensions that the CH32V003's QingKe V2 core has.

grafik

QingKeV2_Processor_Manual.PDF

So when we're not turning that on, we're losing in terms of firmware size and probably execution speed (shorter instructions are faster to load).

I can dynamically turn off xw for Mac in the builder script and probbaly make it go through, but it doesn't feel right at all. I'll need to ask MounRiver support again what's going on there.

maxgerhardt commented 1 year ago

100% what MounRiver IDE is using. There must be an issue with the Mac version of the toolchain.

grafik

maxgerhardt commented 1 year ago

Fixed per PR above until I get a response from MounRiver support or a fixed MacOS toolchain that can do rv32ecxw.

maxgerhardt commented 1 year ago

As expected,

From: support \support@mounriver.com\ Dear Maximilian, Hi, the current MRS toolchain on the macOS platform does not support the extension instructions you currently need. We will update this development resource in the near future.

MounRiver Studio 2023.05.09

maxgerhardt commented 1 year ago

image

New toolchain dropped, this will likely fix the problem of missing rv32ecxw libraries -- will look into updating the toolchain, re-upgrading the march and retesting in CI.

maxgerhardt commented 1 year ago

Toolchain updated per https://github.com/Community-PIO-CH32V/toolchain-riscv-mac/commit/99cb62f72304e1a7afe8e7c191143975793ccfab and workaround removed per https://github.com/Community-PIO-CH32V/platform-ch32v/commit/0f2a3e14d62e9f19077e3d01ea5664e0bc2ebbed.

Examples still compile normally, so everything is fixed now properly :)

unixbigot commented 1 year ago

Works for me, thanks again.

For those reading along, I reverted my platform hack, then did pio pkg update -g -p https://github.com/Community-PIO-CH32V/platform-ch32v.git which updated some stuff. Compilation still failed---looks like the toolchain didn't update. I deleted .platformio/packages/toolchain-riscv/ then recompiled my project, and it fetched the new toolchain during compilation and compiles OK now.