Skip to main content
Rajesh Kannan
Associate II
July 21, 2022
Question

STM32H750 Discovery kit Clock Generation on GPIO Pin @ 10Mhz speed using DMA (Memory to peripheral copy).Clock is not coming properly and it is ringing

  • July 21, 2022
  • 15 replies
  • 2821 views

..

This topic has been closed for replies.

15 replies

Rajesh Kannan
Associate II
July 21, 2022

STM32H750 Discovery kit Clock Generation on GPIO Pin @ 10Mhz speed using DMA (Memory to peripheral copy).

Timer 5 is configured for 10 MHZ speed to trigger the DMA. In the DMA transfer (Memory to Peripheral) we are using the GPIO PB4 for clock generation. Clock is generated but it is not proper. We would like to the know the reason for it and any precautions/setting we have to follow to get the proper clock.

0693W00000QLkbuQAD.pngClock Setting

0693W00000QLkgdQAD.png 

Source code main.c

int main(void)
{
	/* USER CODE BEGIN 1 */
	HAL_StatusTypeDef dataTransferStatus;
	/* USER CODE END 1 */
 
	/* MCU Configuration--------------------------------------------------------*/
 
	/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
	HAL_Init();
 
	/* USER CODE BEGIN Init */
 
	/* USER CODE END Init */
 
	/* Configure the system clock */
	SystemClock_Config();
 
	/* USER CODE BEGIN SysInit */
	/* USER CODE END SysInit */
 
	/* Initialize all configured peripherals */
	MX_GPIO_Init();
	MX_DMA_Init();
	MX_TIM1_Init();
	MX_USART1_UART_Init();
	MX_TIM2_Init();
	MX_TIM5_Init();
	printf("entered into main\r\n");
 
	//Timer Clock 240 MHZ .//Set 20 MHZ speed
	htim5.Init.Prescaler=0;
	htim5.Init.Period = 12-1;
	//Enable timer
	HAL_TIM_Base_Init(&htim5);
	__HAL_TIM_ENABLE_DMA(&htim5, TIM_DMA_UPDATE);
	__HAL_TIM_ENABLE(&htim5);
	//loading GPIO high and low to DMA buffer
	for(int i=0;i<32;i++)
	{
		if(i%2){
			gpioFirstBuf[i] = (uint32_t)GPIOB->ODR | (1<<4) ; //1 -> pulls the line low
		}
		else{
			gpioFirstBuf[i] = (uint32_t)GPIOB->ODR & ~(1<<4) ;
		}
	}
	//Start DMA toggle GPIO -> PB4
	dataTransferStatus = HAL_DMA_Start_IT(&hdma_tim5_up, (uint32_t)gpioFirstBuf, (uint32_t)&GPIOB->ODR, 24);
	if(dataTransferStatus != HAL_OK){
 
		HAL_DMA_Abort(&hdma_tim1_up);
 
	}
	/* USER CODE END 2 */
 
	/* USER CODE BEGIN WHILE */
	while (1)
	{
 
		/* USER CODE END WHILE */
 
		/* USER CODE BEGIN 3 */
	}
	/* USER CODE END 3 */
}

Captured picture using CRO.

0693W00000QLn2RQAT.png

Andrew Neil
Super User
July 21, 2022

"Clock is not observed properly"

So observe it properly, then! ;p

Seriously,

  1. How, exactly, are you generating this?
  2. How, exactly, are you observing it?
  3. What are you seeing?
  4. What is "wrong" about what you are seeing?

It would help to see your code, and a 'scope trace of the output (if possible, get a screen capture - not a photo); maybe also a good, clear, in-focus photograph of your setup.

Is there a particular reason for using DMA rather than, say, a timer ... ?

0693W000008xsqBQAQ.png

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Tesla DeLorean
Guru
July 21, 2022

Ok, what's your primary objection here? The frequency, the ringing?

Make sure to use 10x mode on the probe as frequency increases.

Driving into no-load, perhaps significantly back off the GPIO's SPEEDR setting for slew-rate from INSANELY_FAST to MEDIUM or HIGH.

On H7's also make sure the IO Compensation is properly enabled.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Rajesh Kannan
Associate II
July 22, 2022

Our objection is achieving highest frequency and ringing.

Requirement:

To generate GPIO bit banging on 3 pins in the same port at the frequency 20Mhz.

Procedure followed

1) MCU - STM32H750 (Discovery kit)

2) Timer Source Clock 240 MHZ and linked to DMA (Memory to peripheral) which will transfer the data on the GPIO pins.

3) Setting the timer 20 Mhz using the period (set period 11).

4) On timer elapse event generated to DMA transfer the data on GPIO Port.

5) As you suggested I/O compensation cell is enabled in SYSCFG_CCCSR

Observation

1) Up to 5Mhz (set period 23) the waveform is ok..

2) For 10 Mhz (set period 11), the waveform is ringing (observe the same in the above shown picture)

3) To achieve 20 Mhz(set period 5) frequency on the GPIO pins . We are observing the 10Mhz waveform is ringing.

If we set more than 10 Mhz , then there is no change in the waveform frequency and only 10Mhz waveform is ringing.

Question:

Can we achieve the 20 MHZ clock on GPIO 3 pins in the same port by bit banging?

Andrew Neil
Super User
July 22, 2022

@Rajesh Kannan​ "Our objection is achieving highest frequency and ringing."

Eh?? You want the highest ringing?!?! :o

Surely, for highest frequency, a timer direct to the pin is the way to go?

Ringing is a result of the capacitance & inductance of the wiring - you can't fix that in software!

(well, apart from adjusting slew rate, as @Community member​ said).

Also be sure that you're using a decent scope probe, and that it is properly compensated, properly grounded, etc.

Again, photos of your setup would help,

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
waclawek.jan
Super User
July 22, 2022

> It's ringing because too much energy is being dumping into the trace.

> This could be further exacerbated by the point in the trace you're probing, along with how effective the grounds, and ground connections are.

Additionally to all this, on the Disco, traces may be not optimal and some on-board circuitry may be already connected to given pin.

> For high-speed pattern output, consider the FMC bus into a latch.

Or maybe a timer. In any case, use as much hardware as possible, avoid bit-banging by software. The 'H7 is very inappropriate for accurate real-time operation, probably surprisingly for many.

> Are you driving a print head?

Do you have a Crystal Cube? :)

JW

Andrew Neil
Super User
July 22, 2022

@Community member​ "Are you driving a print head?"

@Community member​ "Do you have a Crystal Cube? :)"

Did you mean crystal ball ?

Anyhow, printhead may be inspired by:

https://community.st.com/s/question/0D53W00001dw96OSAQ/is-there-any-board-which-can-support-more-than-30-mhz-toggle-frequency-on-gpio-and-parallel-processing

@Rajesh Kannan​  - you should review that thread as it contains some (potentially) relevant suggestions - whether or not you're actually working towards a printhead...

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
waclawek.jan
Super User
July 22, 2022

> Did you mean crystal ball ?

No. It's all Cubes when it comes to STM32, said ST.

The flats throw nasty reflections and the edges get into way of sight, but hey they are sooo easy to stack onto each other!

Jan

AScha.3
Super User
November 1, 2022

just i was not aware, H7 could be slow on port access, i try : have DevEBoard here, for my audio player fun project...

simple 1. test: set port by HAL call (slow...maybe. i know. )

0693W00000VOaVlQAL.pngnow H743 at 250MHz clk , caches on, -Ofast , port speed set: low ->

0693W00000VOaYGQA1.pngso 50ns with HAL. next direct write ..

If you feel a post has answered your question, please click on " Best Answer ".
AScha.3
Super User
November 1, 2022

direct write about same : 50ns lo, 50ns hi.

then

optimzed clock tree, to get (maximum) 200MHz on AHB4 , where ports are.

and direct write >> GPIOA->BSRR = 0x00000002;

 0693W00000VObFAQA1.pngso 30 ns seem optimum with H743. :|

just for fun: test write port lo-hi-loop on stm32F303 (M4 core) - Ofast :

0693W00000VObOMQA1.pngabout 15ns , at 72MHz clk. =)

(1 clk 13,8ns at 72 MHz)

and while-loop is 100ns total, because core much slower than H7

same on F303 without optimizer , -O0

 0693W00000VObYlQAL.pngabout 340 ns !!

and funny, with -O2 faster than -Ofast :

0693W00000VObZjQAL.pngabout 83ns , 1 tic faster than fast. ;)

so optimizer -O2 speed up 400% in this small loop. :astonished_face:

If you feel a post has answered your question, please click on " Best Answer ".