title: STM32F042K6: region `FLASH' overflowed by 1212 bytes
body: <p>I am trying to program STM32F042K6 nucleo using CubeIDE and STM32 HAL but the compiler throws an error:</p>
  <p>region `FLASH' overflowed by 1212 bytes.</p>
  <p>Here is the exact console output:</p>
  <pre><code>09:55:03 **** Incremental Build of configuration Debug for project Virtual Com Port ****
  make -j16 all 
  arm-none-eabi-gcc -o &quot;Virtual Com Port.elf&quot; @&quot;objects.list&quot;   -mcpu=cortex-m0 -T&quot;C:\Users\EE Engineering\Documents\Projects\Firmware\Virtual Comm Port\STM32F042K6TX_FLASH.ld&quot; --specs=nosys.specs -Wl,-Map=&quot;Virtual Com Port.map&quot; -Wl,--gc-sections -static --specs=nano.specs -mfloat-abi=soft -mthumb -Wl,--start-group -lc -lm -Wl,--end-group
  c:\st\stm32cubeide_1.7.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_2.0.0.202105311346\tools\arm-none-eabi\bin\ld.exe: Virtual Com Port.elf section `.text' will not fit in region `FLASH'
  c:\st\stm32cubeide_1.7.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_2.0.0.202105311346\tools\arm-none-eabi\bin\ld.exe: region `FLASH' overflowed by 1212 bytes
  collect2.exe: error: ld returned 1 exit status
  make: *** [makefile:69: Virtual Com Port.elf] Error 1
  &quot;make -j16 all&quot; terminated with exit code 2. Build might be incomplete.
  
  09:55:04 Build Failed. 3 errors, 0 warnings. (took 340ms).
  </code></pre>
  <p>However, when I look at the memory regions in the build analyzer, it shows 16.58 KB free out of 32KB size for a usage of 48.19%. If only 48% of the flash storage is used, then how is the flash overflowing by 1212 bytes and what can I do to fix this?</p>
  <p><a href="https://i.stack.imgur.com/kwtgF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kwtgF.png" alt="Build Analyzer" /></a></p>