Skip to main content
Robmar
Senior II
Oct 16, 2026 12:49 PM UTC
Solved

Why enabling a timer via DMA write to the CR1 register fails

I have many timers working on out H743VIT6 board, so only have Tim2, 5, 12 and above available.

I have many forms of of timer triggered DMA working, but in this case as the system is near to max capacity, I need a DMA event scheduled for 52uS in the future WITHOUT using IRQs which are not time-stable enough for the purpose.

So I found that timer 16 in table 98 of the RM0433 manual is show connecting to timer 2, but in CubeMX timer 15 shows no trigger source!

So I though I would set up timer 5 to count down 52uS and trigger its DMA stream to write a half word to CR1 of Timer 15, that was setup to pace its own DMA stream.  Now I can get tier 15 triggering and DMA transfering it I enable it via the end of event cllback for timer 5, but DMAing to CR1 of an diabled timer doesn’t seem to work.

It’s a very complicated problem!
 

// Arm one amplitude bank, started by a TIM5 countdown delay to trigger DMA write to enable a target timer with DMA stream
HAL_StatusTypeDef ArmOneBank(uint32_t *pwm_values, uint32_t DataLength, uint32_t delay_ticks)
{
HAL_StatusTypeDef status; // Free timers 2, 5 and 12-up: Timer 15 does not map to Tim5 or Tim2 in Table 98 RM0433 manual inteconnect matrix
// Timers 16 and 17 are interconnected in table 98 to timer 15, but timers 1-17 do not have trigger sources
// TIM15 in normal up-counter mode, NOT waiting for an ITR trigger
__HAL_TIM_DISABLE(&htim15);
__HAL_TIM_DISABLE_DMA(&htim15, TIM_DMA_UPDATE);

__HAL_TIM_SET_COUNTER(&htim15, 0);
__HAL_TIM_CLEAR_FLAG(&htim15, TIM_FLAG_UPDATE);

// Arm amplitude DMA while TIM15 is stopped
status = HAL_DMA_Start_IT(&hdma_tim15_up,
(uint32_t)pwm_values,
(uint32_t)&TIM8->CCR3,
DataLength);

if (status != HAL_OK)
return status;

// Prepare target timer CR1 value to enable it, preserving existing bits
tim15_cr1_start_word = (uint16_t)(TIM15->CR1 | TIM_CR1_CEN); // 0x81 Check correct!!

// Enable amplitude requests before starting TIM15
__HAL_TIM_ENABLE_DMA(&htim15, TIM_DMA_UPDATE);
///__HAL_TIM_ENABLE(&htim15); // <---- THIS LINE ENABLED THE DMA TRANSFER IMMEDIATELY - NOT DESIRED!

// Prepare TIM5 one-shot delay
__HAL_TIM_DISABLE(&htim5);
__HAL_TIM_DISABLE_DMA(&htim5, TIM_DMA_UPDATE);

__HAL_TIM_SET_COUNTER(&htim5, 0);
__HAL_TIM_SET_AUTORELOAD(&htim5, delay_ticks);
__HAL_TIM_CLEAR_FLAG(&htim5, TIM_FLAG_UPDATE);

// Arm one DMA transfer: TIM5 update -> write TIM15 CR1
status = HAL_DMA_Start_IT(&hdma_tim5_up,
(uint32_t)&tim15_cr1_start_word,
(uint32_t)&TIM15->CR1,
1);

if (status != HAL_OK)
{
__HAL_TIM_DISABLE_DMA(&htim15, TIM_DMA_UPDATE);
HAL_DMA_Abort(&hdma_tim15_up);
return status;
}

// Enable TIM5 update DMA requests only after its stream is armed
__HAL_TIM_ENABLE_DMA(&htim5, TIM_DMA_UPDATE);

// Start the one-shot countdown - when tim5 expires it will trigger its DMA
// to write the tim15_cr1_start_word to enable timer 15 but timer 15 does not pave its DMA stream for some reason
__HAL_TIM_ENABLE(&htim5);

return HAL_OK;
}

 

Robmar
RobmarBest answer
Senior II
Oct 21, 2026 12:58 PM UTC

If you look in the RM0433 manual, all 3500+ pages, around page 595 Taable 98 onwards, and especially the DMAMUX tables showing what sources can be used for synchronizing each DMA trnsfer word by word, you will see only timer 12 TRGO is listed, and othe rch events, its very limited, looks like they ran out of space to more connections in silicon!
I need the DMA to run word per word at 320 KHz, so to do that I havae the use DMAMUX to sync the transfer with timer 12, but I also have to start the transfer in teh future from the Audio IRQ to synchronize phase transfer over slow I2C bus (800KHz).
I do have it working now, but it was not easy to arrive at a configuration that worked given all the limitations of trigger and sync sources.
 

20 replies

ST Technical Moderator
Oct 16, 2026 2:00 PM UTC

Hello ​@Robmar 

Is the TIM15 peripheral clock enabled ?

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Saket_Om
Robmar
RobmarAuthor
Senior II
Oct 16, 2026 2:17 PM UTC

Yes:
 

else if(tim_baseHandle->Instance==TIM15)

{

/* USER CODE BEGIN TIM15_MspInit 0 */



/* USER CODE END TIM15_MspInit 0 */

/* TIM15 clock enable */

__HAL_RCC_TIM15_CLK_ENABLE();



/* TIM15 DMA Init */

/* TIM15_UP Init */

hdma_tim15_up.Instance = DMA2_Stream3;

hdma_tim15_up.Init.Request = DMA_REQUEST_TIM15_UP;

hdma_tim15_up.Init.Direction = DMA_MEMORY_TO_PERIPH;

hdma_tim15_up.Init.PeriphInc = DMA_PINC_DISABLE;

hdma_tim15_up.Init.MemInc = DMA_MINC_ENABLE;

hdma_tim15_up.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;

hdma_tim15_up.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;

hdma_tim15_up.Init.Mode = DMA_NORMAL;

hdma_tim15_up.Init.Priority = DMA_PRIORITY_VERY_HIGH;

hdma_tim15_up.Init.FIFOMode = DMA_FIFOMODE_DISABLE;

if (HAL_DMA_Init(&hdma_tim15_up) != HAL_OK)

{

Error_Handler();

}



__HAL_LINKDMA(tim_baseHandle,hdma[TIM_DMA_ID_UPDATE],hdma_tim15_up);



/* TIM15 interrupt Init */

HAL_NVIC_SetPriority(TIM15_IRQn, 0, 0);

HAL_NVIC_EnableIRQ(TIM15_IRQn);

/* USER CODE BEGIN TIM15_MspInit 1 */



/* USER CODE END TIM15_MspInit 1 */

}

 

Robmar
RobmarAuthor
Senior II
Oct 16, 2026 2:05 PM UTC

The STM Sidekick is pretty useless I asked it a simple question about what the documents confirm about interconnectivity of timers as it seemed to have been unable to understand the H743 manual:-

My question: In the RM0433 manual page 579, table 98, interconections, it states that : Timer 12 peripheral connects to timer 5 trgo via ITR1 - but in CubeMX Timer 12 does not have a DMA tab!!

Reply:  -Sorry, I do not have complete information to answer this question. Please start a new chat and select the appropriate STM32 series or try rephrasing your question with more specific details. My knowledge is based on the official STM32 documentation. You can also ask your question on the online ST Community to get insights from ST experts and ST Community users. Go to the ST Community-

Juli1
ST Employee
Oct 20, 2026 3:00 PM UTC

Hello Robmar,

TIM12 doesn’t support the DMA, i.e. no dma request. You can check if a TIM instance supports the DMA and which DMA request in the TIMx_DIER register with the corresponding DMA request enabling bitfields.

So, you need to use another TIM instance that supports the Update DMA request in your case and has the Internal trigger capability (ITR) to trig the counting start. In H743, you have TIM 2/3/4/5/15.

For the counter start (enable the timer), I guess it’s what you are trying now, but it’s better to use the Slave Mode Controller (SMC) to trig the counter start (TIMx_SMCR.SMS = 0110 Trigger mode) than a DMA transfer to write TIMx_CR1.CEN.

With all that, you need to find a configuration where the TIM instances support the features involved above to perform your use case.

Hope it will help,

BRs

Robmar
RobmarAuthor
Senior II
Oct 16, 2026 3:12 PM UTC

Any experts?  How about this approach:-

TIM5 update (TIM5_UP)

Delayed trigger at the end of the countdown

DMAMUX1 request generator

Generates the DMA requests for the memory to peripheral (33 words)

DMAMUX1 synchronization

TIM12_TRGO controls DMA pacing at 320 KHz per word transfer to the PWM Tim8->CCR3

DMA2 stream → TIM8->CCR3

Transfers PWMsamples

Juli1
ST Employee
Oct 20, 2026 3:29 PM UTC

From what I understand you can only use 1 DMA stream:

TIMA used to count the delayed trigger 52us and use its trgo signal to trig the counter start of another TIMB through its ITR and the Slave Mode Controller. This TIMB will be used to trig the DMA circular transfers for TIM8 PWM values (for channel 3).

timA_trgo (count 52us) → timB_itrx (trig the counter start) + timB_upd_dma request (DMA transfers to TIM8_CCR3) at 320KHz → TIM8 PWM values updated.

 

TIMA can be TIM 2/3/4/5/12/15, so General Purpose (GP) with 2 and 4 channels (also advanced timers TIM1/8 that you already use). The optimize choice would be TIM12 as you keep the GP 4 channels with more features for other purposes.
TIMB can also be TIM 2/3/4/5/12/15 but it needs to be chosen according to TIMA for the ITR interconnection availability.

 

P.S. for your 1st question of the thread, for the interconnections between the different peripherals, the source of trust is the RM and not CubeMX. Maybe there is a miss and we need to fix it.

Robmar
RobmarAuthor
Senior II
Oct 17, 2026 11:52 AM UTC

I guess STM continues to save technical support staff costs, which I beleive will hit product uptake against the likes of ESP32

TDK
Oct 17, 2026 8:21 PM UTC

Okay let’s try to answer this. DMA can clearly write to timer registers, as that is done in a multitude of examples. So the problem must be something else.

You set up DMA for a word write but say you are writing a half word. Which is correct?

Can you provide a minimal (non) working example? The snippets are helpful if something is glaringly wrong but seems not the case here.

A MWE would be best here. Yes that takes some effort on your part but on the upside you may find the solution while constructing the example. And/or as some members prefer the register values at the time of it not working. But that can be difficult when the values are changing.

 

The STM Sidekick is pretty useless I asked it a simple question

AI is not going to always have the answer. That doesn’t mean it’s useless, just that it can’t answer your specific question. I would rather have it say “I don’t have the info to answer that” than try to gaslight me with slop. It’s not going to have information about the CubeMX UI screen. It will have the manual, but the UI screen and the thousands of variations of what does what isn’t going to be there. Not to mention it changes slightly with each release as features are added and bugs fixed and sometimes reintroduced.

I guess STM continues to save technical support staff costs, which I beleive will hit product uptake against the likes of ESP32

It’s a thankless job answering questions. Sometimes you get silence back, sometimes you give the correct response and people just argue with you. If you are very lucky, you get some internet points which (with the weekly leaderboard) mostly disappear away after a week. And disappear entirely when the forum software inevitable changes every few years. The incentives are not there. For ST or for community members. ST staff get paid and clearly they’re encouraging participation here. The majority of ST contributions here are excellent, some really go above and beyond. Some people just like doing it and you get lucky. It’s also the weekend and only a day since you posted. Come on, you’ve been here for a while. Be reasonable. Not saying you will get an answer, but expecting one after 24 hours and on the weekend is the wrong expectation.

Also, friend, if you think support for ESP32 will be any better than here, you are in for a surprise.

"If you feel a post has answered your question, please click ""Accept as Solution""."
LCE
Principal III
Oct 21, 2026 10:48 AM UTC

Maybe it’s one of these DMA PSIZE / MSIZE problems? Have you played with this?

Or some other DMA setting (BURST, DIR, ...) ?

And well, maybe one of the HAL functions doesn’t like something in that setup?

rich.g.williams
Senior
Oct 21, 2026 12:31 PM UTC

​@Robmar  Sidekick does say sorry sometimes but not always clear what has upset it, my strategy is then to ask it a simple question to get going again and then rephrase your question.

With respect what you are doing (using lots of timers to trigger lots of DMA channels) sounds a complicated way forward to me.

I can’t get that interested in it as its explained, but some suggestions that may help:-

  1. have you considered having one pure timer (no input no output no DMA) running near SYSCLOCK speed as an overall sequencer? For a delay of d, let the timer decrement read and remember at time t1 then read again, when it reads t2 where t1-d <= t2 the delay d has elapsed. Let it run this time recording time t2 and again when t2-d <= t3 d has again elapsed. Using 2’s complement 32-bit there is no overflow problem. This one timer can then sequence several jobs (where you have d1, d2, d3 etc) to nanosecond accuracy.
  2. For your immediate job if you find that DMA cannot write config registers how about arranging things so that the DMA channel’s linked list writes to your config register. That will work, its the whole point of linked lists.
  3. Also have you looked at the “Peripherals interconnect matrix” as a way to connect timers to each other? Maybe you are already using this?

 

Bill's Notes
Robmar
RobmarAuthorBest answer
Senior II
Oct 21, 2026 12:58 PM UTC

If you look in the RM0433 manual, all 3500+ pages, around page 595 Taable 98 onwards, and especially the DMAMUX tables showing what sources can be used for synchronizing each DMA trnsfer word by word, you will see only timer 12 TRGO is listed, and othe rch events, its very limited, looks like they ran out of space to more connections in silicon!
I need the DMA to run word per word at 320 KHz, so to do that I havae the use DMAMUX to sync the transfer with timer 12, but I also have to start the transfer in teh future from the Audio IRQ to synchronize phase transfer over slow I2C bus (800KHz).
I do have it working now, but it was not easy to arrive at a configuration that worked given all the limitations of trigger and sync sources.
 

rich.g.williams
Senior
Oct 21, 2026 7:20 PM UTC

 

I’m beginning to understand what you are trying to do now, something is giving you an IRQ at the start but the data is not yet available but it will be after 52uS. Its starting to sound like a really interesting setup. 

You could try having a look at page 666 on RM0517 Table 125, its for the newer STM32H5E5 / 5F5 so not the same but the Peripherals interconnect matrix table looks much more compact and maybe its better explained in a newer reference.

Glad you got it working!

 

Bill's Notes
rich.g.williams
Senior
Oct 22, 2026 11:26 AM UTC

​@Robmar 

Glad you solved this.

Have been thinking about what you are doing and now I realise that you are using say Timer A to begin DMA transfer from Device B to Device C. That's neat I never thought of that "three party" DMA the method could be really useful for several things.

The reference manuals are long but what I suggest is get really familiar with the index and jump from it, in my setup I have the manual on screen all the time on a different machine.

I suggest (if not already done) you take some time studying DMA linked lists and how they work, once understood they give a lot of control flexibility and would suit your cunning style of DMA use.

Good luck with your project.

Richard 

Bill's Notes
Robmar
RobmarAuthor
Senior II
Oct 22, 2026 11:44 AM UTC

hahaha yes, very cunning!  One timer is the trigger counting down to start the pacing timer that then kicks out each word of DMA at the required rate.  It sounds simple but then the limitations of which timer can trigger which other time, and which timer can trigger the DMAMUX units all get a bit restrictive, especially adding to already well developed projects that use nearly all the timers for real-time processing.  I’ve been working on this since ‘23 but there’s always something new to learn and near zero support from STM staff, who seem hellbent on destroying STM… or that’s how it looks!
You know they told me, STM’s “experts” that if I wanted 96 Kbs or higher USB with audio the only way was to install Azure RTOS, for wihch the H743 didn’t have enough memory left to do!  In the end I had to write nearly from scratch the entire device and host USB drivers for composite device support with audio at up to 192 Kbs, and I had only a few weeks to do it, very painful experience, but now its working streaming at 192 Kbs in stereo 16-bit, and virtual com and keyboard at the same time!  Who needs RTOS!

rich.g.williams
Senior
Oct 22, 2026 1:09 PM UTC

Ah ok but don't be hard on ST employees, there are so many products and as you point out reference books are 3,500 plus pages long, then people genuinely don't know without years of experience.  I am also working towards using SAI and SPI for processing high quality audio, you would understand my STM32 notes on my website billsnotes.co.uk

For your project you could consider STM32H5E5ZJ it has 4MB Flash and 1.5 MB SRAM, also has PLAY FPGA built in the PLAY would also have solved your problem. Only thing is it's not as fast as your choice but it can do SYSCLOCK 248MHz from the HSI RC oscillator.

 

Bill's Notes
Robmar
RobmarAuthor
Senior II
Oct 22, 2026 3:55 PM UTC

It’s not the STM staff that are failing the company IMO, its the management, they’re letting ESP32 steal the show and I think its avoidable.  Pushing Azure RTOS and pay per installation AI support down customers throats is just a path to failure, IMO!
I wish I could use the H5E but I need the 480 MHz core with DSP math, and I need the 3 ADC, I could do with more and better ADC too, clients won’t pay for more.
Of course STM will hang on to their core sensor and automotive clients for a while longer, but I’d sell your shares soon!