Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2016-03

STM32F407 fun

9 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Andrew Haines

Hi,

I've been trying to get a very simple program to run on my discovery board that I've had for a while(STM32F407VG). Using st-util with gdb I managed to make some progress.

I've been using the code in fpc for STM32F429 since it's pretty similar. My first problem was that the stackpointer was too high. The STM32F407VG has 64kb less memory than the STM32F429. I added a define in compiler/arm/cpuinfo.pas with the correct info and had it use the STM32F429 unit. That fixed my first problem.

The next/current problem is in CommonInit in system.
SynchronizeTimeoutEvent:=RtlEventCreate;

RtlEventCreate has:
result:=currenttm.rtleventcreate();
This produces the assembly:
0x8007e08 <SYSTEM_$$_RTLEVENTCREATE$$PRTLEVENT> push {lr} (gdb) i registers pc
pc 0x8007e0a 0x8007e0a
<SYSTEM_$$_RTLEVENTCREATE$$PRTLEVENT+2>

0x8007e0a <SYSTEM_$$_RTLEVENTCREATE$$PRTLEVENT+2> ldr r0, [pc, #8] ; (0x8007e14 <SYSTEM_$$_RTLEVENTCREATE$$PRTLEVENT+12>) (gdb) i registers r0
r0 0x20001dc0 536878528 // the address 1dc0 seems reasonable. Location of currenttm+rtleventcreate?

0x8007e0c <SYSTEM_$$_RTLEVENTCREATE$$PRTLEVENT+4> ldr r0, [r0, #0] (gdb) i registers r0
r0 0x0 0

0x8007e0e <SYSTEM_$$_RTLEVENTCREATE$$PRTLEVENT+6> blx r0

For the last instruction r0 is nil. This causes the default interrupt handler to be called which loops forever.

backtrace is:
(gdb) bt
#0 0x08007e0e in SYSTEM_$$_RTLEVENTCREATE$$PRTLEVENT () #1 0x0800ce5e in CLASSES_$$_COMMONINIT ()
#2 0x08012886 in CLASSES_$$_init ()
#3 0x08007a5c in fpc_initializeunits ()
#4 0x08000294 in main () at blinky.lpr:48

I compiled the crosscompiler with:
make clean buildbase CROSSINSTALL=1 CROSSOPT="-XParm-none-eabi-" OS_TARGET=embedded CPU_TARGET=arm SUBARCH=armv7em

the program is compiled with
-Oparmv7em
-WpSTM32F407VG

I'm guessing there is some define I have to use and everything will start working :)

Where do I go from here?

Thanks in advance,

Andrew Haines

Reply by email

Jeppe Johansen
to Andrew Haines
Andrew Haines wrote
I'm guessing there is some define I have to use and everything will start working :) Where do I go from here?

You need to remove classes from your used units. It needs a thread manager to work.
The default thread manager simply halts the program if anything calls it, so that's exactly what you are seeing.

Reply by email

Michael Ring
to Andrew Haines: I've been trying to get a very simple program to run on my discovery board that I've had…

Are you sure about RAM? I checked in cpuinfo, it is set to 128MB, this matches what is written in the user manual, (Page 70)

http://www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/DM00037051.pdf

or are the last 16k for some special use? Could not find a hint while quickly searching through the manual.

Michael

Andrew Haines wrote 67 lines
Hi, I've been trying to get a very simple program to run on my discovery board that I've had for a while(STM32F407VG). Using st-util with gdb I managed to make some progress. I've been using the code in fpc for STM32F429 since it's pretty similar. My first problem was that the stackpointer was too high. The STM32F407VG has 64kb less memory than the STM32F429. I added a define in compiler/arm/cpuinfo.pas with the correct info and had it use the STM32F429 unit. That fixed my first problem. The next/current problem is in CommonInit in system. SynchronizeTimeoutEvent:=RtlEventCreate; RtlEventCreate has: result:=currenttm.rtleventcreate(); This produces the assembly: 0x8007e08 <SYSTEM_$$_RTLEVENTCREATE$$PRTLEVENT> push {lr} (gdb) i registers pc pc 0x8007e0a 0x8007e0a <SYSTEM_$$_RTLEVENTCREATE$$PRTLEVENT+2> 0x8007e0a <SYSTEM_$$_RTLEVENTCREATE$$PRTLEVENT+2> ldr r0, [pc, #8] ; (0x8007e14 <SYSTEM_$$_RTLEVENTCREATE$$PRTLEVENT+12>) (gdb) i registers r0 r0 0x20001dc0 536878528 // the address 1dc0 seems reasonable. Location of currenttm+rtleventcreate? 0x8007e0c <SYSTEM_$$_RTLEVENTCREATE$$PRTLEVENT+4> ldr r0, [r0, #0] (gdb) i registers r0 r0 0x0 0 0x8007e0e <SYSTEM_$$_RTLEVENTCREATE$$PRTLEVENT+6> blx r0 For the last instruction r0 is nil. This causes the default interrupt handler to be called which loops forever. backtrace is: (gdb) bt #0 0x08007e0e in SYSTEM_$$_RTLEVENTCREATE$$PRTLEVENT () #1 0x0800ce5e in CLASSES_$$_COMMONINIT () #2 0x08012886 in CLASSES_$$_init () #3 0x08007a5c in fpc_initializeunits () #4 0x08000294 in main () at blinky.lpr:48 I compiled the crosscompiler with: make clean buildbase CROSSINSTALL=1 CROSSOPT="-XParm-none-eabi-" OS_TARGET=embedded CPU_TARGET=arm SUBARCH=armv7em the program is compiled with -Oparmv7em -WpSTM32F407VG I'm guessing there is some define I have to use and everything will start working :) Where do I go from here? Thanks in advance, Andrew Haines _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email

Michael Ring
to Michael Ring

Re-reading your initial mail I am kind of wondering what you actually did ?

When using -WpSTM32F407VG you will automagially use stm32f407xx.pp unit which is the correct one for your chip and also stack should be correct as ram size is set to 128MB.

How/why did you use STM32F429 unit for the chip?

Michael

Michael Ring wrote 84 lines
Are you sure about RAM? I checked in cpuinfo, it is set to 128MB, this matches what is written in the user manual, (Page 70) http://www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/DM00037051.pdf or are the last 16k for some special use? Could not find a hint while quickly searching through the manual. Michael Am 19.03.16 um 04:47 schrieb Andrew Haines: > Hi, > > I've been trying to get a very simple program to run on my discovery > board that I've had for a while(STM32F407VG). Using st-util with gdb > I managed to make some progress. > > I've been using the code in fpc for STM32F429 since it's pretty > similar. My first problem was that the stackpointer was too high. The > STM32F407VG has 64kb less memory than the STM32F429. I added a define > in compiler/arm/cpuinfo.pas with the correct info and had it use the > STM32F429 unit. That fixed my first problem. > > The next/current problem is in CommonInit in system. > SynchronizeTimeoutEvent:=RtlEventCreate; > > RtlEventCreate has: > result:=currenttm.rtleventcreate(); > This produces the assembly: > 0x8007e08 <SYSTEM_$$_RTLEVENTCREATE$$PRTLEVENT> push {lr} > (gdb) i registers pc > pc 0x8007e0a 0x8007e0a > <SYSTEM_$$_RTLEVENTCREATE$$PRTLEVENT+2> > > 0x8007e0a <SYSTEM_$$_RTLEVENTCREATE$$PRTLEVENT+2> ldr r0, [pc, #8] > ; (0x8007e14 <SYSTEM_$$_RTLEVENTCREATE$$PRTLEVENT+12>) > (gdb) i registers r0 > r0 0x20001dc0 536878528 // the address 1dc0 seems > reasonable. Location of currenttm+rtleventcreate? > > 0x8007e0c <SYSTEM_$$_RTLEVENTCREATE$$PRTLEVENT+4> ldr r0, [r0, #0] > (gdb) i registers r0 > r0 0x0 0 > > 0x8007e0e <SYSTEM_$$_RTLEVENTCREATE$$PRTLEVENT+6> blx r0 > > For the last instruction r0 is nil. This causes the default interrupt > handler to be called which loops forever. > > backtrace is: > (gdb) bt > #0 0x08007e0e in SYSTEM_$$_RTLEVENTCREATE$$PRTLEVENT () > #1 0x0800ce5e in CLASSES_$$_COMMONINIT () > #2 0x08012886 in CLASSES_$$_init () > #3 0x08007a5c in fpc_initializeunits () > #4 0x08000294 in main () at blinky.lpr:48 > > I compiled the crosscompiler with: > make clean buildbase CROSSINSTALL=1 CROSSOPT="-XParm-none-eabi-" > OS_TARGET=embedded CPU_TARGET=arm SUBARCH=armv7em > > the program is compiled with > -Oparmv7em > -WpSTM32F407VG > > I'm guessing there is some define I have to use and everything will > start working :) > > Where do I go from here? > > Thanks in advance, > > Andrew Haines > > > _______________________________________________ > fpc-devel maillist - > http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email

Andrew Haines
to Jeppe Johansen: You need to remove classes from your used units. It needs a thread manager to work. The…
Jeppe Johansen wrote 12 lines
On 03/19/2016 04:47 AM, Andrew Haines wrote: > I'm guessing there is some define I have to use and everything will > start working :) > > Where do I go from here? You need to remove classes from your used units. It needs a thread manager to work. The default thread manager simply halts the program if anything calls it, so that's exactly what you are seeing. _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Ok well that was easy :) It is working now.

Thanks again,

Andrew

Reply by email

Andrew Haines
to Michael Ring: Are you sure about RAM? I checked in cpuinfo, it is set to 128MB, this matches what is…
Michael Ring wrote 6 lines
Re-reading your initial mail I am kind of wondering what you actually did ? When using -WpSTM32F407VG you will automagially use stm32f407xx.pp unit which is the correct one for your chip and also stack should be correct as ram size is set to 128MB.

First off thanks for 'm not sure where you are getting 128MB...?

How/why did you use STM32F429 unit for the chip?

There was no entry in fpc for STM32F407VG. I added
+ (controllertypestr:'STM32F407VG'; controllerunitstr:'STM32F429'; cputype:cpu_armv7em; fputype:fpu_soft; flashbase:$08000000; flashsize:$00080000; srambase:$20000000; sramsize:$00020000),

Show quoted text 5 lines
Michael > Am 19.03.16 um 12:36 schrieb Michael Ring: >/Are you sure about RAM? I checked in cpuinfo, it is set to 128MB, this />>/matches what is written in the user manual, (Page 70) />>//>>/http://www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/DM00037051.pdf

/>>//>>

On the first page of that link under memories it says:

Up to 192+4 Kbytes of SRAM including 64-
Kbyte of CCM (core coupled memory) data
RAM.

Looking in the C header file stm32f4xx.h I find:
#define CCMDATARAM_BASE ((uint32_t)0x10000000) /*!< CCM(core coupled memory) data RAM(64 KB) base address in the alias region */ #define SRAM1_BASE ((uint32_t)0x20000000) /*!< SRAM1(112 KB) base address in the alias region */ #define SRAM2_BASE ((uint32_t)0x2001C000) /*!< SRAM2(16 KB) base address in the alias region */

So starting from SRAM1_BASE there is 128kB of contiguous memory.

1024 * 128 = $20000

Looking at http://www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/DM00071990.pdf for STM32F429VG is says: Up to 256+4 KB of SRAM including 64-KB
of CCM (core coupled memory) data RAM

I couldn't find a specific header for the *29 chip but I'm assuming the extra 64kB memory it has is in that block so there is 192kB of memory. This matches the define for the *29 chip: (controllertypestr:'STM32F429XG'; controllerunitstr:'STM32F429'; cputype:cpu_armv7em; fputype:fpu_soft; flashbase:$08000000; flashsize:$00100000; srambase:$20000000; sramsize:$00030000),

1024 * 192 = $30000

//>>/or are the last 16k for some special use? Could not find a hint while />>/quickly searching through the manual. />>//>>/Michael />>

I attached the changes I made to include the stm32f407vg chip in fpc.

Andrew

Reply by email

Michael Ring
to Andrew Haines

OK, seems you are not using trunk or an outdated version of trunk as there are quite a number of units for stm32f4 available in current trunk:

stm32f401xx.pp
stm32f407xx.pp
stm32f411xe.pp
stm32f429xx.pp
stm32f446xx.pp

So I'd recomment to either upgrade to current trunk or at least copy the unit specially made for your chip to your installation and compile it by adding it to the list of controller units in the embedded rtl makefile and changing controllerunitstr to match the correct filename.

Good that we agree that 128MB is the right memory size, I first thought that you are using trunk and that the 128MB configured in the cpuinfo are wrong and instead 112MB is correct.
I haven't compiled for this chip for a while, I am mostly targeting f401, f411 and lately the f469 chips (I really like the STM32F469 Discovery board) these days...

Michael

Andrew Haines wrote 81 lines
On 03/19/2016 07:36 AM, Michael Ring wrote: > Re-reading your initial mail I am kind of wondering what you actually > did ? > > When using -WpSTM32F407VG you will automagially use stm32f407xx.pp unit > which is the correct one for your chip and also stack should be correct > as ram size is set to 128MB. > First off thanks for 'm not sure where you are getting 128MB...? > How/why did you use STM32F429 unit for the chip? There was no entry in fpc for STM32F407VG. I added + (controllertypestr:'STM32F407VG'; controllerunitstr:'STM32F429'; cputype:cpu_armv7em; fputype:fpu_soft; flashbase:$08000000; flashsize:$00080000; srambase:$20000000; sramsize:$00020000), > > Michael >> Am 19.03.16 um 12:36 schrieb Michael Ring: >> /Are you sure about RAM? I checked in cpuinfo, it is set to 128MB, >> this />>/matches what is written in the user manual, (Page 70) >> />>//>>/http://www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/DM00037051.pdf > />>//>> On the first page of that link under memories it says: Up to 192+4 Kbytes of SRAM including 64- Kbyte of CCM (core coupled memory) data RAM. Looking in the C header file stm32f4xx.h I find: #define CCMDATARAM_BASE ((uint32_t)0x10000000) /*!< CCM(core coupled memory) data RAM(64 KB) base address in the alias region */ #define SRAM1_BASE ((uint32_t)0x20000000) /*!< SRAM1(112 KB) base address in the alias region */ #define SRAM2_BASE ((uint32_t)0x2001C000) /*!< SRAM2(16 KB) base address in the alias region */ So starting from SRAM1_BASE there is 128kB of contiguous memory. 1024 * 128 = $20000 Looking at http://www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/DM00071990.pdf for STM32F429VG is says: Up to 256+4 KB of SRAM including 64-KB of CCM (core coupled memory) data RAM I couldn't find a specific header for the *29 chip but I'm assuming the extra 64kB memory it has is in that block so there is 192kB of memory. This matches the define for the *29 chip: (controllertypestr:'STM32F429XG'; controllerunitstr:'STM32F429'; cputype:cpu_armv7em; fputype:fpu_soft; flashbase:$08000000; flashsize:$00100000; srambase:$20000000; sramsize:$00030000), 1024 * 192 = $30000 //>>/or are the last 16k for some special use? Could not find a hint while />>/quickly searching through the manual. />>//>>/Michael />> I attached the changes I made to include the stm32f407vg chip in fpc. Andrew _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email

Michael Ring
to Michael Ring

Aehm, and yes, I meant 128kb, not 128MB ;-)

Michael

Michael Ring wrote 111 lines
OK, seems you are not using trunk or an outdated version of trunk as there are quite a number of units for stm32f4 available in current trunk: stm32f401xx.pp stm32f407xx.pp stm32f411xe.pp stm32f429xx.pp stm32f446xx.pp So I'd recomment to either upgrade to current trunk or at least copy the unit specially made for your chip to your installation and compile it by adding it to the list of controller units in the embedded rtl makefile and changing controllerunitstr to match the correct filename. Good that we agree that 128MB is the right memory size, I first thought that you are using trunk and that the 128MB configured in the cpuinfo are wrong and instead 112MB is correct. I haven't compiled for this chip for a while, I am mostly targeting f401, f411 and lately the f469 chips (I really like the STM32F469 Discovery board) these days... Michael Am 19.03.16 um 14:03 schrieb Andrew Haines: > On 03/19/2016 07:36 AM, Michael Ring wrote: > >> Re-reading your initial mail I am kind of wondering what you >> actually did ? >> >> When using -WpSTM32F407VG you will automagially use stm32f407xx.pp unit >> which is the correct one for your chip and also stack should be correct >> as ram size is set to 128MB. >> > > First off thanks for 'm not sure where you are > getting 128MB...? > >> How/why did you use STM32F429 unit for the chip? > > There was no entry in fpc for STM32F407VG. I added > + (controllertypestr:'STM32F407VG'; > controllerunitstr:'STM32F429'; cputype:cpu_armv7em; > fputype:fpu_soft; flashbase:$08000000; flashsize:$00080000; > srambase:$20000000; sramsize:$00020000), > >> >> Michael > >>> Am 19.03.16 um 12:36 schrieb Michael Ring: >>> /Are you sure about RAM? I checked in cpuinfo, it is set to 128MB, >>> this />>/matches what is written in the user manual, (Page 70) >>> />>//>>/http://www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/DM00037051.pdf >> > />>//>> > > On the first page of that link under memories it says: > > Up to 192+4 Kbytes of SRAM including 64- > Kbyte of CCM (core coupled memory) data > RAM. > > Looking in the C header file stm32f4xx.h I find: > #define CCMDATARAM_BASE ((uint32_t)0x10000000) /*!< CCM(core > coupled memory) data RAM(64 KB) base address in the alias region */ > #define SRAM1_BASE ((uint32_t)0x20000000) /*!< SRAM1(112 > KB) base address in the alias region */ > #define SRAM2_BASE ((uint32_t)0x2001C000) /*!< SRAM2(16 > KB) base address in the alias region */ > > So starting from SRAM1_BASE there is 128kB of contiguous memory. > > 1024 * 128 = $20000 > > Looking at > http://www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/DM00071990.pdf > for STM32F429VG is says: > Up to 256+4 KB of SRAM including 64-KB > of CCM (core coupled memory) data RAM > > I couldn't find a specific header for the *29 chip but I'm assuming > the extra 64kB memory it has is in that block so there is 192kB of > memory. This matches the define for the *29 chip: > (controllertypestr:'STM32F429XG'; > controllerunitstr:'STM32F429'; cputype:cpu_armv7em; > fputype:fpu_soft; flashbase:$08000000; flashsize:$00100000; > srambase:$20000000; sramsize:$00030000), > > 1024 * 192 = $30000 > > > //>>/or are the last 16k for some special use? Could not find a hint > while />>/quickly searching through the manual. />>//>>/Michael />> > > I attached the changes I made to include the stm32f407vg chip in fpc. > > > > Andrew > > > > > _______________________________________________ > fpc-devel maillist > http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email

Andrew Haines
to Michael Ring: OK, seems you are not using trunk or an outdated version of trunk as there are quite a…
Michael Ring wrote 13 lines
OK, seems you are not using trunk or an outdated version of trunk as there are quite a number of units for stm32f4 available in current trunk: stm32f401xx.pp stm32f407xx.pp stm32f411xe.pp stm32f429xx.pp stm32f446xx.pp So I'd recomment to either upgrade to current trunk or at least copy the unit specially made for your chip to your installation and compile it by adding it to the list of controller units in the embedded rtl makefile and changing controllerunitstr to match the correct filename.

Ok I updated. I was using a trunk version from late October. Fpc is moving pretty fast.

Show quoted text 8 lines
Good that we agree that 128MB is the right memory size, I first thought that you are using trunk and that the 128MB configured in the cpuinfo are wrong and instead 112MB is correct. I haven't compiled for this chip for a while, I am mostly targeting f401, f411 and lately the f469 chips (I really like the STM32F469 Discovery board) these days...

I've had this board for probably 6 years sitting waiting for me to do something with it. A year or two ago I got a HD44780 lcd to work with it using gcc. But didn't go further with it than that. I'm pretty inexperienced with embedded stuff.

Andrew

Reply by email