cancel
Showing results for 
Search instead for 
Did you mean: 

External SPI flash loader warning while generating code

Kraal
Senior III

Hi everyone,

I made a custom external flash loader following the examples provided with CubeProgrammer.

The generated elf is working perfectly as I want, I can read, write and erase the NOR chip.

But the device information structure below

struct StorageInfo const StorageInfo = {
    "W25Q16JV_MyBoard", // Device Name
    NOR_FLASH, // Device Type
    0x90000000, // Device Start Address
    0x200000, // Device Size in Bytes (2 MBytes)
    0x100, // Programming Page Size 256 Bytes
    0xFF, // Initial Content of Erased Memory
    // Specify Size and Address of Sectors (view example below)
    0x00000200, 0x00001000, // Sector Num: 512, Sector Size: 4 KBytes
    0x00000000, 0x00000000,
};

keeps generating the following warning (using GNU gcc with TrueStudio 9.3):

..\src\Dev_Inf.c:5:40: warning: missing braces around initializer [-Wmissing-braces]
 struct StorageInfo const StorageInfo = {
                                        ^
..\src\Dev_Inf.c:5:40: note: (near initialization for 'StorageInfo')

Does anyone understands why gcc is not happy here ?

Best regards,

Kraal

1 REPLY 1
Kraal
Senior III

OK I found the reason of the warning.

Let me add the struct definitions

#define SECTOR_NUM 10 // Max Number of Sector types
 
struct DeviceSectors {
  unsigned long SectorNum; // Number of Sectors
  unsigned long SectorSize; // Sector Size in Bytes
};
 
struct StorageInfo {
   char DeviceName[100]; // Device Name and Description
   unsigned short DeviceType; // Device Type: ONCHIP, EXT8BIT, EXT16BIT, ...
   unsigned long  DeviceStartAddress; // Default Device Start Address
   unsigned long  DeviceSize; // Total Size of Device
   unsigned long  PageSize; // Programming Page Size
   unsigned char  EraseValue; // Content of Erased Memory
   struct DeviceSectors	sectors[SECTOR_NUM];
};

The problem was with the nested struct DeviceSectors, declaring StorageInfo like the following

const struct StorageInfo StorageInfo = {
    "W25Q16JV_MyBoard", // Device Name
    NOR_FLASH, // Device Type
    0x90000000, // Device Start Address
    0x200000, // Device Size in Bytes (2 MBytes)
    0x100, // Programming Page Size 256 Bytes
    0xFF, // Initial Content of Erased Memory
    // Specify Size and Address of Sectors
    {
        {
            0x00000200, 0x00001000 // Sector Num: 512, Sector Size: 4 KBytes
        },
        {
            0x00000000, 0x00000000
        }
    }
};

And now the struct is correctly initialized.