Arduino_core_stm32: Disable HAL feature when not used in the sketch

Created on 16 Mar 2018  路  7Comments  路  Source: stm32duino/Arduino_Core_STM32

Goal of this issue is to be able to disable HAL module if not used in the sketch in order to reduce binary size.

Mainly useful for MCU with smallflash size (See #165)

Proposition:

handle a default HAL conf file which could be override by end user at sketch level or variant.
~PeripheralPins arrays could also use new switch to force an array to be disable even if the HAL module is enabled.~

Implementation done thanks #518

  • Extra HAL module can be enabled/disabled in variant.h if required or in a file named (at sketch level): hal_conf_extra.h

    • To enable a HAL modules use the standard HAL definition: HAL_PPP_MODULE_ENABLED with PPP the peripheral to enable.
    • To disable a HAL modules use one or more following values:

      • HAL_ADC_MODULE_DISABLED

      • HAL_I2C_MODULE_DISABLED

      • HAL_RTC_MODULE_DISABLED

      • HAL_SPI_MODULE_DISABLED

      • HAL_DAC_MODULE_DISABLED

      • HAL_ETH_MODULE_DISABLED

      • HAL_SD_MODULE_DISABLED

      • HAL_QSPI_MODULE_DISABLED

      • HAL_EXTI_MODULE_DISABLED

      • HAL_TIM_MODULE_DISABLED

        Note: HAL_UART_MODULE_ENABLED and HAL_PCD_MODULE_ENABLED are handled thanks Arduino menu.

  • Custom HAL configuration file can replace the default one by adding a file named (at sketch level):
    hal_conf_custom.h .

Enhancement

Most helpful comment

This will be available for all variants. It's a core feature not specific to a variant.
Anyway, depending of the feature used, the HAL part is not embed if not used.
Example for SPI or I2C if SPI.h or Wire.h is not include, the HAL part is removed by the compiler as it is not used. Only the pinmap array is kept but it should be removed if not used to save some space.

All 7 comments

With "small flash size" do you consider also the blue pill and similar 48pins f1 boards?
As you know it should be 64kb, even if we use it as a 128kb i think that a smaller bin would be safer

This will be available for all variants. It's a core feature not specific to a variant.
Anyway, depending of the feature used, the HAL part is not embed if not used.
Example for SPI or I2C if SPI.h or Wire.h is not include, the HAL part is removed by the compiler as it is not used. Only the pinmap array is kept but it should be removed if not used to save some space.

Serial can now be enabled or not:
https://github.com/stm32duino/Arduino_Core_STM32/commit/83d872ff42c3d4988ffed7295199b22a453c9362

This allow to build without HAL_UART_MODULE_ENABLED (save memory)
HAL_UART_MODULE_ENABLED should not be defined in stm32yyxx_hal_conf.h

Shouldn't RCC also be on the list here, e.g., following the comment https://github.com/stm32duino/Arduino_Core_STM32/issues/165#issuecomment-373646769 ("I've generate the code with CubeMx to use LL instead of HAL for RCC") ?

This could.

hi @fpistm ,
for this points:

ADC: be able to build without HAL_ADC_MODULE_ENABLED
DAC: it's already possible to build without HAL_DAC_MODULE_ENABLED, maybe a menu could be proposed to enable or not the feature...
PWM: be able to build without HAL_PWM_MODULE_ENABLED

we need menu and some ifdef "only", right?

Hi @Adminius,
probably yes, I have to find a nice and easiest way to do this.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

davidanger picture davidanger  路  6Comments

mayurharge picture mayurharge  路  6Comments

Adminius picture Adminius  路  6Comments

zhaorui4142 picture zhaorui4142  路  4Comments

Jorgen-VikingGod picture Jorgen-VikingGod  路  8Comments