Mf4.2 + gcc +stm32

OK, picked this project up again.

My reset issue was in part related to the odd naming for the fuses. I inadvertently enabled the hardware watchdog to start with the chip.

With that disabled my program always dies in the same spot. Seems to be malloc related. The first time malloc is called, deep inside, it dies, in side _sbrk_r() to be exact.

Why would this be?

My scatter file:

MEMORY
{
    LR_FLASH : ORIGIN = 0x08000000, LENGTH = 0xFE000
    LR_CONFIG : ORIGIN = 0x080FE000, LENGTH = 0x00002000
    CUSTOMHEAP : ORIGIN = 0x20015E00, LENGTH = 0x1FC
    HEAP : ORIGIN = 0x20018000, LENGTH = 0x7FFC
    STACK : ORIGIN = 0x20016000, LENGTH = 0x1FFC
    RELOC_RAM : ORIGIN = 0x20000000, LENGTH = 0x15E00
}
ENTRY(EntryPoint)
SECTIONS
{
    ER_FLASH  :
    {
        * (i.EntryPoint)
        * (SectionForBootstrapOperations)
        * (.text.BootEntry)
        * (.text*)
        * (i.*)
        * (t.*)
        * (.glue*)
        * (.rodata*)
        * (rodata)
        * (.constdata*)
        * (.conststring*)
        * (tinyclr_metadata)
        PROVIDE(_sbrk = .);
        PROVIDE(_write = .);
        PROVIDE(_close = .);
        PROVIDE(_fstat = .);
        PROVIDE(_lseek = .);
        PROVIDE(_read = .);
        PROVIDE(_exit = .);
        PROVIDE(_getpid = .);
        PROVIDE(_kill = .);
        PROVIDE(abort = .);
        PROVIDE(__errno = .);
        PROVIDE(_read = .);
        PROVIDE(isatty = .);
        PROVIDE(_isatty = .);
        LONG(0xE12FFF1E); 
    }>LR_FLASH
    ER_RAM_RO  : ALIGN(0x10)
    {
        * (VectorsTrampolines)
        * (SectionForFlashOperations)
    }>RELOC_RAM AT>LR_FLASH
    ER_RAM_RW  : ALIGN(0x10)
    {
        * (rwdata)
        * (.data*)
    }>RELOC_RAM AT>LR_FLASH
    .bss  : ALIGN(0x10)
    {
        * (.zidata*)
        * (.bss*)
        PROVIDE(__exidx_start = .); 
        PROVIDE(__exidx_end = .); 
        * (g_SSL_SeedData)
    }>RELOC_RAM
    /DISCARD/  :
    {
        * (.ARM.exidx*)
        * (.ARM.extab*)
    }
    ER_HEAP_BEGIN 0x20018000 :
    {
        * (SectionForHeapBegin)
    }
    ER_HEAP_END 0x2001FFFC :
    {
        * (SectionForHeapEnd)
    }
    ER_CUSTOM_HEAP_BEGIN 0x20015E00 :
    {
        * (SectionForCustomHeapBegin)
    }
    ER_CUSTOM_HEAP_END 0x20015FFC :
    {
        * (SectionForCustomHeapEnd)
    }
    ER_STACK_BOTTOM 0x20016000 :
    {
        * (SectionForStackBottom)
    }
    ER_STACK_TOP 0x20017FFC :
    {
        * (SectionForStackTop)
    }
    ER_CONFIG  :
    {
        * (SectionForConfig)
    }>LR_CONFIG
}
Load$$ER_FLASH$$Base = ADDR(ER_FLASH);
Image$$ER_FLASH$$Length = SIZEOF(ER_FLASH);
Image$$ER_RAM_RO$$Base = ADDR(ER_RAM_RO);
Image$$ER_RAM_RO$$Length = SIZEOF(ER_RAM_RO);
Load$$ER_RAM_RO$$Base = LOADADDR(ER_RAM_RO);
Image$$ER_RAM_RW$$Base = ADDR(ER_RAM_RW);
Image$$ER_RAM_RW$$Length = SIZEOF(ER_RAM_RW);
Load$$ER_RAM_RW$$Base = LOADADDR(ER_RAM_RW);
Image$$ER_RAM_RW$$ZI$$Base = ADDR(.bss);
Image$$ER_RAM_RW$$ZI$$Length = SIZEOF(.bss);
__use_no_semihosting_swi = 0;

Hmm, double post.
Got:

[quote]Gateway Time-out

The gateway did not receive a timely response from the upstream server or application.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Apache/2.2.16 (Unix) mod_ssl/2.2.16 OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4 Server at www.tinyclr.com Port 80[/quote]

Ok, that issue was because I switched compilers and didn’t delete the build folder. This meant that old and new object files where being linked. Really bad.

Next issue… :slight_smile:
Dying in Events_WaitForEvents. As in the ST gdb server dies. Dead. Seems that the interrupts are not enabled and the CPU sleeps indefinitely…

Getting further though.

Edit: Also, my “STM32_Flash_Driver::EraseBlock” code nukes the whole flash… :frowning:

Great. Flash isn’t arranged in a friendly manner on this chip.

First four sectors are 16KB each. Then one 64KB sector, then 7 sectors of 128KB.

What is BLOCKTYPE_STORAGE_A and BLOCKTYPE_STORAGE_B used for?
I need two sectors of 4KB, one for each of BLOCKTYPE_STORAGE_A and BLOCKTYPE_STORAGE_A.
Then I need one sector of 8KB for BLOCKTYPE_CONFIG.

Yes correct. We have the flash drivers so you do not need to worry about this part. Will share shortly

For the old file / new file problem it may help to run

msbuild /t:clean /p:flavor=flash;release=debug

This will clean out the output folder

:slight_smile: I would have liked to hear the words you uttered when you saw the flash get nuked :slight_smile: Glad that you found out about the jagged sector sizing.

AFAIK BLOCKTYPE_STORAGE_A / B are used as 2 banks for EWR. At this point you can live without them. Remove them from the BlockStorage header and the scatter file.

Have fun !

How do you handle it Gus? Do you do a “Read into Ram”/“Erase Sector”/“Modify Ram”/“Write Ram”?

Flash erase took me a few seconds to understand what happened, but the debugger did show that the chip only contained FFFFFF in every location… :slight_smile:

Turns out that the STM32F10X needed the Flash address to erase. It got the sector itself and did the job.

The STM32F4XX needs the sector number to erase. I dumped the full address into that register and that wrote the “EraseAll” bit and whammy! :-[

Errol,
You may want the top of your stack ER_STACK_TOP 0x20017FFC : aligned to 8 bytes.

Interestingly enough, with GCC at least, and probably the others, it’s possible to do everything in C, with no asm at all (not even for the vector table). To see how this can be done, see this YAGARTO sample project: http://www.yagarto.de/download/yagarto/STM32Test.zip

Has there been any more progress?

Started moving the Cerberus code over to GCC. Having a new issue with the IP stack, don’t think that was part of my previous porting attempt.

Getting this:

[quote]D:\MF\client_v4_2_comm\DeviceCode\pal\lwip\SocketsDriver\lwIP__Sockets.cpp: In static member function ‘static int LWIP_SOCKETS_Driver::GetNativeError(int)’:
D:\MF\client_v4_2_comm\DeviceCode\pal\lwip\SocketsDriver\lwIP__Sockets.cpp:1075:9: error: duplicate case value
D:\MF\client_v4_2_comm\DeviceCode\pal\lwip\SocketsDriver\lwIP__Sockets.cpp:998:9: error: previously used here[/quote]

But they are different #defines with different defined values.
Line 1075

case ESHUTDOWN:

Line 998

case ENOTSOCK:

Defined in D:\MF\client_v4_2_comm\DeviceCode\pal\lwip\lwip_1_3_2\src\include\lwip\arch.h

#define  ENOTSOCK  88  /* Socket operation on non-socket */
 #define  ESHUTDOWN  108  /* Cannot send after transport endpoint shutdown */

I don’t get it…

What version/distribution of GCC are you building with?

[quote]arm-none-eabi-cpp.exe (Sourcery CodeBench Lite 2011.09-69) 4.6.1
Copyright © 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.[/quote]

Make sure you vote for the issue here: http://netmf.codeplex.com/workitem/1346 if support for newer versions of GCC is important to you.

Voted.

Don’t know if the compiler is the issue though. Will try older compiler tonight. I just changed the #define for one from 108 to 1108 and it compiled.

The only real compiler issue I have had was with tinycrt.c, I think. There was some varg mangling or something that I just removed as GCC now complies to the standard and it doesn’t need mangling anymore…

I’m trying this out too, as Architect, I want to get the STMF1 port working first. Imanaged to get Sourcery CGG 4.6.1 working and most code compiles.

The assembler code is causing me headache though.

What is the correct GCC syntax for these here:

VectorsHandlers.s:38: Error: invalid register list to push/pop instruction – push {r0-r11}' VectorsHandlers.s:57: Error: invalid register list to push/pop instruction --push {r0-r12,r14}'
IDelayLoop.s:18: Error: instruction not supported in Thumb16 mode – `subs r0,r0,#4
Besides these I still have to convert SmartPtr_cortex asm…

PS: @ Architect: did the move to a newer GCC fix those duplicate “BX lr” errors?

@ maoli
Will look when I get home a bit later…

@ maoli

I don’t have these errors,but I haven’t touch my GCC for awhile. :frowning: - Busy at work

@ maoli
I don’t know if this fixed the thumb16 error or only hid it, but I put this at the top of the file:

	.syntax unified
	.thumb

And this before the function that contains the subs

.thumb_func

For the push error I only added “.syntax unified” to the top of the file.

This might all be very bad… :slight_smile:

Just checked mine. I do have .syntax unified The rest I might have added as command line options in the config file.

Damn it, I was just going to post that my assembler code was missing
.syntax unified
.thumb
compiles fine now, whatever this means :slight_smile:

Thx.