2023-10-04 11:41 AM
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 */
}
Solved! Go to Solution.
2023-10-04 11:50 AM
Compile with higher optimization settings. Particularly, changing the configuration from Debug to Release will see a drastic reduction in the amount of space needed.
2023-10-04 11:50 AM
Compile with higher optimization settings. Particularly, changing the configuration from Debug to Release will see a drastic reduction in the amount of space needed.
2023-10-04 12:27 PM
Thank you, now I am able to build and the build analyzer shows 46.88% capacity of the flash.