Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor STM32 classes to be more like Samd21 #103

Closed
terrillmoore opened this issue Nov 24, 2018 · 4 comments
Closed

Refactor STM32 classes to be more like Samd21 #103

terrillmoore opened this issue Nov 24, 2018 · 4 comments
Assignees
Labels

Comments

@terrillmoore
Copy link
Member

Samd21 classes use an elaborate technique to avoid conditional compiles, based on the C compiler's ability to optimize out globals that aren't used.

  1. The table of platforms contains all the known platforms.
  2. The actual class Catena4450, etc., has a getPlatformTable() method that returns the platforms supported by the device.
  3. Startup code calls that as needed.
  4. Other platforms in the vector aren't referenced, so they're discarded.

STM32 classes instead have a table that's constructed with #if. This is much more fragile.

Please refactor the Stm32 classes to use the Samd21 technique.

@chwon64
Copy link
Collaborator

chwon64 commented Nov 27, 2018

Do you also want to remove #if when declare table instances as below?

#if defined(ARDUINO_MCCI_CATENA_4550) || defined(ARDUINO_CATENA_4550)
const CATENA_PLATFORM gkPlatformCatena4550 =
{
Guid: GUID_HW_CATENA_4550_BASE(WIRE),
pParent: &gkPlatformCatena4550,
PlatformFlags:
CatenaBase::fHasLoRa |
CatenaBase::fHasTtnNycLoRa |
CatenaBase::fHasBme280 |
CatenaBase::fHasLuxSi1133 |
CatenaBase::fHasFRAM |
CatenaBase::fHasFlash,
};
#endif /* CATENA_4550 */
#if defined(ARDUINO_MCCI_CATENA_4551) || defined(ARDUINO_CATENA_4551)
const CATENA_PLATFORM gkPlatformCatena4551 =

If we remove this #if, these table instances are constructed and actual code size will be increased.

@terrillmoore
Copy link
Member Author

The linker is supposed to remove the unused CATENA_PLATFORM instances, because there will be no reference to them (this is the --gc-sections option). You can compare size after you take out the #ifs; size shouldn't change. That's why I used this sort of strange format rather than a vector.

@chwon64
Copy link
Collaborator

chwon64 commented Nov 27, 2018

I checked the linker doesn't remove the unused CATENA_PLATORM instances. I also checked --gc-sections option applied when build STM32.

@chwon64
Copy link
Collaborator

chwon64 commented Nov 28, 2018

All changes are merged.

@chwon64 chwon64 closed this as completed Nov 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants