Name

Peripheral clock control — Details

Synopsis

#include <cyg/hal/hal_io.h>
    

cyg_uint32 clkdesc = CYGHWR_HAL_STM32_CLOCK( clk );

CYGHWR_HAL_STM32_CLOCK_ENABLE ( clkdesc );

CYGHWR_HAL_STM32_CLOCK_DISABLE ( clkdesc );

Description

The HAL provides macros which may be used to enable or disable peripheral clocks. Effectively this indicates whether the peripheral is powered on (enabled) or powered down (disabled) and so may be used to ensure unused peripherals are turned off, to save power.

It is important to remember that before a peripheral can be used, it must be enabled. It is safe to re-enable a peripheral that is already enabled, although usually a device driver will only do so once in its initialisation. eCos will automatically initialise some peripheral blocks where it needs to use the associated peripherals (such as memory controllers and some (but usually not all) GPIO banks), and in eCos-supplied device drivers which are included in the eCos configuration. However this should not be relied on - it is always safest to enable the peripheral clocks anyway just in case. Finally, remember that each GPIO bank must be enabled separately.

The CYGHWR_HAL_STM32_CLOCK macro can be used to create a descriptor used to specify the clock. This takes the following parameter:

clk
This parameter selects the specific clock. Definitions for each clock can be found in the file <cyg/hal/var_io.h> which can also be found as the file include/var_io.h within the STM32 processor variant HAL package in the eCos source repository, ensuring you are looking at the correct section for the relevant processor family.

Once a descriptor has been created, it may be used as the parameter to the CYGHWR_HAL_STM32_CLOCK_ENABLE or CYGHWR_HAL_STM32_CLOCK_DISABLE macros in order to enable or disable the peripheral clock.

The following example shows how these macros may be used:

#define CYGHWR_HAL_STM32_ETH_MAC_CLOCK          CYGHWR_HAL_STM32_CLOCK( ETHMAC )

int init_eth(...)
{
      CYGHWR_HAL_STM32_CLOCK_ENABLE(CYGHWR_HAL_STM32_ETH_MAC_CLOCK);
      ... /* Rest of initialisation */
}

void stop_eth(...)
{
     ... /* Free up resources */
     CYGHWR_HAL_STM32_CLOCK_DISABLE(CYGHWR_HAL_STM32_ETH_MAC_CLOCK);
}