shadow578 / Marlin-H32

Marlin for HC32F460 based printers (now in upstream)
http://marlinfw.org
GNU General Public License v3.0
13 stars 7 forks source link

[BUG] CPU_FREQ is not const #29

Closed classicrocker883 closed 8 months ago

classicrocker883 commented 1 year ago

Bug Description

this isn't particular to your repository, but is relatable I was wondering if you could look through this code anyway. So I went ahead and merged the current Marlin repo with this, and Mriscoc's ProUI - wasn't easy - but it compiles fine and its all good and everything, just wanted a second opinion

so here in this file src/module/stepper.cpp (linked to my repo as stated above)

 #ifdef CPU_32_BIT

    // A fast processor can just do integer division
    constexpr uint32_t min_step_rate = uint32_t(STEPPER_TIMER_RATE) / HAL_TIMER_TYPE_MAX;
    return step_rate > min_step_rate ? uint32_t(STEPPER_TIMER_RATE) / step_rate : HAL_TIMER_TYPE_MAX;

  #else

however I get this error

framework-arduino-hc32f46x\cores\arduino/Arduino.h:13:21: note: 'uint32_t CPU_FREQ' is not const
13 | extern uint32_t CPU_FREQ;

so I changed the above code to:

TERN(TARGET_HC32F46x, const, constexpr) uint32_t min_step_rate = uint32_t(STEPPER_TIMER_RATE) / HAL_TIMER_TYPE_MAX;

I'm wondering if that is the correct way, because after it compiles fine, but also without const or constexpr (left blank), it also compiles fine.

my question is what would you do? feel free to look over the repo which I merged to the current Marlin bugfix.

Version of Marlin Firmware

Hybrid of Marlin, Mriscoc and this "aquila" branch

classicrocker883 commented 1 year ago

update - note: not matter if const/constexpr/or (blank), it compiles successful with no changes to RAM or FLASH, not by one byte. it just will not compile successful using only HC32 and constexpr.

shadow578 commented 1 year ago

this is a known issue, i'm working on a permanent solution for this in the cores.

Basically, issue is that the clock frequency for the HC32 is configured using code (similar to how the STM32* does it) and can change during the runtime of the firmware. So setting it to a constant value like Marlin expects it to be is not quite as simple...

classicrocker883 commented 1 year ago

hey I'm guessing the new library fixed some things? do you know if BLTouch can be enabled with the other lcd dwin sets like ProUI? because it would somehow only work with JyersUI. apparently UBL or BLTouch gives constant boot loop, or restarts when saving.

shadow578 commented 8 months ago

i believe this issue is since fixed, if not please re-open