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 44 forks source link

CFLAGS & LINKFLAGS from extra_script #11

Closed zerog2k closed 5 years ago

zerog2k commented 5 years ago

There are some more advanced things im trying to do with my project which don't seem to be working E.g., for one of my projects, I have some very special (don't ask why ;) CFLAGS and LINKFLAGS, which I'm not sure how to handle other than appending to env in extra_script.py: https://github.com/zerog2k/stc_diyclock/blob/master/post_extra_script.py#L12-L20 I think it used to work, but now testing, I'm compiling and seeing that these don't seem to be honored by compile time.

jens@pluto:/media/jens/DataPart/build/stc_diyclock$ pio run -v

Processing stc15w408as (platform: https://github.com/zerog2k/platform-mcs51.git; extra_scripts: post_extra_script.py; upload_port: /dev/ttyUSB2; board: stc15w408as; upload_protocol: stcgal)
--------------------------------------------------------------------------------------------------------------------------
PLATFORM: MCS 8051/8052 > stc15w408as
SYSTEM: MCS51 11MHz 512B RAM (8KB Flash)
Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF MODES: FINDER(chain) COMPATIBILITY(soft)
Collected 0 compatible libraries
Scanning dependencies...
No dependencies
sdcc -o .pioenvs/stc15w408as/src/adc.rel -c --std-sdcc11 --opt-code-size --peep-return -mmcs51 -DF_CPU=11059200 -DHEAP_SIZE=128 -DPLATFORMIO=30600 -Isrc src/adc.c
sdcc -o .pioenvs/stc15w408as/src/ds1302.rel -c --std-sdcc11 --opt-code-size --peep-return -mmcs51 -DF_CPU=11059200 -DHEAP_SIZE=128 -DPLATFORMIO=30600 -Isrc src/ds1302.c
sdcc -o .pioenvs/stc15w408as/src/main.rel -c --std-sdcc11 --opt-code-size --peep-return -mmcs51 -DF_CPU=11059200 -DHEAP_SIZE=128 -DPLATFORMIO=30600 -Isrc src/main.c
src/ds1302.c:84: warning 59: function 'readbyte' must return value
src/main.c:672: warning 126: unreachable code
src/main.c:672: warning 126: unreachable code
src/main.c:673: warning 126: unreachable code
src/main.c:673: warning 126: unreachable code
src/main.c:677: warning 126: unreachable code
src/main.c:677: warning 126: unreachable code
src/main.c:678: warning 126: unreachable code
src/main.c:678: warning 126: unreachable code
src/main.c:691: warning 126: unreachable code
src/main.c:691: warning 126: unreachable code
src/main.c:692: warning 126: unreachable code
src/main.c:692: warning 126: unreachable code
src/main.c:694: warning 126: unreachable code
src/main.c:694: warning 126: unreachable code
src/main.c:695: warning 126: unreachable code
src/main.c:695: warning 126: unreachable code
src/main.c:697: warning 126: unreachable code
src/main.c:697: warning 126: unreachable code
src/main.c:701: warning 126: unreachable code
src/main.c:701: warning 126: unreachable code
src/main.c:704: warning 126: unreachable code
src/main.c:704: warning 126: unreachable code
src/main.c:712: warning 126: unreachable code
src/main.c:712: warning 126: unreachable code
src/main.c:713: warning 126: unreachable code
src/main.c:713: warning 126: unreachable code
src/main.c:716: warning 126: unreachable code
src/main.c:716: warning 126: unreachable code
src/main.c:717: warning 126: unreachable code
src/main.c:717: warning 126: unreachable code
src/main.c:723: warning 126: unreachable code
src/main.c:723: warning 126: unreachable code
src/main.c:724: warning 126: unreachable code
src/main.c:724: warning 126: unreachable code
src/main.c:727: warning 126: unreachable code
src/main.c:727: warning 126: unreachable code
src/main.c:728: warning 126: unreachable code
src/main.c:728: warning 126: unreachable code
src/main.c:737: warning 126: unreachable code
src/main.c:737: warning 126: unreachable code
src/main.c:738: warning 126: unreachable code
src/main.c:738: warning 126: unreachable code
src/main.c:739: warning 126: unreachable code
src/main.c:739: warning 126: unreachable code
src/main.c:744: warning 126: unreachable code
src/main.c:744: warning 126: unreachable code
src/main.c:745: warning 126: unreachable code
src/main.c:745: warning 126: unreachable code
sdcc -o .pioenvs/stc15w408as/firmware.ihx -mmcs51 --iram-size 256 --xram-size 256 --code-size 8192 --out-fmt-ihx --data-loc 48 .pioenvs/stc15w408as/src/adc.rel .pioenvs/stc15w408as/src/ds1302.rel .pioenvs/stc15w408as/src/main.rel -L.pioenvs/stc15w408as
============================================== [SUCCESS] Took 2.14 seconds ==============================================

======================================================= [SUMMARY] =======================================================
Environment stc15f204ea [SKIP]
Environment stc15w404as [SKIP]
Environment stc15w408as [SUCCESS]
============================================== [SUCCESS] Took 2.14 seconds ==============================================
zerog2k commented 5 years ago

ok appears that LINKFLAGS getting passed to link stage, but CFLAGS not passed to compile stage?

zerog2k commented 5 years ago

@ivankravets @Palatis any pointers here? https://github.com/platformio/platform-mcs51/blob/master/builder/main.py#L71-L103

zerog2k commented 5 years ago

sorry, to be clear, my post_extra_script.py is doing this:

# compiler and linker flags dont work very well in build_flags of platformio.ini - need to set them here
env.Append(
    CFLAGS = [
    "--disable-warning", 126,
    "--disable-warning", 59
    ],
    LINKFLAGS = [
        "--data-loc", 0x30
    ]
)
ivankravets commented 5 years ago

I've just renamed dev platform and refactored code. Please run pio update.

Next. Please use pre:extra.py instead of POST.

Does it work now?

ivankravets commented 5 years ago

Could you provide "blink" project here and attach? I would like to test it on my Mac and add CI support.

zerog2k commented 5 years ago

here is a simply "blinky" project... just updated so it will build against latest https://github.com/zerog2k/stc_blinky

zerog2k commented 5 years ago

regarding extra_script, i changed the line to:

extra_scripts = pre:extra_script.py

and renamed post_extra_script.py to extra_script.py - is this correct? (did not change - still getting warnings, seems like not including)

zerog2k commented 5 years ago

for my own and others' ref, seems like many changes and additions to this doc since last time I looked at this... need to re-read: http://docs.platformio.org/en/latest/projectconf/advanced_scripting.html#projectconf-advanced-scripting

ivankravets commented 5 years ago

Are these flags https://github.com/platformio/platform-intel_mcs51/issues/11#issuecomment-412130947 common per each board? Could we add them directly to dev platform?

zerog2k commented 5 years ago

no, this is some cflags specific to this board... i'd prefer to put into simpler build_flags, but there seems to be some disconnect in the way options are passed from platformio to compiler... e.g.

build_flags = "--option value" 

gets interpreted as a single option, not option name "option" then value of "value". Anyhow, I think Palatis pointed this out last time as well.. The previous workaround was to hack on the CFLAGS var with a strange list construct, not sure why it was needed, but now it seems broken. Anyhow, I found a completely different workaround, which is to use sdcc compiler pragmas in the sourc code to disable certain warnings. Since this is project specific, this will work for me, and I can take it out of extra scripts... (Although still curious why it just didnt work... ;)

ivankravets commented 5 years ago

Tested with

[env:myenv]
build_flags =
    --data-loc 0x30
    --disable-warning 126
    --disable-warning 59

P.S: If you need to pass something to LINKFLAGS, you have to use extra script.