Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use assembly files in MCS51 platform due to core issue #3917

Closed
maxgerhardt opened this issue Apr 2, 2021 · 10 comments
Closed

Cannot use assembly files in MCS51 platform due to core issue #3917

maxgerhardt opened this issue Apr 2, 2021 · 10 comments
Assignees
Milestone

Comments

@maxgerhardt
Copy link
Contributor

maxgerhardt commented Apr 2, 2021

What kind of issue is this?

  • [X ] PlatformIO Core.
    If you’ve found a bug, please provide an information below.

You can erase any parts of this template not applicable to your Issue.


Configuration

Operating system: Windows 10 x64

PlatformIO Version (platformio --version): PlatformIO Core, version 5.2.0a3

Description of problem

Per https://community.platformio.org/t/mcs51-assembler-programming/20410.

When attempting to write an assembler program for a MCS51 device on Windows by creating a src/blink.s file, the following error occurrs

Building in release mode
sdcc -DF_CPU=11059200 -DHEAP_SIZE=64 -DPLATFORMIO=50200 -Iinclude -Isrc -c -o .pio\build\stc15f204ea\src\blinky.rel src\blinky.s
at 1: error 119: don't know what to do with file 'src\blinky.s'. file extension unsupported
SDCC : mcs51/z80/z180/r2k/r3ka/gbz80/tlcs90/ez80_z80/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8 3.8.4 #10766 (MINGW64)

Suddenly it wants to use sdcc, the C compiler, for the .s file, but in the special case of SDCC, it does not know how to handle assembly files.

The platform code

https://github.com/platformio/platform-intel_mcs51/blob/c52ea3a706e540df65bdc6a0caf64f1eefeb8ac9/builder/main.py#L56-L60

sets the correct AS="sdas8051" directive, however the code in

# fix ASM handling under non case-sensitive OS
if not Util.case_sensitive_suffixes(".s", ".S"):
env.Replace(AS="$CC", ASCOM="$ASPPCOM")

overwrites the assembler on non-case-sensitive operating systems to SDCC, thus causing the issue.

Steps to Reproduce

  1. Create a new project for the stc15f204ea board
  2. Add a blink.s file with empty content
  3. Hit "Build"

Actual Results

sdcc -DF_CPU=11059200 -DHEAP_SIZE=64 -DPLATFORMIO=50200 -Iinclude -Isrc -c -o .pio\build\stc15f204ea\src\blinky.rel src\blinky.s
at 1: error 119: don't know what to do with file 'src\blinky.s'. file extension unsupported

Expected Results

It uses sdas8051 correctly, as it actually does on Llinux.

Building in release mode
sdas8051 -o .pio/build/stc15f204ea/src/blinky.rel src/blinky.s
[..]

(note: the assembler flags are still wrong per linked issue, but that's a different issue)

If problems with PlatformIO Build System:

The content of platformio.ini:

[env:stc15f204ea]
platform = intel_mcs51
board = stc15f204ea

Source file to reproduce issue:

Additional info

On Linux systems this issue does not occur

Building in release mode
sdas8051 -o .pio/build/stc15f204ea/src/blinky.rel src/blinky.s

But final linking fails due to multiple other issues which will be filed separately in the MCS51 platform (missing -l assembler flag, etc.).

@maxgerhardt
Copy link
Contributor Author

maxgerhardt commented Apr 2, 2021

Addendum: This issue also applies to platform-ststm8 if someone tries to actually use the sdasstm8 assembler with assembly files.

https://github.com/platformio/platform-ststm8/blob/712f391f99a6b767fe7f1183fdb2b7d4d239b549/builder/main.py#L26-L29

Addendum 2: The current behavior is okay for all GCC toolchains, it's just wrong for the SDCC toolchain.

@ivankravets
Copy link
Member

Thanks for the report! It is a very interesting issue, mainly related to the SCons. See https://github.com/SCons/scons/blob/master/SCons/Tool/asm.py#L44
As you can see, a default ASM tool declares ".s" and ".S" extensions on Windows (non-case-sensitive) for ASCOM. This is classic behavior for native compilers but not for GCC. The f63b2f7 fixes this situation.

Nevertheless, we found a historical bug in ALL dev-platforms where we overwrite ASFLAGS with the preprocessor's data instead of ASPPFLAGS. We will fix it soon.

@positron96
Copy link

My platformio just upgraded to 6.0.1 and for some reason, the build for STM32 started to fail with this message:

Compiling .pio\build\board\src\cubemx\startup_stm32f407xx.o
arm-none-eabi-as: unrecognized option `-x'

Apparently, my platformio.ini file has always contained line

src_filter =     
+<cubemx/startup_stm32f407xx.s>

and it has always worked fine on Windows.

When I changed the line to uppercase ".S", the build started to work fine.

Does the fixing of this issue mean that, from now on, all projects that referenced ".s" files and worked before need to be changed and files renamed to uppercase?

@ivankravets
Copy link
Member

Yes, it was a historical bug in SCons on Windows, and we decided to fix it on our side. See http://draskovblog.blogspot.com/2008/12/gcc-differences-between-s-and-s.html

@positron96
Copy link

Ok, thanks for the link.
Am I right that .S files are passed to gcc (with -x) option, and .s files are passed to as (also with -x option) and the latter complains about -x option? Then there is a problem for those who have rightful .s files (to be passed directly to as).

Also, the compilation database shows arm-none-eabi-as.exe for both .s and .S, despite calling different programs in reality. Is this a bug?

@ivankravets
Copy link
Member

Yes, .s and .S are assembly files and as.exe is used. The only flags are different. You can check this with pio run -t envdump. Please search for ASCOM.

@positron96
Copy link

positron96 commented May 18, 2022

Hmm, let me humbly disagree.

I'm running pio run --verbose for both files and here are commands being executed:

here is one for .s:

arm-none-eabi-as -x assembler-with-cpp -Os -ffunction-sections -fdata-sections -Wall -mthumb -mcpu=cortex-m4 -o .pio\build\board\src\cubemx\startup_stm32f407xx.o src\cubemx\startup_stm32f407xx.s

here is one for .S:
arm-none-eabi-gcc -x assembler-with-cpp -Os -ffunction-sections -fdata-sections -Wall -mthumb -mcpu=cortex-m4 -DGIT_HASH=\"4e3680\" -DGIT_TIMESTAMP=1652884351 -DGIT_DATE=\"2022-05-18\" -DF_CPU=168000000L -DPLATFORMIO=60001 -DSTM32F407xx -DSTM32F4 -DUSE_FULL_LL_DRIVER -DUSE_HAL_DRIVER -DSTM32F407xx -DFROZEN_NO_EXCEPTIONS -Isrc -Ilib\util -Ilib\frozen\include -Ilib\frozen -Ilib\RTT -Ilib\littlefs "-I.pio\libdeps\board\Embedded Template Library\include" "-I.pio\libdeps\board\Embedded Template Library" -Isrc\drivers -Isrc\cubemx\Inc -Isrc\cubemx\Drivers\STM32F4xx_HAL_Driver\Inc -Isrc\cubemx\Drivers\STM32F4xx_HAL_Driver\Inc\Legacy -Isrc\cubemx\Middlewares\Third_Party\FreeRTOS\Source\include -Isrc\cubemx\Middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS -Isrc\cubemx\Middlewares\Third_Party\FreeRTOS\Source\portable\GCC\ARM_CM4F -Isrc\cubemx\Middlewares\Third_Party\FatFs\src -Isrc\cubemx\Middlewares\ST\STM32_USB_Host_Library\Core\Inc -Isrc\cubemx\Middlewares\ST\STM32_USB_Host_Library\Class\MSC\Inc -Isrc\cubemx\Drivers\CMSIS\Device\ST\STM32F4xx\Include -Isrc\cubemx\Drivers\CMSIS\Include -c -o .pio\build\board\src\cubemx\startup_stm32f407xx.o src\cubemx\startup_stm32f407xx.S

The first one fails since as does not know about -x parameter (it's from gcc). It was also reported here: platformio/platform-ststm32#332 but again, it was fixed by changing the extension to .S.

My point is, if people use .s extension erroneously, then they need to change the case and everything will work. However, if they use .s extension rightfully and really need to pass the file directly to as, they they will face the arm-none-eabi-as: unrecognized option '-x' problem. It might not be relevant and everyone uses .s files that really should be .S, I don't know.

@ivankravets
Copy link
Member

@positron96 thanks, fixed in https://github.com/platformio/platform-ststm32

Could you try the latest version of ST STM32 dev-platform?

[env:development]
platform = https://github.com/platformio/platform-ststm32.git

Please navigate to the project folder and type pio pkg update.

Does it work now?

@positron96
Copy link

Yes, the assembler doesn't complain about unknown arguments anymore. It is run with these arguments now:

arm-none-eabi-as -o .pio\build\board\src\cubemx\startup_stm32f407xx.o src\cubemx\startup_stm32f407xx.s

Thank you for making very useful software!

BTW, for some reason after I changed platform line in platformio.ini, pio pkg update did not update anything even after I removed ststm32 folder. Removing the platform folder and rebuilding did the trick.

@ivankravets
Copy link
Member

You can only update installed packages. If they have not been installed yet, you will not see any updates.

Thanks for the kind words! 🙏🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants