cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G030F6P6TR Memory flash

MarioE
Associate

Hello to everyone,

I have an issue with the MCU in the title. I am about to show you my problem in some steps:

1- What is the flash memory size of my microcontroller? I consulted the datasheet of device and I read:

 

MarioE_0-1693403558894.png

So, for this series, I can have up to 64 Kbytes of memory flash. Specifically, for this package I should have a 32 Kbytes memory flash. Right?

MarioE_2-1693403888603.png

2- Where can I store my application data in the memory flash?

I taked a look to 'Build Analyzer' in STM32cubeIde and I saw the size of FLASH: 32 KB, and the used space 30.96 Kb, about 96.77 % of the space.
With 'Memory' tool I saw every sector of the flash and where the memory address is out of range, it shows me a series of '?' like follow: 

MarioE_3-1693404236780.png

but, where I thinked to be out of range I see that:

MarioE_4-1693404272120.png

Is that unsed flash memory space or what? 

From the datasheet I see the memory organization:  For the main memory there is 2k for each page, so in my case I should have only 16 available pages (?).

Ignoring that, I started to store my data at page 31 with address 0x0801 0000 and the program seems to work :dizzy_face:

MarioE_5-1693404360070.png

Here's my stored data:

MarioE_6-1693404531340.png

using the following function:

#define FLASH_PAGE_TO_ERASE 31
#define FLASH_DATA_ADDRESS (0x0800F800) //page 31 address

void writeDataToFlash()
{
   HAL_FLASH_Unlock();
 
    // Erasing page 31
    FLASH_EraseInitTypeDef eraseInit;
    eraseInit.TypeErase = FLASH_TYPEERASE_PAGES;
    eraseInit.Page = FLASH_PAGE_TO_ERASE;
    eraseInit.NbPages = 1;
    uint32_t pageError = 0;
    HAL_FLASHEx_Erase(&eraseInit, &pageError);
 
    // writing page 31
    uint64_t* data_ptr = (uint64_t*)&data;
    for(int i= 0;i<sizeof(datastruct)/8;i++)
    {
    HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, FLASH_DATA_ADDRESS + (i*8), data_ptr[i]);
    }
 
    HAL_FLASH_Lock();
}
 
What does it mean? I can't figure it out.
 
3- At first, my code size was largerthan 32Kb, so I tried to change the memory length in the linker configuration STM32G030F6PX_FLASH.ld : 

/* Memories definition */
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 8K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 48K
}
 
The compiler worked well, but during the earasing phase, there was an error, because the size of definited memory was bigger the the memory of MCU. 
So this confirms the memory size to be around 32 KB, but if I can memorize the data on page 31 that means the memory size is larger than 32KB. What is the truth and what am I doing wrong?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

ST uses the same die for multiple chips, but only tests the portion of FLASH guaranteed by the datasheet. In your case, that's 32kB starting at 0x08000000.

There may be FLASH beyond that, which probably works, but wasn't tested and isn't guaranteed to work. Up to you if you want to use it or not.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

4 REPLIES 4
TDK
Guru

ST uses the same die for multiple chips, but only tests the portion of FLASH guaranteed by the datasheet. In your case, that's 32kB starting at 0x08000000.

There may be FLASH beyond that, which probably works, but wasn't tested and isn't guaranteed to work. Up to you if you want to use it or not.

If you feel a post has answered your question, please click "Accept as Solution".

Hi TDK,

Thanks for the reply.

So, I'm using unprotected memory, thanks.
Supposing I want to extend the flash memory beyond 32Kb what should I do?

You mean apart from buying a new chip with more memory?

Create the project intended for a 64kB chip in the same form factor and see if that works. It's possible that ST's tools check the register that sets the flash size and will refuse to program past that.

If you feel a post has answered your question, please click "Accept as Solution".
Pavel A.
Evangelist III

>. It's possible that ST's tools check the register that sets the flash size and will refuse to program past that.

In this case, try to write the extra flash by program.

The "official" flash size in KB can be read from the Flash memory size data register at  0x1FFF 75E0

(RM0454, 30.1)