Skip to main content
LLope.31
Associate III
October 4, 2023
Solved

32kB flash overflowing using just USB CDC and SPI

  • October 4, 2023
  • 2 replies
  • 1985 views

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 */
}

 

This topic has been closed for replies.
Best answer by TDK

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

2 replies

TDK
TDKBest answer
October 4, 2023

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""."
LLope.31
LLope.31Author
Associate III
October 4, 2023

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