STM32 region `FLASH' overflowed by xxx bytes problem solved

STM32 Region `FLASH' overflowed by xxx bytes problem solved

1. Problem phenomenon

For the STM32L031 project created with STM32CUBEIDE, when HAL_UART_Receive_IT(&huart2, (uint8_t *)&aRxBuffer, 1); is enabled, even if the reception of serial port 2 is interrupted, an error Region FLASH overflowed by xxx bytes is reported when building the project.
Insert picture description hereInsert picture description here

2. Incorrect solution

There is a way to introduce on the Internet, modify the compiled script file in the project directory, open the ld file and
Insert picture description here
modify the FLASH (rx) value to a larger value, such as 36K
Insert picture description here
after the modification, the build can be downloaded into the chip successfully, but the program cannot run . STM32L031 has only 32K Flash space, and artificially increasing the size of the space recognized by the software does not solve the problem.

3. The correct solution

Because the non-interrupted polling (polling) method is used to receive serial port data successfully, the basic judgment is that the code generated by the optimization of the uart interrupt method is too large. So it can be adjusted for compilation optimization.

In the Project-Properties of STM32CUBEIDE, find the Optimization option
Insert picture description here
to optimize debug and release compilation, select Optimize for size
Insert picture description here
Insert picture description here
or all types use Optimize for size
Insert picture description here
Apply and exit. Type a space in the code, save and rebuild the project, and the compilation and linking are successful. After downloading to the chip, the serial port interrupt receiving operation is normal.

After ST upgraded the STM32CUBEIDE version, the control menu became as follows, just use it inference:
Insert picture description here
-End-

Guess you like

Origin blog.csdn.net/hwytree/article/details/103125176