Back to Unleashed Firmware

Using FuriHalBus API {#furi_hal_bus}

documentation/FuriHalBus.md

latest5.7 KB
Original Source

Using FuriHalBus API {#furi_hal_bus}

Basic info

On system startup, most of the peripheral devices are under reset and not clocked by default. This is done to reduce power consumption and to guarantee that the device will always be in the same state before use.

Some crucial peripherals are enabled right away by the system, others must be explicitly enabled by the user code.

NOTE: Here and afterwards, the word "system" refers to any code belonging to the operating system, hardware drivers or built-in apps.

To ENABLE a peripheral, call furi_hal_bus_enable(). At the time of the call, the peripheral in question MUST be disabled; otherwise a crash will occur to indicate improper use. This means that any given peripheral cannot be enabled twice or more without disabling it first.

To DISABLE a peripheral, call furi_hal_bus_disable(). Likewise, the peripheral in question MUST be enabled, otherwise a crash will occur.

To RESET a peripheral, call furi_hal_bus_reset(). The peripheral in question MUST be enabled, otherwise a crash will occur. This method is used whenever it is necessary to reset all the peripheral's registers to their initial states without disabling it.

Peripherals

Built-in peripherals are divided into three categories:

  • Enabled by the system on startup, never disabled;
  • Enabled and disabled by the system on demand;
  • Enabled and disabled by the user code.

Always-on peripherals

Below is the list of peripherals that are enabled by the system. The user code must NEVER attempt to disable them.

Table 1 — Peripherals enabled by the system

PeripheralEnabled at
DMA1furi_hal_dma.c
DMA2--
DMAMUX--
GPIOAfuri_hal_resources.c
GPIOB--
GPIOC--
GPIOD--
GPIOE--
GPIOH--
PKAfuri_hal_bt.c
AES2--
HSEM--
IPCC--
FLASHenabled by hardware

On-demand system peripherals

Below is the list of peripherals that are enabled and disabled by the system. The user code must avoid using them directly, preferring the respective APIs instead.

When not using the API, these peripherals MUST be enabled by the user code and then disabled when not needed anymore.

Table 2 — Peripherals enabled and disabled by the system

PeripheralAPI header file
RNGfuri_hal_random.h
SPI1furi_hal_spi.h
SPI2--
I2C1furi_hal_i2c.h
I2C3--
USART1furi_hal_serial.h
LPUART1--
USBfuri_hal_usb.h

On-demand shared peripherals

Below is the list of peripherals that are not enabled by default and MUST be enabled by the user code each time it accesses them.

Note that some of these peripherals may also be used by the system to implement its certain features.

The system will take over any given peripheral only when the respective feature is in use.

Table 3 — Peripherals enabled and disabled by user

PeripheralSystemPurpose
CRC
TSC
ADC
QUADSPI
TIM1yessubghz, lfrfid, nfc, infrared, etc...
TIM2yessubghz, infrared, etc...
TIM16yesspeaker
TIM17yescc1101_ext
LPTIM1yestickless idle timer
LPTIM2yespwm
SAI1
LCD

DMA

The DMA1, DMA2 peripherals are a special case in that they have multiple independent channels. Some channels may be in use by the system.

Below is the list of DMA channels and their usage by the system.

Table 4 — DMA channels

DMAChannelSystemPurpose
DMA11yesdigital signal
--2yes--
--3
--4yespulse reader
--5
--6yesUSART_Rx
--7yesLPUART_Rx
DMA21yesinfrared, lfrfid, subghz,
--2yes--
--3yescc1101_ext
--4yescc1101_ext
--5yescc1101_ext
--6yesSPI
--7yesSPI