platformio / platform-intel_mcs51

Intel MCS-51 (8051): development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/intel_mcs51
Apache License 2.0
56 stars 45 forks source link

Bug in main.py prevents use of L suffix in f_cpu #40

Closed snovotill closed 2 years ago

snovotill commented 3 years ago

I was told to log this bug as explained below. I think this means the L needs to be stripped prior to calculating f_cpu_khz but left in tact for passing to the environment. Here is the summary from this discussion: https://community.platformio.org/t/specifying-f-cpu-in-boardname-json-doesnt-like-l-suffix/21847

Because of the following line in /builder/main.py the value in build.f_cpu has to be parsable as an integer with the Python int() functiont, so it can not contain any L.

f_cpu_khz = int(board_config.get(\"build.f_cpu\")) / 1000

That’s different to e.g. the atmel-avr platform which does not attempt to load the integer value into Python, but simply passes the value on.

Leaving out the L suffix will make the Python code not fail, but maybe the macro expansion in main.py

CPPDEFINES=[
    "F_CPU=$BOARD_F_CPU",
    "HEAP_SIZE=" + __getSize("size_heap", env)

will be wrong then. Something like

long f_cpu = F_CPU; 

might internally overflow, because the F_CPU value is not a long constant…

snovotill commented 3 years ago

Okay, I've submitted a pull request which fixes this and also updates the boardname.json files to include the L. Beware that I'm don't know what I'm doing and this is the first line of Python that I've ever written! I did test my fix and it works fine here.