cnlohr / ch32v003fun

Open source minimal stack for the ch32 line of WCH processors, including the ch32v003, a 10¢ 48 MHz RISC-V Microcontroller - as well as many other chips within the ch32v/x line.
MIT License
955 stars 146 forks source link

Compilation failure using gcc 13.2.0 (latest release) vs gcc 9.3.0 #358

Closed brian-smith-github closed 3 months ago

brian-smith-github commented 3 months ago

Hi again. Can you help? I've switched from CH32V003 to CH32V103 board, but have noticed that although using gcc 9.3.0 (the current default in Ubuntu) works fine, I get compiler errors when using gcc 13.2.0 (the latest release):

../../ch32v003fun/ch32v003fun.c:1274:9: error: impossible constraint in 'asm' 1274 | asm volatile( | ^

The offending line in ch32v003fun.c seem to be (line 1292) :

  : : "InterruptVector" (InterruptVector) : "t0", "memory"

If i comment this line out, the compile is fine (testing with examples_v10x/blink.c). The CH32V003 examples/blink/ compiles and works fine, only the examples_v*/blink examples break.

TommyMurphyTM1234 commented 3 months ago

Can you provide the build log?

using gcc 13.2.0 (the latest release)

GCC 14.1 is actually the latest release:

Although, if you're using riscv-gnu-toolchain or some derivative then it hasn't updated to 14 yet:

brian-smith-github commented 3 months ago

I didn't build from source, I am just using the latest binary release from: https://github.com/riscv-collab/riscv-gnu-toolchain/releases

Given that the error relates to interrupts, I am suspicious that the higher version of the compiler is revealing an underlying bug in the interrupt-handling code as I'm unable to get a simple timer-based interrupt working on the CH32V103 board right now.

TommyMurphyTM1234 commented 3 months ago

Build log?

TommyMurphyTM1234 commented 3 months ago

Hi again. Can you help? I've switched from CH32V003 to CH32V103 board, but have noticed that although using gcc 9.3.0 (the current default in Ubuntu) works fine, I get compiler errors when using gcc 13.2.0 (the latest release):

../../ch32v003fun/ch32v003fun.c:1274:9: error: impossible constraint in 'asm' 1274 | asm volatile( | ^

The offending line in ch32v003fun.c seem to be (line 1292) :

  : : "InterruptVector" (InterruptVector) : "t0", "memory"

Why do you point the finger at line 1292 when the error message mentions line 1274?

brian-smith-github commented 3 months ago

line 1274 is just the opening section of a multi-line block of assembly code:

asm volatile(

Line 1292 is the bit of code that when commented out allows the compile to complete without errors, hence why I'm thinking that is where the error is (something to do with macro processing I think, but I can't get my head around how the compiler processes macros)

TommyMurphyTM1234 commented 3 months ago

Your line 1292 doesn't match the latest in source control:

You still haven't provided a build log.

brian-smith-github commented 3 months ago

It's now line 1297, I was referencing an older version of the file I think... the bug is still there though. I'll try my interrupt test code on the latest ch32v003fun and see if it's any better though.

brian-smith-github commented 3 months ago

My timer-generates-interrupt test program behaves so strangely that I've no hope of tracing the problem so I'll just close this and put my 103-board in a drawer I think... :)

cnlohr commented 3 months ago

@brian-smith-github what happens if you use one of our existing demo programs?

brian-smith-github commented 3 months ago

It looks like there are 2 examples for CH32V003 that use a timer to generate an interrupt: 1) The simplest is systick_irq - This won't work on CH32V103 as the 'SysTick' data structure is different between boards and is missing the 'Service Request' (SR) variable for some reason, so won't compile (commenting out references to SR doesn't work either, no ISR seems to happen at all). 2) There is also adc_fixed_fs but again this doesn't compile for the 103 board because of different data structures.

Really though, don't worry about it, I've got a 'Arduino Nano Connect' board I'm going to use instead for now.

brian-smith-github commented 3 months ago

(I was hoping to use the CH32V103 board as a bridge towards moving to the new CH32 boards, I'll just wait until they are actually released now instead).