This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

FlashDev / FlashPrg for STM32F107

Hello.

I'm trying to set up a MCBSTM32C to have a Flash File System using the RL-ARM FlashFS library, but i'm having a bit of trouble i hoped someone could help me sort out.

In the book "Building Applications with RL-ARM" under RL-Flash introduction, there's a section discussing how to set up a Flash-based filesystem.

It calls out for the file FS_FlashPrg.c and FS_FlashDev.h under the folder C:\KEIL\ARM\RL\FLASHFS\FLASH then a subdirectory named according to your flash or microcontroller.

Looking in that folder i have the following folders:

25F640S33
AM29x800BB
AM29x800BBx2
AM29x800BT
AM29x800BTx2
AT45DB321C
AT45DB642D
LPC_IAP_128
LPC_IAP_256
SST39x320x
STR71x
STR75x
STR91x

I'm not sure which one would correspond to the STM32F107VC... Do I have to write my own drivers for this controller? If so, is there literature i can obtain covering how to do this?

Thanks for any insight.

- Per

Parents
  • so, I seem to be having a spot of trouble here.

    I followed the instructions, but I'm encountering a hard fault when i try the following code:

    FILE* fptr = fopen("f:\\test.txt", "w");
    

    Here's what I did:

    1. Copied the files FlashDev / FlashPrg from Keil\ARM\Flash\STM32F10x
    2. Modified FlashPrg. Everything was pretty straightforward except step 7 and 8.
    For 7, i encountered 2 chunks of code like:

    M16(adr) = *((unsigned short *)buf);      // Program Half Word
    

    I ASSUME I just need to add __packed to this so i would get

    M16(adr) = *((__packed unsigned short *)buf);      // Program Half Word
    


    Is this correct?

    for 8, i have no idea if i need to do anything...

    3. In FlashDev, i had to go back a few fimes ...

    It seemed to call for 2048-byte sectors for the 107-CL, so i created 128 of them in the macro FL_DEVICE.

    I compiled (worked) but when i ran the code above, Hard Fault.

    I then figured that maybe my File_Config.c is not set up right, so went in there and changed
    Base address to 0x0800 0000, in accordance with the memory map of the device. and size to 0x0004 0000, also in accordance to the memory map.

    This also crashed.

    I then realized that my program is using a certain amount of code, so i changed Base Address of the Flash Drive to 0x0802 0000 (up by 0x20000), and changed Device Size to 0x0002 0000 (down by 0x20000). In my mind this would create a flash drive in the range 0x0802 0000 -> 0x0803 FFFF. And as my code was less than 0x10000 bytes, i should be good?)

    again a crash.

    I poked at the settings for the project and changed 'IROM1 on-chip Read/Only Memory area' to 0x0800 0000, 0x20000 (down by half).

    Still crashing.

    I'm a bit at a loss here. any insight or knowledge to assist me here, would be greatly appreciated!

    thank you.

Reply
  • so, I seem to be having a spot of trouble here.

    I followed the instructions, but I'm encountering a hard fault when i try the following code:

    FILE* fptr = fopen("f:\\test.txt", "w");
    

    Here's what I did:

    1. Copied the files FlashDev / FlashPrg from Keil\ARM\Flash\STM32F10x
    2. Modified FlashPrg. Everything was pretty straightforward except step 7 and 8.
    For 7, i encountered 2 chunks of code like:

    M16(adr) = *((unsigned short *)buf);      // Program Half Word
    

    I ASSUME I just need to add __packed to this so i would get

    M16(adr) = *((__packed unsigned short *)buf);      // Program Half Word
    


    Is this correct?

    for 8, i have no idea if i need to do anything...

    3. In FlashDev, i had to go back a few fimes ...

    It seemed to call for 2048-byte sectors for the 107-CL, so i created 128 of them in the macro FL_DEVICE.

    I compiled (worked) but when i ran the code above, Hard Fault.

    I then figured that maybe my File_Config.c is not set up right, so went in there and changed
    Base address to 0x0800 0000, in accordance with the memory map of the device. and size to 0x0004 0000, also in accordance to the memory map.

    This also crashed.

    I then realized that my program is using a certain amount of code, so i changed Base Address of the Flash Drive to 0x0802 0000 (up by 0x20000), and changed Device Size to 0x0002 0000 (down by 0x20000). In my mind this would create a flash drive in the range 0x0802 0000 -> 0x0803 FFFF. And as my code was less than 0x10000 bytes, i should be good?)

    again a crash.

    I poked at the settings for the project and changed 'IROM1 on-chip Read/Only Memory area' to 0x0800 0000, 0x20000 (down by half).

    Still crashing.

    I'm a bit at a loss here. any insight or knowledge to assist me here, would be greatly appreciated!

    thank you.

Children
  • Ok, an update. I was able to set up Flash as a file system.. but i'm not sure it's working correctly.

    To make it work, I had found a reference manual for the 207 with 1024 KB flash, and they say this:

    Main memory
    Sector 0 0x0800 0000 - 0x0800 3FFF 16 Kbyte
    Sector 1 0x0800 4000 - 0x0800 7FFF 16 Kbyte
    Sector 2 0x0800 8000 - 0x0800 BFFF 16 Kbyte
    Sector 3 0x0800 C000 - 0x0800 FFFF 16 Kbyte
    Sector 4 0x0801 0000 - 0x0801 FFFF 64 Kbyte
    Sector 5 0x0802 0000 - 0x0803 FFFF 128 Kbyte
    Sector 6 0x0804 0000 - 0x0805 FFFF 128 Kbyte
    .
    .
    .
    .
    .
    .
    .
    .
    .
    Sector 11 0x080E 0000 - 0x080F FFFF 128 Kbyte
    

    So i placed the device start at 0x08000000, and sized it to 0x00020000 (128KB) and then in the FS_FlashDev.h I had only one sector starting at offset 0x00020000, and with size 128 KB.

    This works - i.e. i can open a file, write to it, and close it. But when I try to use ffind or fopen( ..., "r") on it, i cannot see it.

    Any ideas?

  • Some more information ...

    If i try to use any memory area at 0x0802 5800 or higher, the program i have will hard fault with the call stack as follows.

    HardFault_Handler()
    <0800135e()>
    fs_ReadData()
      adr <invisible>
      cnt <invisible>
      buf <invisible>
    fs_Find_File()
      fname 0x00000000
      fcb 0x20000090
      fa 0x20000b9d8
      buf 0x2000b9b4
      bl 0x00000000
      prev <invisible>
      fid 0x0000bdf7
    __fopen()
      fname 0x0800048a
      openmode <invisible>
      i <invisible>
      fid 0x2000b9b4
      handle 0x00000000
      fcb 0x20000090
      rval <invisible>
    _sys_open()
      name <invisible>
      openmode <invisible>
    <080010f2()>
    main()
    

    if i do not include any addresses above this, it behaves as such:

    ...
            fptr = fopen("F:\\test.txt", "w");
            if ( fptr != NULL )
            {
                    r= fwrite("this is a test", 1, 14, fptr);
                    r= fflush(fptr);
                    r= fclose(fptr); // the code will run to here
            }
    
            fptr = fopen("F:\\test.txt", "r" );
            if ( fptr != NULL )
            {
                    r= fread(sz, sizeof(char), 14, fptr);
                    r= fflush(fptr);
                    r= fclose(fptr); // the code will NOT run to here
            }
    

    It seems the file is not written properly in the fwrite call?