HAL LPTIM Use Cases

Low Power Timer Encoder

@startuml
' To add a number by line
'autonumber

title "Low Power Timer Encoder"

' Fix order of each column
participant "User Application" as App
participant "HAL LPTIM" as Driver


group Initialization
App -[hidden]>Driver
end

group Configuration
App->Driver : <b>HAL_LPTIM_SetConfig</b>((hal_lptim_config_t) {\n.source = <font color=green>HAL_LPTIM_CLK_ENCODER_SUBMODE_1</font>,\n<font color=blue>.mode = <b>HAL_LPTIM_CONTINUOUS</b></font>,\n.prescaler = <font color=red>HAL_LPTIM_CLK_SRC_DIV1</font>,\n.period = autoreload_value,\n.repetition_counter = 0x00})
Driver --> App : HAL_OK

App->Driver : <b>HAL_LPTIM_SetConfigEncoder</b>((hal_lptim_encoder_t) {\n.input1 = HAL_LPTIM_INPUT1_GPIO,\n.input2 = HAL_LPTIM_INPUT2_GPIO,\n.filter = HAL_LPTIM_FDIV1})
Driver --> App : HAL_OK

end

group Start LPTIMx

App->Driver : <b>HAL_LPTIM_Start</b>()
Driver --> App : HAL_OK

end
@enduml

Called functions:

Low Power Timer Pulse Counter


@startuml
' To add a number by line
'autonumber

title "Low Power Timer Pulse Counter"

' Fix order of each column
participant "User Application" as App
participant "HAL LPTIM" as Driver


group Initialization
App -[hidden]>Driver
end

group Configuration
App->Driver : <b>HAL_LPTIM_SetConfig</b>((hal_lptim_config_t) {\n.source = <font color=green>HAL_LPTIM_CLK_EXTERNAL_ASYNCHRONOUS</font>,\n<font color=blue>.mode = <b>HAL_LPTIM_CONTINUOUS</b></font>,\n.prescaler = <font color=red>HAL_LPTIM_CLK_SRC_DIV1</font>,\n.period = PeriodValue,\n.repetition_counter = 0x00})
Driver --> App : HAL_OK

App -[#grey]>Driver : <font color=grey><b>HAL_LPTIM_DisablePreload</b>()</font>
Driver --[#grey]> App : <font color=grey>HAL_OK</font>

App->Driver : <b>HAL_LPTIM_SetConfigInput1</b>((hal_lptim_input1_config_t) {\n.src = HAL_LPTIM_INPUT1_GPIO,\n.polarity = HAL_LPTIM_INPUT_RISING,\n.filter = HAL_LPTIM_FDIV1})
rnote over Driver: filter is always set to\n HAL_LPTIM_FDIV1 (i.e. no filter)\nin Asynchronous mode)
Driver --> App : HAL_OK


App->Driver : <b>HAL_LPTIM_RegisterAutoReloadMatchCallback</b>(callback)
Driver --> App : HAL_OK
end

group Start LPTIMx

App->Driver : <b>HAL_LPTIM_Start_IT</b>()
Driver --> App : HAL_OK

hnote across: Enter Low Power Mode

@enduml

Called functions:

Low Power Timer PWM generator with external clock


@startuml
' To add a number by line
'autonumber

title "Low Power Timer PWM generator with external clock"

' Fix order of each column
participant "User Application" as App
participant "HAL LPTIM" as Driver


group Initialization
App -[hidden]>Driver
end

group Configuration
App->Driver : <b>HAL_LPTIM_SetConfig</b>((hal_lptim_config_t) {\n.source = <font color=green>HAL_LPTIM_CLK_EXTERNAL_ASYNCHRONOUS</font>,\n<font color=blue>.mode = <b>HAL_LPTIM_CONTINUOUS</b></font>, \n.prescaler = HAL_LPTIM_CLK_SRC_DIV1,\n.period = PeriodValue,\n.repetition_counter = 0x00})
Driver --> App : HAL_OK

App->Driver : <b>HAL_LPTIM_SetConfigInput1</b>((hal_lptim_input1_config_t) {\n.src = HAL_LPTIM_INPUT1_GPIO,\n.polarity = HAL_LPTIM_INPUT_RISING,\n.filter = HAL_LPTIM_FDIV1})
rnote over Driver: filter is always set to\n HAL_LPTIM_FDIV1 (i.e. no filter)\nin Asynchronous mode)
Driver --> App : HAL_OK

App->Driver : <b><back:lime>HAL_LPTIM_OC_SetConfigChannel</back></b>(<font color=blue>HAL_LPTIM_CHANNEL_1</font>,\n(hal_lptim_oc_config_t){\n.polarity = HAL_LPTIM_OC_HIGH,\n.pulse = PulseValue})
Driver --> App : HAL_OK

end

group Start LPTIMx

App->Driver : <b>HAL_LPTIM_StartChannel</b>(<font color=blue>HAL_LPTIM_CHANNEL_1</font>)
Driver --> App : HAL_OK

App->Driver : <b>HAL_LPTIM_Start</b>()
Driver --> App : HAL_OK

hnote across: Enter Low Power Mode

App->Driver : <b>HAL_LPTIM_StopChannel</b>(<font color=blue>HAL_LPTIM_CHANNEL_1</font>)
Driver --> App : HAL_OK

App->Driver : <b>HAL_LPTIM_Stop</b>()
Driver --> App : HAL_OK
end
@enduml

Called functions:

Low Power Timer Timeout


@startuml
' To add a number by line
'autonumber

title "Low Power Timer Timeout"

' Fix order of each column
participant "User Application" as App
participant "HAL LPTIM" as Driver
participant "IT" as IT


group Initialization
App -[hidden]>Driver
end

' OutputPolarity = LPTIM_OUTPUTPOLARITY_HIGH,\n.Init.UpdateMode = LPTIM_UPDATE_IMMEDIATE,\n.' Init.Input1Source = LPTIM_INPUT1SOURCE_GPIO,\n.Init.Input2Source = LPTIM_INPUT2SOURCE_GPIO

group Configuration
App->Driver : <b>HAL_LPTIM_SetConfig</b>((hal_lptim_config_t) {\n.source = <font color=green>HAL_LPTIM_CLK_INTERNAL</font>,\n<font color=blue>.mode = <b>HAL_LPTIM_TIMEOUT</b></font>,\n.prescaler = <font color=red>HAL_LPTIM_CLK_SRC_DIV1</font>,\n.period = <font color=lime>0xFFFF</font>,\n.repetition_counter = 0x00})
Driver --> App : HAL_OK


App->Driver : <b>HAL_LPTIM_SetConfigExtTrigInput(</b>((hal_lptim_ext_trig_config_t) {\n.source = HAL_LPTIM_TRIG_GPIO,\n.polarity = HAL_LPTIM_TRIG_POLARITY_RISING_FALLING,\n.filter = HAL_LPTIM_FDIV1})
Driver --> App : HAL_OK

App->Driver : <b><back:lime>HAL_LPTIM_OC_SetChannelPulse</back></b>(<font color=blue>HAL_LPTIM_CHANNEL_1</font>,\npulse = <back:pink><b>timeout</b></back>})
Driver --> App : HAL_OK

App->Driver : <b>HAL_LPTIM_RegisterCompareMatchCallback</b>(timeout_callback)
Driver --> App : HAL_OK
end

group Start LPTIMx

App->Driver : <b>HAL_LPTIM_StartChannel_IT</b>(<font color=blue>HAL_LPTIM_CHANNEL_1</font>)
Driver --> App : HAL_OK

App->Driver : <b>HAL_LPTIM_Start</b>()
Driver --> App : HAL_OK

hnote across: Enter Low Power Mode

end
@enduml

Called functions: