HAL HRTIM Use Cases

Arbitrary waveform generation

@startuml
' To add a number by line
'autonumber
' Fix order of each column

participant "User Application" as App
participant "HAL HRTIM" as Driver

group HRTIM Initialization
App -[hidden]>Driver
end

group Timer D configuration

App -> App : \ntimer_d_config.period = 0x2000;
App->Driver : HAL_HRTIM_TIM_SetConfig(&hhrtim, HAL_HRTIM_TIMD, &timer_d_config)
Driver --> App : HAL_OK

App->Driver : \nHAL_HRTIM_TIM_SetUpdateSource(&hhrtim, HAL_HRTIM_TIMD, HAL_HRTIM_UPDATE_EVENT_REPETITION)
Driver --> App : HAL_OK

App -> Driver : HAL_HRTIM_TIM_EnablePreload(&hhrtim, HAL_HRTIM_TIMD)
Driver --> App : HAL_OK

App->Driver : \nHAL_HRTIM_TIM_SetCompareValue(&hhrtim, HAL_HRTIM_TIMD, HAL_HRTIM_COMPARE_UNIT_1, 0x10)
Driver --> App : HAL_OK

App->Driver : \nHAL_HRTIM_TIM_SetCompareValue(&hhrtim, HAL_HRTIM_TIMD, HAL_HRTIM_COMPARE_UNIT_2, 0x20)
Driver --> App : HAL_OK

App->Driver : \nHAL_HRTIM_TIM_SetCompareValue(&hhrtim, HAL_HRTIM_TIMD, HAL_HRTIM_COMPARE_UNIT_3, 0x30)
Driver --> App : HAL_OK

App -> App : \nchd1_config.set =\nHAL_HRTIM_OUT_SET_TIM_PERIOD |\nHAL_HRTIM_OUT_SET_TIM_CMP1 |\nHAL_HRTIM_OUT_SET_TIM_CMP2\nchd1_config.reset =\nHAL_HRTIM_OUT_RESET_TIM_PERIOD |\nHAL_HRTIM_OUT_RESET_TIM_CMP1 |\nHAL_HRTIM_OUT_RESET_TIM_CMP2

App->Driver : HAL_HRTIM_OUT_SetConfig(&hhrtim, HAL_HRTIM_CHD1, chd1_config)
Driver --> App : HAL_OK

App -> App : \nchd2_config.set =\nHAL_HRTIM_OUT_SET_TIM_PERIOD |\nHAL_HRTIM_OUT_SET_TIM_CMP2\nchd2_config.reset =\nHAL_HRTIM_OUT_RESET_TIM_CMP1 |\nHAL_HRTIM_OUT_RESET_TIM_CMP3

App->Driver : HAL_HRTIM_OUT_SetConfig(&hhrtim, HAL_HRTIM_CHD2, chd2_config)
Driver --> App : HAL_OK
note right of App: From this point onward, HRTIM outputs are ready to be connected to the MCU I/Os.\nIn the GPIO controller, the selected HRTIM I/Os must be configured as per the alternate function mapping.

end

group Start Signal generation

App -> Driver : HAL_HRTIM_OUT_Enable(&hhrtim, (HAL_HRTIM_CHD1 | HAL_HRTIM_CHD2))
Driver --> App : HAL_OK

App -> Driver : HAL_HRTIM_TIM_Start(&hhrtim, HAL_HRTIM_TIMD)
Driver --> App : HAL_OK

end

@enduml

Called functions:

Generating PWM with the master timer

@startuml
' To add a number by line
'autonumber
' Fix order of each column

participant "User Application" as App
participant "HAL HRTIM" as Driver

group HRTIM Initialization
App -[hidden]>Driver
end

group Master timer configuration

App -> App : \nmaster_timer_config.period = 0x1000;
App->Driver : HAL_HRTIM_TIM_SetConfig(&hhrtim, HAL_HRTIM_MASTER, &master_timer_config)
Driver --> App : HAL_OK

App->Driver : \nHAL_HRTIM_TIM_SetUpdateSource(&hhrtim, HAL_HRTIM_MASTER, HAL_HRTIM_UPDATE_EVENT_REPETITION)
Driver --> App : HAL_OK

App -> Driver : HAL_HRTIM_TIM_EnablePreload(&hhrtim, HAL_HRTIM_MASTER)
Driver --> App : HAL_OK

App->Driver : \nHAL_HRTIM_TIM_SetCompareValue(&hhrtim, HAL_HRTIM_MASTER, HAL_HRTIM_COMPARE_UNIT_1, 0x10)
Driver --> App : HAL_OK

end

group Timer D configuration

App -> App : \ntimer_d_config.period = 0x2000;
App->Driver : HAL_HRTIM_TIM_SetConfig(&hhrtim, HAL_HRTIM_TIMD, &timer_d_config)
Driver --> App : HAL_OK

App->Driver : \nHAL_HRTIM_TIM_SetUpdateSource(&hhrtim, HAL_HRTIM_TIMD, HAL_HRTIM_UPDATE_EVENT_REPETITION)
Driver --> App : HAL_OK

App -> Driver : HAL_HRTIM_TIM_EnablePreload(&hhrtim, HAL_HRTIM_TIMD)
Driver --> App : HAL_OK

App->Driver : \nHAL_HRTIM_TIM_SetCompareValue(&hhrtim, HAL_HRTIM_TIMD, HAL_HRTIM_COMPARE_UNIT_1, 0x20)
Driver --> App : HAL_OK

App -> App : \nchd1_config.set = HAL_HRTIM_OUT_SET_TIM_CMP1\nchd1_config.reset = HAL_HRTIM_OUT_RESET_TIM_PERIOD

App->Driver : HAL_HRTIM_OUT_SetConfig(&hhrtim, HAL_HRTIM_CHD1, chd1_config)
Driver --> App : HAL_OK

App -> App : \nchd1_config.set = HAL_HRTIM_OUT_SET_MASTER_CMP1\nchd1_config.reset = HAL_HRTIM_OUT_RESET_MASTER_PERIOD

App->Driver : HAL_HRTIM_OUT_SetConfig(&hhrtim, HAL_HRTIM_CHD2, chd2_config)
Driver --> App : HAL_OK
note right of App: From this point onward, HRTIM outputs are ready to be connected to the MCU I/Os.\nIn the GPIO controller, the selected HRTIM I/Os must be configured as per the alternate function mapping.

end

group Start Signal generation

App -> Driver : HAL_HRTIM_OUT_Enable(&hhrtim, (HAL_HRTIM_CHD1 | HAL_HRTIM_CHD2))
Driver --> App : HAL_OK

App -> Driver : HAL_TIM_Start(&hhrtim, (HAL_HRTIM_MASTER | HAL_HRTIM_TIMD))
Driver --> App : HAL_OK

end

@enduml

Called functions:

Complementary PWM Signals generation

@startuml
' To add a number by line
'autonumber
' Fix order of each column

participant "User Application" as App
participant "HAL HRTIM" as Driver
participant "Interrupt service routine" as ISR

group HRTIM Initialization
App -[hidden]>Driver
end

group Timer A configuration

App -> Driver: HAL_HRTIM_SetConfigInterrupts(&hhrtim, HAL_HRTIM_IT_TIMA, HAL_HRTIM_OPT_IT_CMP1)
Driver -> Driver: Timer A interrupt mask is stored\ninto the HRTIM handle
Driver --> App : HAL_OK

App -> App : \ntimer_a_config.period = 0x2000
App->Driver : HAL_HRTIM_TIM_SetConfig(&hhrtim, HAL_HRTIM_TIMA, &timer_a_config)
Driver --> App : HAL_OK

App->Driver : \nHAL_HRTIM_TIM_SetUpdateSource(&hhrtim, HAL_HRTIM_TIMA, HAL_HRTIM_UPDATE_EVENT_REPETITION)
Driver --> App : HAL_OK

App -> Driver : HAL_HRTIM_TIM_EnablePreload(&hhrtim, HAL_HRTIM_TIMA)
Driver --> App : HAL_OK

App->Driver : \nHAL_HRTIM_TIM_SetCompareValue(&hhrtim, HAL_HRTIM_TIMA, HAL_HRTIM_COMPARE_UNIT_1, 0x20)
Driver --> App : HAL_OK

App -> App : \nrising_dt.value = 0x5\nrising_dt.sign = HAL_HRTIM_DEADTIME_POSITIVE
App -> Driver :  HAL_HRTIM_TIM_SetConfigDeadtime(&hhrtim, HAL_HRTIM_TIMA, HAL_HRTIM_DEADTIME_RISING, &rising_dt)
Driver --> App : HAL_OK

App -> App : \nfalling_dt.value = 0x3\nfalling_dt.sign = HAL_HRTIM_DEADTIME_POSITIVE
App -> Driver :  HAL_HRTIM_TIM_SetConfigDeadtime(&hhrtim, HAL_HRTIM_TIMA, HAL_HRTIM_DEADTIME_FALLING, &falling_dt)
Driver --> App : HAL_OK

App -> Driver :  HAL_HRTIM_TIM_EnableDeadtime(&hhrtim, HAL_HRTIM_TIMA)
Driver --> App : HAL_OK

App -> App : \nCHA1_config.set = HAL_HRTIM_OUT_SET_TIM_CMP1\nCHA1_config.set = HAL_HRTIM_OUT_RESET_TIM_PERIOD

App->Driver : HAL_HRTIM_OUT_SetConfig(&hhrtim, HAL_HRTIM_CHA1, &CHA1_config)
Driver --> App : HAL_OK
note right of App: From this point onward, HRTIM outputs are ready to be connected to the MCU I/Os.\nIn the GPIO controller, the selected HRTIM I/Os must be configured as per the alternate function mapping.

end

group Start Signal generation (interrupt mode)

App -> Driver : HAL_HRTIM_OUT_Enable(&hhrtim, (HAL_HRTIM_CHA1 | HAL_HRTIM_CHA2))
Driver --> App : HAL_OK

App -> Driver : HAL_TIM_Start_IT(&hhrtim, HAL_HRTIM_TIMA)
Driver -> Driver: Timer A compare 1 interrupt\n is enabled
Driver --> App : HAL_OK

end

group Compare 1 match interrupt processing

ISR -> Driver: HAL_HRTIM_TIMA_IRQHandler(&hhrtim, HAL_HRTIM_TIMA, HAL_HRTIM_COMPARE_UNIT_1)
Driver -> Driver: Clear interrupt flag
Driver -> App: HAL_HRTIM_CompareMatchCallback(&hhrtim, HAL_HRTIM_TIMA, HAL_HRTIM_COMPARE_UNIT_1)
App -> App: Compare 1 match interrupt processing
App -> Driver
Driver -> ISR

end

@enduml

Called functions:

External event capture with DMA

@startuml
' To add a number by line
'autonumber
' Fix order of each column

participant "User Application" as App
participant "HAL HRTIM" as Driver
participant "HAL DMA" as DMA
participant "Interrupt service routine" as ISR

group HRTIM Initialization
App -[hidden]>Driver
end

group DMA channel Initialization (Peripheral to Memory)

App->DMA : DMA channel initialization

App->Driver :  HAL_HRTIM_SetDMA(&hhrtim, HAL_HRTIM_DMA_TIMA, &hdma)

Driver -> Driver: DMA channel handle associated to Timer A\nis stored into the HRTIM handle

Driver --> App : HAL_OK

end

group Timer A configuration

note right of App:dma_config must be persistent (accessed through the HRTIM handle by the HAL_HRTIM_TIM_Start_DMA function).
App -> App : dma_config.requests = HAL_HRTIM_OPT_DMA_CPT1\ndma_config.src_addr = HRTIM_CPT1AR\ndma_config.dest_addr = &captured_values\ndma_config.size_byte = 12


App->Driver : HAL_HRTIM_SetConfigDMA(&hhrtim, HAL_HRTIM_DMA_TIMA, &dma_config)
Driver -> Driver: Pointer to the Timer A DMA configuration\nis stored into the HRTIM handle
Driver --> App : HAL_OK


App -> App : \nevt3_config.source = HAL_HRTIM_EEV3_GPIO\nevt3_config.sensitivity = HAL_HRTIM_EEV_EDGE_RISING

App-->Driver: HAL_HRTIM_EEV_SetConfig(&hhrtim, HAL_HRTIM_EEV3, &evt3_config)
Driver --> App : HAL_OK

App -> App : \ntimer_a_config.period = 0x2000

App->Driver : HAL_HRTIM_TIM_SetConfig(&hhrtim, HAL_HRTIM_TIMA, &timer_a_config)
Driver --> App : HAL_OK

App -> App : \nevt3_filter.filter = HAL_HRTIM_BLANKING_TIMB_CMP1\nevt3_filter.notification_mode = HAL_HRTIM_EEV_IMMEDIATE

App->Driver : HAL_HRTIM_TIM_SetEventFilter(&hhrtim, HAL_HRTIM_TIMA, HAL_HRTIM_EEV3, &evt3_filter)
Driver --> App : HAL_OK

App->Driver : HAL_HRTIM_TIM_SetCaptureTrigger(&hhrtim, HAL_HRTIM_TIMA, HAL_HRTIM_CAPTURE_UNIT_1, HAL_HRTIM_CAPTURE_EVT3)
Driver --> App : HAL_OK

end

group Timer B configuration

App -> App : \ntimer_b_config.period = 0x2000

App->Driver : HAL_HRTIM_TIM_SetConfig(&hhrtim, HAL_HRTIM_TIMB, &timer_b_config)
Driver --> App : HAL_OK

App->Driver : \nHAL_HRTIM_TIM_SetCompareValue(&hhrtim, HAL_HRTIM_TIMB, HAL_HRTIM_COMPARE_UNIT_1, 0x100)
Driver --> App : HAL_OK

end

group Start input capture (DMA mode)

App -> Driver : HAL_HRTIM_TIM_Start_DMA(&hhrtim, HAL_HRTIM_TIMA | HAL_HRTIM_TIMB)
Driver -> Driver: Enable capture 1 DMA request
Driver->DMA : Start DMA transfer in interrupt mode
Driver --> App : HAL_OK

end

group DMA transfer complete interrupt processing\n

ISR -> DMA: HAL_DMA_IRQHandler(&hdma)
DMA -> DMA: Clear interrupt flag
DMA -> Driver: hrtim_dma_cb_cplt(&hdma)
Driver -> Driver: Retrieve HAL_HRTIM_TIMx from hdma
Driver -> App: HAL_HRTIM_DMACpltCallback(&hdma, HAL_HRTIM_TIMA)
App -> App: DMA transfer complete processing
App --> Driver
Driver --> DMA
DMA --> ISR

end

@enduml

Called functions:

PWM signal generation with DMA

@startuml
' To add a number by line
'autonumber
' Fix order of each column

participant "User Application" as App
participant "HAL HRTIM" as Driver
participant "HAL DMA" as DMA

group HRTIM Initialization
App -[hidden]>Driver
end

group DMA channel Initialization (Memory to Peripheral)
App->DMA : DMA channel initialization
App->Driver :  HAL_HRTIM_SetDMA(&hhrtim, HAL_HRTIM_DMA_TIMA, &hdma)
Driver -> Driver: DMA channel handle associated to Timer A\nis stored into the HRTIM handle
Driver --> App : HAL_OK
end

group Timer A configuration

note right of App:dma_config must be persistent (accessed through the HRTIM handle by the HAL_HRTIM_TIM_Start_DMA function).
App -> App : dma_config.requests = HAL_HRTIM_OPT_DMA_REPETITION\ndma_config.src_addr = &compare_values\ndma_config.dest_addr = HRTIM_CMP1AR\ndma_config.size = 12
App->Driver : HAL_HRTIM_SetConfigDMA(&hhrtim, HAL_HRTIM_DMA_ID_TIMA, &hrdma_config)
Driver -> Driver: Pointer to the Timer A DMA configuration\nis stored into the HRTIM handle
Driver --> App : HAL_OK

App -> App : \ntimer_a_config.period = 0x2000\ntimer_a_config.repetition = 9
App->Driver : HAL_HRTIM_TIM_SetConfig(&hhrtim, HAL_HRTIM_TIMA, &timer_a_config)
Driver --> App : HAL_OK

App->Driver : \nHAL_HRTIM_TIM_SetCompareValue(&hhrtim, HAL_HRTIM_TIMA, HAL_HRTIM_COMPARE_UNIT_1, 0x10)
Driver --> App : HAL_OK

App->Driver : HAL_HRTIM_TIM_EnableDeadtime(&hhrtim, HAL_HRTIM_TIMA)
Driver --> App : HAL_OK

App -> App : \ncha1_config.set = HAL_HRTIM_OUT_SET_TIM_CMP1\ncha1_config.reset = HAL_HRTIM_OUT_RESET_TIM_PERIOD
App->Driver : HAL_HRTIM_OUT_SetConfig(&hhrtim, HAL_HRTIM_CHA1, cha1_config)
Driver --> App : HAL_OK
note right of App: From this point onward, HRTIM outputs are ready to be connected to the MCU I/Os.\nIn the GPIO controller, the selected HRTIM I/Os must be configured as per the alternate function mapping.

end

group Start Signal generation (DMA mode)

App -> Driver : HAL_HRTIM_OUT_Enable(&hhrtim, (HAL_HRTIM_CHA1 | HAL_HRTIM_CHA2))
Driver --> App : HAL_OK

App -> Driver : HAL_TIM_Start_DMA(&hhrtim, HAL_HRTIM_TIMA)
Driver -> Driver: Enable repetition DMA request
Driver->DMA : Start DMA transfer in interrupt mode
Driver --> App : HAL_OK

end

group DMA transfer complete interrupt processing\n

ISR -> DMA: HAL_DMA_IRQHandler(&hdma)
DMA -> DMA: Clear interrupt flag
DMA -> Driver: hrtim_dma_cb_cplt(&hdma)
Driver -> Driver: Retrieve HAL_HRTIM_TIMx from hdma
Driver -> App: HAL_HRTIM_DMACpltCallback(&hdma, HAL_HRTIM_TIMA)
App -> App: DMA transfer complete processing
App --> Driver
Driver --> DMA
DMA --> ISR

end

@enduml

Called functions: