cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 memory out and how avoid that

SGian.1
Senior

Hi there,

here i'm for ask another help. I compile my program with keil and i read this data :

Program Size: Code=15988 RO-data=360 RW-data=24 ZI-data=2088  

How i can interpret ?

I use one STM32G031F4P6 wher i have 8K of RAM and 16K of program.

So i jus put one delay (just for test one thingh) and the compiler gave me that

Error: L6220E: Load region LR_IROM1 size (16424 bytes) exceeds limit (16384 bytes). Region contains 30 bytes of padding and 0 bytes of veneers (total 30 bytes of linker generated content)

Error: L6220E: Execution region ER_IROM1 size (16400 bytes) exceeds limit (16384 bytes). Region contains 24 bytes of padding and 0 bytes of veneers (total 24 bytes of linker generated content).

I'm sure i'm out of mememory i'm right ?

The question is i can do somethingh ? or i neeed the change the microontroller ?

Forgive me but when you start a project simpli of complicated what did you choise your microcontroller ? i don't talk about pin i talk about memory . Because my project is very easy i receive data from serial port (RS485) and afther i turn of or on led W2812B and i have I2C memory where i save a data

Thank a lot

Sergio

11 REPLIES 11
MM..1
Chief II

You are on normal fourth phase named Optimizing code. When this is end over memory you need new MCU.

From your explain your code isnt "optimal"

GLASS
Senior

You need to factorize code if you can, avoid any cut-paste...;>))

Be sure to use nano Lib and not standard lib.

Avoid float and math lib, especialy with cpu without FPU, otherwise IEEE float​ sw lib take huge space in flash.

If you compil code to debug, maybe be you can free a lot of space compiling HAL and other driver/middleware with specific compile option -o2.

If you need to debug our code, compile only our C modules with -og option​.

GLASS
Senior

Try mixing -og and ​-o2 at first.

It is easy to try and can give you a lot free flash (discarding not used functions), especially if actually you are using -o0 to debug...

SGian.1
Senior

First thanks for your help. Forgive me but i don't have any idea what wanna mean :

Try mixing -og and ​-o2 at first.

here i put my code right now

/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.c
  * @brief          : Main program body
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2022 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
 
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
//#include "ws2812b.h"
//#include "RS485.h"
/* USER CODE END Includes */
 
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
uint8_t tx[1]={0x00};
/* USER CODE END PTD */
 
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
	
 
/* USER CODE END PD */
 
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
 
/* USER CODE END PM */
 
/* Private variables ---------------------------------------------------------*/
CRC_HandleTypeDef hcrc;
 
I2C_HandleTypeDef hi2c1;
 
TIM_HandleTypeDef htim3;
DMA_HandleTypeDef hdma_tim3_ch3;
 
UART_HandleTypeDef huart2;
 
/* USER CODE BEGIN PV */
uint16_t address=0;
//rs485Data rs485;
extern uint8_t send;
/* USER CODE END PV */
 
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_DMA_Init(void);
static void MX_I2C1_Init(void);
static void MX_USART2_UART_Init(void);
static void MX_TIM3_Init(void);
static void MX_CRC_Init(void);
/* USER CODE BEGIN PFP */
 
/* USER CODE END PFP */
 
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
 
//void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
//{
//  /* Prevent unused argument(s) compilation warning */
//  HAL_UART_Transmit_DMA(&huart2, (uint8_t*)tx, 2);
//	sends=0;
//  /* NOTE : This function should not be modified, when the callback is needed,
//            the HAL_UART_TxCpltCallback can be implemented in the user file.
//   */
//}
//void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
//{
//	
//  HAL_UART_Receive_DMA(&huart2, (uint8_t*)rs485.pRxBuffer, 1);
//	HAL_Delay(2000);
//	if((uint8_t)rs485.pRxBuffer == 4){
//		HAL_UART_Transmit_DMA(&huart2, (uint8_t*)tx, 1);
//	}
 
//}
 
/* USER CODE END 0 */
 
/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{
  /* USER CODE BEGIN 1 */
 
  /* USER CODE END 1 */
 
  /* MCU Configuration--------------------------------------------------------*/
 
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
 
  /* USER CODE BEGIN Init */
 
 
  /* USER CODE END Init */
 
  /* Configure the system clock */
  SystemClock_Config();
 
  /* USER CODE BEGIN SysInit */
 
  /* USER CODE END SysInit */
 
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_I2C1_Init();
  MX_USART2_UART_Init();
  MX_TIM3_Init();
  MX_CRC_Init();
  /* USER CODE BEGIN 2 */
//	HAL_TIM_Base_Start(&htim3);
	address= (GPIOA->IDR & 0xF0)>>4;
	
 
	
	
	
	
	//ws2812b_init();
//	Set_LED(0,128, 255, 0);
//	Set_LED(1,255, 0, 255);
//	Set_LED(2,255, 255, 255);
//	WS2812_Send ();
	
//	HAL_UART_Receive_DMA(&huart2,(uint8_t*)rs485.pRxBuffer, 1);
	HAL_UART_Receive_IT(&huart2,(uint8_t*)tx, 1); //rs485.pRxBuffer
  /* USER CODE END 2 */
 
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
		if(send==1){
			HAL_Delay(3000);
			
			HAL_UART_Transmit_IT(&huart2,(uint8_t*)tx, 1);
			send=0;	
		}
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}
 

Ther is nothing of special send is set from the interrupt of UART when i recive data .

SGian.1
Senior

In the beginnig i use DMA but afther i prefer the interrupt for UAR and in CubeMx i set the flay of UART interrupt and i dismiss the DMA . Stupid question is possible Keil or CubeMx make some mistake because i change a couple of time the configuration ?

Thanks

I'm only another stm32 user, not a member of a support team...

You asked how you can do to reduce flash memory requirement because you exhaust this memory for a trivial SW managing one rs485, one i2c memory​ and one Led.

In my fisrt reply i explain differents ways to lower flash requirement.

In my 2nd reply i only say that the first thing to try is to configure optimisation at compiler level.

One rafinement is to apply different level of optimisation​ consideri.g that some part of Sw are already debugged.

For existing SW already qualified, you can use a high level of optimisation​, and stay without optimisation for our C code that you need to debug.

I told you about gcc optimisation level -o2 and for code needing to be debugged the -og optimisation level.

You have to transpose it to keil if you use it.

About using different level of optimisation with keil,​

Have a look here:

​https://developer.arm.com/documentation/ka003013/latest

Sorry i have not enough time to read code​...

You have to work on it.​

SGian.1
Senior

Thanks GLASS i did i use level og but still te same problem. I post the code just for show i did nothing except send one data on UART.

Thanks for you time

Nikita91
Lead II

If you want to use a so small memory MCU, you should consider producing optimized code yourself, and not using generic code such as HAL. It often happens to reduce the code by 2 by doing this for such a simple code.

Speaking of code optimization I think: only code the features that are useful to you with the LL.

The compilers will build exactly what you give them.

If you are using the IT versions of the functions, you're going to need to insure the IRQHandler is present, along with your related call-backs to service that interrupt properly.

The Cube directories should contain a lot of working examples, perhaps review those rather than randomly toggling switches/settings in CubeMX

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..