Platformio 8051 --model-medium linker err

hello, everyone
I want compile 8051 MCU with medium model in platformio,but link fail.please help me and think very much.

my platfromio.ini is list as follow:

[env:ch552]
platform = intel_mcs51
board = ch552
build_flags =
  --model-medium
  --LC:/Users/caoyf/.platformio/packages/toolchain-sdcc/lib/medium
  -IC:/Users/caoyf/Documents/PlatformIO/Projects/ch552_gpio/src/Driver/inc
  -Isrc/PLAT/inc

link errors is list as follow:

Linking .pio\build\ch552\firmware.hex
?ASlink-Warning-Conflicting sdcc options:
   "-mmcs51 --model-medium" in module "main" and
   "-mmcs51 --model-small" in module "_divulong".
?ASlink-Warning-Conflicting sdcc options:
   "-mmcs51 --model-medium" in module "main" and
   "-mmcs51 --model-small" in module "_moduint".
?ASlink-Warning-Conflicting sdcc options:
   "-mmcs51 --model-medium" in module "main" and
   "-mmcs51 --model-small" in module "_divuint".
?ASlink-Warning-Conflicting sdcc options:
   "-mmcs51 --model-medium" in module "main" and
   "-mmcs51 --model-small" in module "_gptrget".
?ASlink-Warning-Conflicting sdcc options:
   "-mmcs51 --model-medium" in module "main" and
   "-mmcs51 --model-small" in module "_modsint".
?ASlink-Warning-Conflicting sdcc options:
   "-mmcs51 --model-medium" in module "main" and
   "-mmcs51 --model-small" in module "_divsint".
?ASlink-Warning-Conflicting sdcc options:
   "-mmcs51 --model-medium" in module "main" and
   "-mmcs51 --model-small" in module "_startup".
*** [.pio\build\ch552\firmware.hex] Error 1

it seems that linker use the lib file in .platformio\packages\toolchain-sdcc\lib\small not the link file in .platformio\packages\toolchain-sdcc\lib\medium,how can i correct it?

1 Like

I don’t see that board in platform-intel_mcs51/boards at develop · platformio/platform-intel_mcs51 · GitHub. Did you add this yourself?

Yes, I add this myself. The following is the .json file:

{
  "build": {
    "f_cpu": "24000000",
    "size_iram": 256,
    "size_xram": 1024,
    "size_code": 14336,
    "size_heap": 128,
    "mcu": "ch552t",
    "cpu": "mcs51"
  },
  "frameworks": [],
  "upload": {
    "maximum_ram_size": 1280,
    "maximum_size": 14336,
    "protocol": "stcgal",
    "stcgal_protocol": "stc15",
    "protocols": [
      "stcgal"
    ]
  },
  "name": "Generic CH552",
  "url": "http://www.wch.cn/product/CH552.html",
  "vendor": "WCH"
}

ch552 is a cheap 8051 MCU made in China with USB support.

The linker flags need to include --model-medium, too, otherwise it assumes small by default.

Please add the line

extra_scripts = link_medium.py

to your platformio.ini and, in the project folder at the same level of the platformio.ini, the file link_medium.py with the content

Import("env")
env.Append(LINKFLAGS=["--model-medium"])

Think you very much!
it sovle my problems.
Sincere wishes from faraway China, Happy New Year!
新年快乐!

1 Like

It should be -LC:/Users/caoyf/.platformio/packages/toolchain-sdcc/lib/medium but not --L to link lib