cancel
Showing results for 
Search instead for 
Did you mean: 

32kB flash overflowing using just USB CDC and SPI

LLope.31
Associate III

Hello everyone,

I am trying to use both USB CDC and SPI on a STM32F042F6P6 MCU. Unfortunately, without even writing almost any code (just an HAL_SPI_TransmitReceive() and a CDC_Transmit_FS()) it says the flash memory overflows by 1484 bytes.

Is this normal? If so, is there a way reduce the amount of flash consumed by these peripherals? For my application it does not need much code either, just needs to respond to basic commands over USB and write registers over SPI.

I will leave my entire main() too:

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_SPI1_Init();
MX_USB_DEVICE_Init();
/* USER CODE BEGIN 2 */
HAL_SPI_TransmitReceive(&hspi1, &addr, &zero, 1, HAL_MAX_DELAY);
HAL_SPI_TransmitReceive(&hspi1, &zero, &reading, 1, HAL_MAX_DELAY);
/* USER CODE END 2 */

/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
uint8_t data[] = "\nHello\n";
CDC_Transmit_FS(data, sizeof(data));
CDC_Transmit_FS(&reading, 1);
HAL_Delay (1000);
/* USER CODE END WHILE */

/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}

 

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

Compile with higher optimization settings. Particularly, changing the configuration from Debug to Release will see a drastic reduction in the amount of space needed.

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

View solution in original post

2 REPLIES 2
TDK
Guru

Compile with higher optimization settings. Particularly, changing the configuration from Debug to Release will see a drastic reduction in the amount of space needed.

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

Thank you, now I am able to build and the build analyzer shows 46.88% capacity of the flash.