cancel
Showing results for 
Search instead for 
Did you mean: 

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

Rajesh Kannan
Associate II
 
15 REPLIES 15
Rajesh Kannan
Associate II

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
Evangelist III

"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

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
Up vote any posts that you find helpful, it shows what's working..

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?

@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,

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.

 gpio_init_structure.Speed   = GPIO_SPEED_FAST; // FAST=50, HIGH=100

 //gpio_init_structure.Speed   = GPIO_SPEED_FREQ_VERY_HIGH;

Perhaps be using SLOW or MEDIUM if there is negligible load on the pin/signal

See also SystemClock_Config()

/*
  Note : The activation of the I/O Compensation Cell is recommended with communication  interfaces
          (GPIO, SPI, FMC, QSPI ...)  when  operating at  high frequencies(please refer to product datasheet)
          The I/O Compensation Cell activation  procedure requires :
        - The activation of the CSI clock
        - The activation of the SYSCFG clock
        - Enabling the I/O Compensation Cell : setting bit[0] of register SYSCFG_CCCSR
 
          To do this please uncomment the following code
*/
 
  __HAL_RCC_CSI_ENABLE() ;
 
  __HAL_RCC_SYSCFG_CLK_ENABLE() ;
 
  HAL_EnableCompensationCell();

For high-speed pattern output, consider the FMC bus into a latch. Plus it's far less likely to saturate the processor. Have you considered a simple CPLD/FPGA for brutal grunt work that's ill suited to a general purpose MCU?

Are you driving a print head?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

> 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

Thanks Tesla ,

We are not driving the print head. We are analyzing the feasibility for proof of concept.

It has resolved the ringing issue with proper test setup.

In SystemClock_Config() enabled the suggested code by you.

With previous explained procedure not going beyond the 11 Mhz.

Is it possible to achieve the 20 Mhz in STM32H7 MCU?

@Rajesh Kannan​ "We are not driving the print head. We are analyzing the feasibility for proof of concept"

What concept are you attempting to prove?

Does the end-goal involve a printhead?