Recent

Author Topic: Problem with assembler for STM32 [SOLVED]  (Read 2103 times)

petex

  • Jr. Member
  • **
  • Posts: 69
Problem with assembler for STM32 [SOLVED]
« on: January 13, 2021, 02:13:31 pm »
I have recently built the embedded ARM cross compiler using the FpcupDeluxe utility. I am intending to cross compile programs for the "blue pill" STM32F103C8T6 card.
I am compiling the simple "Blink" example and I get errors in the assembly from the compiler...
I basically followed instructions in the WIKI and running Lazarus under Windows.

Debug: C:\temp-svn\blue pill\lib\arm-embedded\project1.s:9: Error: lo register required -- `stmfd r13!,{r11,r12,r14,r15}'

etc.etc.
The full message listing  is at the end.

The compiler options are as follows:-

'C:\FreePascalDeluxe\fpc\bin\x86_64-win64\fpc.exe'  -Tembedded -Parm -CpARMV7R -MObjFPC -Scghi -l -vewnhibq -Filib\arm-embedded -Fu. -FUlib\arm-embedded -FE. -oproject1 -WpSTM32F103X8

the source is :-

Code: Pascal  [Select][+][-]
  1. program project1;
  2. {$O-}
  3.  
  4. procedure delay;
  5. var
  6.   i : uint32;
  7. begin
  8.   for i := 0 to 500000 do
  9.     begin
  10.       asm
  11.         nop   // empty instruction
  12.       end;
  13.     end;
  14. end;
  15.  
  16. begin
  17.   // turn on Port C
  18.   RCC.APB2ENR := RCC.APB2ENR or (%1 shl 4);
  19.  
  20.   // Pin 13 from Port C to Output
  21.   PortC.CRH := $00300000;
  22.  
  23.   // Note: The LED lights up at LOW.
  24.   while true do
  25.     begin
  26.       // Pin 13 - High
  27.       PortC.BSRR := 1 shl 13;
  28.       Delay;
  29.  
  30.       // Pin 13 - Low
  31.       PortC.BRR := 1 shl 13;
  32.       Delay;
  33.     end;
  34. end.


MESSAGE LISTING ====>
Quote
Compile Project, OS: embedded, CPU: arm, Target: project1: Exit code 1, Errors: 1, Hints: 4
Note: Changed CPU type to be consistent with specified controller
Hint: Start of reading config file C:\FreePascalDeluxe\fpc\bin\x86_64-win64\fpc.cfg
Hint: End of reading config file C:\FreePascalDeluxe\fpc\bin\x86_64-win64\fpc.cfg
Note: Changed CPU type to be consistent with specified controller
Verbose: Free Pascal Compiler version 3.2.0-r45643 [2021/01/12] for arm
Verbose: Copyright (c) 1993-2020 by Florian Klaempfl and others
Verbose: Target OS: Embedded
Verbose: Compiling project1.lpr
Verbose: Assembling project1
Debug: C:\temp-svn\blue pill\lib\arm-embedded\project1.s: Assembler messages:
Debug: C:\temp-svn\blue pill\lib\arm-embedded\project1.s:9: Error: lo register required -- `stmfd r13!,{r11,r12,r14,r15}'
Debug: C:\temp-svn\blue pill\lib\arm-embedded\project1.s:10: Error: lo register required -- `sub r11,r12,#4'
Debug: C:\temp-svn\blue pill\lib\arm-embedded\project1.s:12: Error: unshifted register required -- `mvn r0,#0'
Debug: C:\temp-svn\blue pill\lib\arm-embedded\project1.s:13: Error: lo register required -- `str r0,[r11,#-48]'
Debug: C:\temp-svn\blue pill\lib\arm-embedded\project1.s:16: Error: lo register required -- `ldr r0,[r11,#-48]'
Debug: C:\temp-svn\blue pill\lib\arm-embedded\project1.s:18: Error: lo register required -- `str r0,[r11,#-48]'
Debug: C:\temp-svn\blue pill\lib\arm-embedded\project1.s:22: Error: lo register required -- `ldr r0,[r11,#-48]'
Debug: C:\temp-svn\blue pill\lib\arm-embedded\project1.s:24: Error: unshifted register required -- `orr r1,r1,#288'
Debug: C:\temp-svn\blue pill\lib\arm-embedded\project1.s:29: Error: lo register required -- `ldmea r11,{r11,r13,r15}'
Debug: C:\temp-svn\blue pill\lib\arm-embedded\project1.s:40: Error: lo register required -- `stmfd r13!,{r11,r12,r14,r15}'
Debug: C:\temp-svn\blue pill\lib\arm-embedded\project1.s:41: Error: lo register required -- `sub r11,r12,#4'
Debug: C:\temp-svn\blue pill\lib\arm-embedded\project1.s:46: Error: unshifted register required -- `orr r0,r0,#16'
Debug: C:\temp-svn\blue pill\lib\arm-embedded\project1.s:66: Error: lo register required -- `ldmea r11,{r11,r13,r15}'
Debug: C:\temp-svn\blue pill\lib\arm-embedded\project1.s:23: Error: invalid immediate: 499712 is out of range
Debug: C:\temp-svn\blue pill\lib\arm-embedded\project1.s:23: Error: value of 499712 too large for field of 2 bytes at 8
Debug: C:\temp-svn\blue pill\lib\arm-embedded\project1.s:44: Error: invalid offset, target not word aligned (0x0000002E)
Debug: C:\temp-svn\blue pill\lib\arm-embedded\project1.s:44: Error: invalid offset, value too big (0x00000026)
Debug: C:\temp-svn\blue pill\lib\arm-embedded\project1.s:47: Error: invalid offset, target not word aligned (0x0000002E)
Debug: C:\temp-svn\blue pill\lib\arm-embedded\project1.s:47: Error: invalid offset, value too big (0x00000022)
Debug: C:\temp-svn\blue pill\lib\arm-embedded\project1.s:49: Error: invalid immediate: 3145728 is out of range
Debug: C:\temp-svn\blue pill\lib\arm-embedded\project1.s:49: Error: value of 3145728 too large for field of 2 bytes at 16
Debug: C:\temp-svn\blue pill\lib\arm-embedded\project1.s:50: Error: invalid offset, target not word aligned (0x00000032)
Debug: C:\temp-svn\blue pill\lib\arm-embedded\project1.s:50: Error: invalid offset, value too big (0x00000022)
Debug: C:\temp-svn\blue pill\lib\arm-embedded\project1.s:55: Error: invalid immediate: 8192 is out of range
Debug: C:\temp-svn\blue pill\lib\arm-embedded\project1.s:56: Error: invalid offset, target not word aligned (0x00000036)
Debug: C:\temp-svn\blue pill\lib\arm-embedded\project1.s:56: Error: invalid offset, value too big (0x0000001E)
Debug: C:\temp-svn\blue pill\lib\arm-embedded\project1.s:59: Error: invalid immediate: 8192 is out of range
Debug: C:\temp-svn\blue pill\lib\arm-embedded\project1.s:60: Error: invalid offset, target not word aligned (0x0000003A)
Debug: C:\temp-svn\blue pill\lib\arm-embedded\project1.s:60: Error: invalid offset, value too big (0x00000016)
project1.lpr(41,0) Error: Error while assembling exitcode 1
project1.lpr(41,0) Verbose: There were 2 errors compiling module, stopping
Verbose: Compilation aborted
Verbose: C:\FreePascalDeluxe\fpc\bin\x86_64-win64\ppcrossarm.exe returned an error exitcode

[Edited to add code tags - please see How to use the Forums.]
« Last Edit: January 14, 2021, 09:26:42 am by petex »

MiR

  • Full Member
  • ***
  • Posts: 246
Re: Problem with assembler for STM32
« Reply #1 on: January 13, 2021, 02:20:38 pm »
Try -CpARMV7M instead of ARMV7R

ccrause

  • Hero Member
  • *****
  • Posts: 845
Re: Problem with assembler for STM32
« Reply #2 on: January 13, 2021, 03:16:20 pm »
Try -CpARMV7M instead of ARMV7R
+1

Or omit -Cp if using FPC 3.2 or trunk.  The compiler will then look up the CPU type based on the controller name.

petex

  • Jr. Member
  • **
  • Posts: 69
Re: Problem with assembler for STM32
« Reply #3 on: January 13, 2021, 03:31:14 pm »
new compiler options:-

C:\FreePascalDeluxe\fpc\bin\x86_64-win64\fpc.exe
-Tembedded
-Parm
-MObjFPC
-Scghi
-l
-vewnhibq
-Filib\arm-embedded
-Fu.
-FUlib\arm-embedded
-FE.
-oproject1
-CpARMV7M
-WpSTM32F103X8

I get past the assembler errors, but now getting an unknown linker error ===>


Compile Project, OS: embedded, CPU: arm, Target: project1: Exit code 1, Errors: 1, Hints: 2
Hint: Start of reading config file C:\FreePascalDeluxe\fpc\bin\x86_64-win64\fpc.cfg
Hint: End of reading config file C:\FreePascalDeluxe\fpc\bin\x86_64-win64\fpc.cfg
Verbose: Free Pascal Compiler version 3.2.0-r45643 [2021/01/12] for arm
Verbose: Copyright (c) 1993-2020 by Florian Klaempfl and others
Verbose: Target OS: Embedded
Verbose: Compiling project1.lpr
Verbose: Assembling project1
Verbose: Linking C:\temp-svn\blue pill\project1
Debug: STM32F10X_MD
Usage: C:\FreePascalDeluxe\cross\bin\arm-embedded\arm-none-eabi-objcopy.exe [option(s)] in-file [out-file]
 Copies a binary file, possibly transforming it in the process
 The options are:
  -I --input-target <bfdname>      Assume input file is in format <bfdname>
  -O --output-target <bfdname>     Create an output file in format <bfdname>
  -B --binary-architecture <arch>  Set output arch, when input is arch-less
  -F --target <bfdname>            Set both input and output format to <bfdname>
     --debugging                   Convert debugging information, if possible
  -p --preserve-dates              Copy modified/access timestamps to the output
  -D --enable-deterministic-archives
                                   Produce deterministic output when stripping archives
  -U --disable-deterministic-archives
                                   Disable -D behavior (default)
  -j --only-section <name>         Only copy section <name> into the output
     --add-gnu-debuglink=<file>    Add section .gnu_debuglink linking to <file>
  -R --remove-section <name>       Remove section <name> from the output
     --remove-relocations <name>   Remove relocations from section <name>
  -S --strip-all                   Remove all symbol and relocation information
  -g --strip-debug                 Remove all debugging symbols & sections
     --strip-dwo                   Remove all DWO sections
     --strip-unneeded              Remove all symbols not needed by relocations
  -N --strip-symbol <name>         Do not copy symbol <name>
     --strip-unneeded-symbol <name>
                                   Do not copy symbol <name> unless needed by
                                     relocations
     --only-keep-debug             Strip everything but the debug information
     --extract-dwo                 Copy only DWO sections
     --extract-symbol              Remove section contents but keep symbols
  -K --keep-symbol <name>          Do not strip symbol <name>
     --keep-file-symbols           Do not strip file symbol(s)
     --localize-hidden             Turn all ELF hidden symbols into locals
  -L --localize-symbol <name>      Force symbol <name> to be marked as a local
     --globalize-symbol <name>     Force symbol <name> to be marked as a global
  -G --keep-global-symbol <name>   Localize all symbols except <name>
  -W --weaken-symbol <name>        Force symbol <name> to be marked as a weak
     --weaken                      Force all global symbols to be marked as weak
  -w --wildcard                    Permit wildcard in symbol comparison
  -x --discard-all                 Remove all non-global symbols
  -X --discard-locals              Remove any compiler-generated symbols
  -i --interleave[=<number>]       Only copy N out of every <number> bytes
     --interleave-width <number>   Set N for --interleave
  -b --byte <num>                  Select byte <num> in every interleaved block
     --gap-fill <val>              Fill gaps between sections with <val>
     --pad-to <addr>               Pad the last section up to address <addr>
     --set-start <addr>            Set the start address to <addr>
    {--change-start|--adjust-start} <incr>
                                   Add <incr> to the start address
    {--change-addresses|--adjust-vma} <incr>
                                   Add <incr> to LMA, VMA and start addresses
    {--change-section-address|--adjust-section-vma} <name>{=|+|-}<val>
                                   Change LMA and VMA of section <name> by <val>
     --change-section-lma <name>{=|+|-}<val>
                                   Change the LMA of section <name> by <val>
     --change-section-vma <name>{=|+|-}<val>
                                   Change the VMA of section <name> by <val>
    {--[no-]change-warnings|--[no-]adjust-warnings}
                                   Warn if a named section does not exist
     --set-section-flags <name>=<flags>
                                   Set section <name>'s properties to <flags>
     --add-section <name>=<file>   Add section <name> found in <file> to output
     --update-section <name>=<file>
                                   Update contents of section <name> with
                                   contents found in <file>
     --dump-section <name>=<file>  Dump the contents of section <name> into <file>
     --rename-section <old>=<new>[,<flags>] Rename section <old> to <new>
     --long-section-names {enable|disable|keep}
                                   Handle long section names in Coff objects.
     --change-leading-char         Force output format's leading character style
     --remove-leading-char         Remove leading character from global symbols
     --reverse-bytes=<num>         Reverse <num> bytes at a time, in output sections with content
     --redefine-sym <old>=<new>    Redefine symbol name <old> to <new>
     --redefine-syms <file>        --redefine-sym for all symbol pairs
                                     listed in <file>
     --srec-len <number>           Restrict the length of generated Srecords
     --srec-forceS3                Restrict the type of generated Srecords to S3
     --strip-symbols <file>        -N for all symbols listed in <file>
     --strip-unneeded-symbols <file>
                                   --strip-unneeded-symbol for all symbols listed
                                     in <file>
     --keep-symbols <file>         -K for all symbols listed in <file>
     --localize-symbols <file>     -L for all symbols listed in <file>
     --globalize-symbols <file>    --globalize-symbol for all in <file>
     --keep-global-symbols <file>  -G for all symbols listed in <file>
     --weaken-symbols <file>       -W for all symbols listed in <file>
     --add-symbol <name>=[<section>:]<value>[,<flags>]  Add a symbol
     --alt-machine-code <index>    Use the target's <index>'th alternative machine
     --writable-text               Mark the output text as writable
     --readonly-text               Make the output text write protected
     --pure                        Mark the output file as demand paged
     --impure                      Mark the output file as impure
     --prefix-symbols <prefix>     Add <prefix> to start of every symbol name
     --prefix-sections <prefix>    Add <prefix> to start of every section name
     --prefix-alloc-sections <prefix>
                                   Add <prefix> to start of every allocatable
                                     section name
     --file-alignment <num>        Set PE file alignment to <num>
     --heap <reserve>[,<commit>]   Set PE reserve/commit heap to <reserve>/
                                   <commit>
     --image-base <address>        Set PE image base to <address>
     --section-alignment <num>     Set PE section alignment to <num>
     --stack <reserve>[,<commit>]  Set PE reserve/commit stack to <reserve>/
                                   <commit>
     --subsystem <name>[:<version>]
                                   Set PE subsystem to <name> [& <version>]
     --compress-debug-sections[={none|zlib|zlib-gnu|zlib-gabi}]
                                   Compress DWARF debug sections using zlib
     --decompress-debug-sections   Decompress DWARF debug sections using zlib
     --elf-stt-common=[yes|no]     Generate ELF common symbols with STT_COMMON
                                     type
  -M  --merge-notes                Remove redundant entries in note sections
      --no-merge-notes             Do not attempt to remove redundant notes (default)
  -v --verbose                     List all object files modified
  @<file>                          Read options from <file>
  -V --version                     Display this program's version number
  -h --help                        Display this output
     --info                        List object formats & architectures supported
C:\FreePascalDeluxe\cross\bin\arm-embedded\arm-none-eabi-objcopy.exe: supported targets: elf32-littlearm elf32-bigarm elf32-little elf32-big plugin srec symbolsrec verilog tekhex binary ihex
project1.lpr(41,0) Error: Error while linking
project1.lpr(41,0) Verbose: There were 1 errors compiling module, stopping
Verbose: Compilation aborted
Verbose: C:\FreePascalDeluxe\fpc\bin\x86_64-win64\ppcrossarm.exe returned an error exitcode


MiR

  • Full Member
  • ***
  • Posts: 246
Re: Problem with assembler for STM32
« Reply #4 on: January 13, 2021, 03:39:10 pm »
Hmmm... havent seen binutils tools creating an error before, strange.....

Please add -sh parameter to your build, this will give you a linker script and a linker file.

The Linker file includes all the searchpaths so you can check if you have correctly set all needed searchpaths.

Running the linker script manually may also help to better identify the issue.

When stuck, please post content of the files

petex

  • Jr. Member
  • **
  • Posts: 69
Re: Problem with assembler for STM32
« Reply #5 on: January 13, 2021, 04:32:35 pm »
hmmmm.....
I took the space out of the project folder "blue pill" to "blue-pill" and it worked. (in so much as I got a hex output file, not checked it yet)  Not the first time this has happened to me, never seem to learn !!

Thanks for your help.

ccrause

  • Hero Member
  • *****
  • Posts: 845
Re: Problem with assembler for STM32
« Reply #6 on: January 13, 2021, 06:09:45 pm »
hmmmm.....
I took the space out of the project folder "blue pill" to "blue-pill" and it worked. (in so much as I got a hex output file, not checked it yet)
The compiler is supposed to properly quote the paths passed to external tools as required, so this sounds like a potential bug.  It would be interesting to see the contents of the linker script files (ppas.bat and linkxxx.res I think) generated with the -sh option (and a space in the path) as suggested by MiR.

 

TinyPortal © 2005-2018