Recent

Author Topic: Can't Compile wiki examples for the stm32f103c8  (Read 4332 times)

chucky

  • New Member
  • *
  • Posts: 42
Can't Compile wiki examples for the stm32f103c8
« on: September 03, 2022, 12:38:14 am »
I installed fpcupdeluxe-x86-64-linux V2.2.0k and loaded the trunk releases of fpc and lazarus. I then installed the cross compiler for arm embedded. That gave me fpc 3.3.1 and lazarus 2.3

When I try to compile the WIKI example for blinking the led on the bluepill I get
 Indentifier not found "PORTC"

This is the complete code listing in the wiki

program project1;

{$O-}

procedure delay;
var
  i : uint32;
begin
  for i := 0 to 500000 do
    begin
      asm
        nop   // empty instruction
      end;
    end;
end;

begin
  // turn on Port C
  RCC.APB2ENR := RCC.APB2ENR or (%1 shl 4);

  // Pin 13 from Port C to Output
  PortC.CRH := $00300000;

  // Note: The LED lights up at LOW.
  while true do
    begin
      // Pin 13 - High
      PortC.BSRR := 1 shl 13;
      Delay;

      // Pin 13 - Low
      PortC.BRR := 1 shl 13;
      Delay;
    end;
 end.

Here are my command line parameters:

/home/pappy/fpcupdeluxe/fpc/bin/x86_64-linux/fpc.sh
-Tembedded
-Parm
-CpARMV7M
-MObjFPC
-Scghi
-O1
-l
-vewnhibq
-Filib/arm-embedded
-Fu.
-FUlib/arm-embedded
-FE.
-oproject1
-WpSTM32F103C8

If I add
  Uses stm32f10x_md;
The compilation is successful but it bombs out in the linking phase with multiple errors stating multiple definitions in various functions.

Im starting lazarus using the local fpc.cfg file which was automatically generated by fpcupdeluxe.

What am i missing here? The cross binutils were downloaded and stored automatically by fpcupdelexe when I installed the cross compiler.

I tried another wiki listing for blinking the led and I get the same PORTC not found.

Id appreciate any help.

           

ccrause

  • Hero Member
  • *****
  • Posts: 1083
Re: Can't Compile wiki examples for the stm32f103c8
« Reply #1 on: September 03, 2022, 08:10:42 am »
-WpSTM32F103C8
From wiki: -WpSTM32F103X8
It is easy to miss, the C in the controller name should change to X.

chucky

  • New Member
  • *
  • Posts: 42
Re: Can't Compile wiki examples for the stm32f103c8
« Reply #2 on: September 04, 2022, 12:47:43 pm »
Thanks so much. It works!

But does this make the compiler use a different rtl that has the Ports defined? How do you know which source is being used? In the compile Options tab I pressed the All options button and then scrolled down to the -Wp parameter and selected the drop down list and chose the name of the controller chip on the board assuming this was the correct choice, which in fact wasn't. very confusing to me.


PascalDragon

  • Hero Member
  • *****
  • Posts: 6238
  • Compiler Developer
Re: Can't Compile wiki examples for the stm32f103c8
« Reply #3 on: September 04, 2022, 08:44:34 pm »
But does this make the compiler use a different rtl that has the Ports defined? How do you know which source is being used? In the compile Options tab I pressed the All options button and then scrolled down to the -Wp parameter and selected the drop down list and chose the name of the controller chip on the board assuming this was the correct choice, which in fact wasn't. very confusing to me.

It makes the compiler pick the correct unit for the microcontroller which contains the low level port and register declarations for your microcontroller. The RTL itself is independant of that. Third party frameworks however may depend on the microcontroller however and thus you'll need to recompile them for each microcontroller you want to use.

ccrause

  • Hero Member
  • *****
  • Posts: 1083
Re: Can't Compile wiki examples for the stm32f103c8
« Reply #4 on: September 05, 2022, 08:38:27 am »
In the compile Options tab I pressed the All options button and then scrolled down to the -Wp parameter and selected the drop down list and chose the name of the controller chip on the board assuming this was the correct choice, which in fact wasn't. very confusing to me.
See attached picture for the list of ARM controllers I can see (Lazarus 2.2.2, FPC 3.2.2),
I only see STM32L103X8 in the -Wp list, not STM32L103C8.

Which versions of Lazarus and FPC are you using?

chucky

  • New Member
  • *
  • Posts: 42
Re: Can't Compile wiki examples for the stm32f103c8
« Reply #5 on: September 05, 2022, 08:53:09 pm »
Im using Lazarus 2.3.0 and fpc 3.3.1

Reading general topics in the forum on embedded programing it looked like everyone was using the trunk version. This version contains much much more selections for the -Wp option. Should I be using the the latest stable version fpc 3.2.2?

chucky

  • New Member
  • *
  • Posts: 42
Re: Can't Compile wiki examples for the stm32f103c8
« Reply #6 on: September 07, 2022, 03:54:09 am »
I next tried the ARM Embedded Tutorial - Simple Timer at:
https://wiki.freepascal.org/ARM_Embedded_Tutorial_-_Simple_Timer

This uses an Interrupt from timer 2. I got it to compile with no errors using fpc 3.3.1 and laz 2.3.0. When I flash the bluepill it just lights up the led and the led stays solid on, no blinking. I tried to compile with the fpc 3.2.2 and lax 2.2.0 but was unable to even get a successful compile.

with fpc 3.3.1 and laz 2.3.0 I could get a successful compile using -WpSTM32F103C8 but nothing else:

/home/pappy/fpcupdeluxe/fpc/bin/x86_64-linux/fpc.sh
-Tembedded
-Parm
-CpARMV7M
-MObjFPC
-Scghi
-O1
-l
-vewnhibq
-Filib/arm-embedded
-Fu.
-FUlib/arm-embedded
-FE.
-oproject1
-WpSTM32F103C8

the compiler gives one Hint : Local proc "Timer2_Interrupt" is not used.

I went back and studied the code for errors but I copied the example as given.

I guess embedded development is advancing so fast that these examples are becoming outdated.

Can anyone tell me what I'm doing wrong?



ccrause

  • Hero Member
  • *****
  • Posts: 1083
Re: Can't Compile wiki examples for the stm32f103c8
« Reply #7 on: September 07, 2022, 07:14:59 am »
Im using Lazarus 2.3.0 and fpc 3.3.1

Reading general topics in the forum on embedded programing it looked like everyone was using the trunk version. This version contains much much more selections for the -Wp option. Should I be using the the latest stable version fpc 3.2.2?
No need to use 3.2.2, it just happened to be the version of the ARM cross compiler I had for testing.

ccrause

  • Hero Member
  • *****
  • Posts: 1083
Re: Can't Compile wiki examples for the stm32f103c8
« Reply #8 on: September 07, 2022, 08:22:00 pm »
with fpc 3.3.1 and laz 2.3.0 I could get a successful compile using -WpSTM32F103C8 but nothing else:
After installing the latest FPC 3.3.1 for ARM using fpcupdeluxe, I get the following error when specifying -WpSTM32F103C8:
Code: [Select]
Error: Illegal parameter: -WpSTM32F103C8
Changing to -WpSTM32F103X8 proceeds further, but then the compiler complains about:
Code: [Select]
timer_blink.lpr(19,24) Error: Identifier not found "GPIOC"This makes sense because looking in unit stm32f10x_md.pp shows no GPIOC variable, but rather a likely PortC variable.  I don't use ARM, so all I can say is that I cannot compile the wiki example either.  One problem is that your compiler accepts -WpSTM32F103C8 as valid, while mine doesn't.  Looking at the supported controllers listed by ppcrossarm does not show STM32F103C8:
Code: [Select]
~/fpcupdeluxe/working/fpc/bin/x86_64-linux$ ./ppcrossarm -i | grep F103
  STM32F102X8,STM32F102XB,STM32F103X4,STM32F103X6,STM32F103X8,STM32F103XB,
  STM32F103XC,STM32F103XD,STM32F103XE,STM32F103XF,STM32F103XG,STM32F107X8,
Can you please enable "Show everything (-va)" under your project's Verbosity setting in Lazarus, rebuild the timer example and attach the full compiler output to a reply.  Perhaps this will reveal something interesting.

I was hoping that one of the more experienced ARM users would have commented by now...

Laksen

  • Hero Member
  • *****
  • Posts: 802
    • J-Software
Re: Can't Compile wiki examples for the stm32f103c8
« Reply #9 on: September 07, 2022, 09:52:25 pm »
If the compiler accepts a -Wp<arg> parameter that doesn't exist it should of course be reported as an error

I'm pretty sure -WpSTM32F103C8 has never been a supported parameter in trunk. STM32F103X8 was added 9 years ago, where before there was very few STM32's

kupferstecher

  • Hero Member
  • *****
  • Posts: 604
Re: Can't Compile wiki examples for the stm32f103c8
« Reply #10 on: September 07, 2022, 11:04:11 pm »
See attached a minimum project using the Timer2-Update-Interrupt.

Note that the UART (UART1) is remapped to the Pins PB6 (TXD) and PB7 (RXD). But that could be changed in TUART.Init: Comment out line GPIO_PinRemapConfig and set the port settings.

Hope it helps!

Regards~




chucky

  • New Member
  • *
  • Posts: 42
Re: Can't Compile wiki examples for the stm32f103c8
« Reply #11 on: September 09, 2022, 07:05:19 pm »
If the compiler accepts a -Wp<arg> parameter that doesn't exist it should of course be reported as an error

I'm pretty sure -WpSTM32F103C8 has never been a supported parameter in trunk. STM32F103X8 was added 9 years ago, where before there was very few STM32's

Code: Pascal  [Select][+][-]
  1. pappy@delta:~/fpcupdeluxe/fpc/bin/x86_64-linux$ ./ppcrossarm -i | grep F103
  2.   STM32F102X4,STM32F102X6,STM32F102X8,STM32F102XB,STM32F103X4,STM32F103X6,
  3.   STM32F103X8,STM32F103XB,STM32F103XC,STM32F103XD,STM32F103XE,STM32F103XF,
  4.   STM32F103XG,STM32F105X8,STM32F105XB,STM32F105XC,STM32F107X8,STM32F107XB,
  5.   STM32F103C4,STM32F103C6,STM32F103C8,STM32F103CB,STM32F103R4,STM32F103R6,
  6.   STM32F103R8,STM32F103RB,STM32F103RC,STM32F103RD,STM32F103RE,STM32F103RF,
  7.   STM32F103RG,STM32F103T4,STM32F103T6,STM32F103T8,STM32F103TB,STM32F103V8,
  8.   STM32F103VB,STM32F103VC,STM32F103VD,STM32F103VE,STM32F103VF,STM32F103VG,
  9.   STM32F103ZC,STM32F103ZD,STM32F103ZE,STM32F103ZF,STM32F103ZG,STM32F105R8,
  10.   STM32F107RC,STM32F107VB,STM32F107VC,NUCLEOF103RB,STM32VLDISCOVERY,
  11.  

This was what my compiler reported for -Wp options. Ive downloaded pcupdeluxe several times but im pretty sure I deleted all directories between downloads. The only differences I've made is in the cross compiler downloads I've changed the Subarch settings for Arm target from armhf to armeland the ABI setting to eabi.

ccrause

  • Hero Member
  • *****
  • Posts: 1083
Re: Can't Compile wiki examples for the stm32f103c8
« Reply #12 on: September 10, 2022, 07:28:39 am »
Code: Pascal  [Select][+][-]
  1. pappy@delta:~/fpcupdeluxe/fpc/bin/x86_64-linux$ ./ppcrossarm -i | grep F103
  2.   STM32F102X4,STM32F102X6,STM32F102X8,STM32F102XB,STM32F103X4,STM32F103X6,
  3.   STM32F103X8,STM32F103XB,STM32F103XC,STM32F103XD,STM32F103XE,STM32F103XF,
  4.   STM32F103XG,STM32F105X8,STM32F105XB,STM32F105XC,STM32F107X8,STM32F107XB,
  5.   STM32F103C4,STM32F103C6,STM32F103C8,STM32F103CB,STM32F103R4,STM32F103R6,
  6.   STM32F103R8,STM32F103RB,STM32F103RC,STM32F103RD,STM32F103RE,STM32F103RF,
  7.   STM32F103RG,STM32F103T4,STM32F103T6,STM32F103T8,STM32F103TB,STM32F103V8,
  8.   STM32F103VB,STM32F103VC,STM32F103VD,STM32F103VE,STM32F103VF,STM32F103VG,
  9.   STM32F103ZC,STM32F103ZD,STM32F103ZE,STM32F103ZF,STM32F103ZG,STM32F105R8,
  10.   STM32F107RC,STM32F107VB,STM32F107VC,NUCLEOF103RB,STM32VLDISCOVERY,
  11.  

This was what my compiler reported for -Wp options. Ive downloaded pcupdeluxe several times but im pretty sure I deleted all directories between downloads. The only differences I've made is in the cross compiler downloads I've changed the Subarch settings for Arm target from armhf to armeland the ABI setting to eabi.
Clearly your cross compiler reports a longer list of controllers than the version I compiled.  Could it be that you have a custom patch installed?

Please report the FPC source revision (content of ~/fpcupdeluxe/fpcsrc/compiler/revision.txt).  Mine is '11847-g3a11ee9a14', or main version from September 6th.

Please show the output of the following command: ~/fpcupdeluxe/fpcsrc/compiler$ rgrep -n -i NUCLEOF103. This is one of the controllers I don't see listed in my version of the FPC source code.  All supported controllers are listed in compiler/arm/cpuinfo.pas, and a quick search of the current main version here doesn't contain the text NUCLEOF103

chucky

  • New Member
  • *
  • Posts: 42
Re: Can't Compile wiki examples for the stm32f103c8
« Reply #13 on: November 06, 2022, 09:49:40 am »
I finally starting getting somewhere with the arm tutorials. I'm such a newbie with embedded controllers but then that's what they're there for, aren't they?

The arm development is progressing at fast pace and they quickly become outdated and non-functional.

Can anyone edit these tutorials or is that not considered polite?

dbannon

  • Hero Member
  • *****
  • Posts: 3619
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Can't Compile wiki examples for the stm32f103c8
« Reply #14 on: November 06, 2022, 11:36:43 am »
> Can anyone edit these tutorials or is that not considered polite?

Yep, anyone. And if you do a good job, no one will revert it !

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

 

TinyPortal © 2005-2018