STM32g030k6p6 simple sketch overflows the flash memory?

And just to prove my point up there about floating point numbers:

There are two places where double is used, unneededly. The MPRLS library has in .pio\libdeps\genericSTM32G030K6\Adafruit MPRLS Library\Adafruit_MPRLS.cpp

  _OUTPUT_min = (uint32_t)((float)COUNTS_224 * (OUTPUT_min / 100.0) + 0.5);
  _OUTPUT_max = (uint32_t)((float)COUNTS_224 * (OUTPUT_max / 100.0) + 0.5);

so the 100.0 and 0.5 are double-type constants. 100.0f and 0.5f would be float-type constants.

  _OUTPUT_min = (uint32_t)((float)COUNTS_224 * (OUTPUT_min / 100.0f) + 0.5f);
  _OUTPUT_max = (uint32_t)((float)COUNTS_224 * (OUTPUT_max / 100.0f) + 0.5f);

Additionally, printing the results with pressure_hPa being a float

  Serial.print("Pressure (hPa): "); Serial.println(pressure_hPa);
  Serial.print("Pressure (PSI): "); Serial.println(pressure_hPa / 68.947572932);

has the problem that the .println() API only has a double as type, not a float.

size_t Print::println(double num, int digits)

So, as a test, forcing them to be int and again doing a float division

  Serial.print("Pressure (hPa): "); Serial.println((int)pressure_hPa);
  Serial.print("Pressure (PSI): "); Serial.println((int)(pressure_hPa / 68.947572932f));

Doing that brings the firmware down to a total of

RAM:   [==        ]  15.1% (used 1240 bytes from 8192 bytes)
Flash: [=====     ]  45.3% (used 28968 bytes from 64000 bytes)

with the .text section now only being 29608 bytes compared to the previous 34332 bytes. That’s saving approximately 5000 bytes by not including double.

1 Like