Fast GPIO-Toggle with portenta H7 using HAL

Hello everybody.
I want to use the Portenta H7 to realize a very simple but fast OOK transmitter. Therefore I need to generate 10 us rectangular pulses, which I can achieve by utilizing HAL GPIO operations in combination with a timer.
Now the problem: I noticed that although most of the pulses are exactly 10 us, some of them are up to 14 us long, which is a problem for the receiver.
Thinking this might result from the timer overflow, I removed it completely leaving only GPIO bit banging as you can see in the following code example:

//#include "stm32h7xx_hal_gpio.h"

void setup() {
  // put your setup code here, to run once:
  MX_GPIO_Init();           // Initialize GPIO 
}

void loop() {
  // put your main code here, to run repeatedly:

HAL_GPIO_WritePin(GPIOH, GPIO_PIN_15, GPIO_PIN_SET); // SET Pin PH15 HIGH
HAL_GPIO_WritePin(GPIOH, GPIO_PIN_15, GPIO_PIN_RESET); // SET Pin PH15 LOW

}




// ------------------------ GPIO Pin Initialization for STM32 ------------------------
void MX_GPIO_Init()
{
  /* GPIO Ports Clock Enable */
 __HAL_RCC_GPIOH_CLK_ENABLE();

 GPIO_InitTypeDef GPIO_InitStruct; 

  /*Configure GPIO pin : PH15 */
 GPIO_InitStruct.Pin = GPIO_PIN_15;       // Pin15  -> D0 on arduino portenta  
 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; // digital Output, push-pull configuration
 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
 HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);  // GPIO-H
}

The result can be seen in image0 in the attachment. The GPIO-toggle works very fast. One cycle takes no more than 50 ns. However, as can be seen in the image0, every 125 us there is a break of about 4 us, where nothing happens. This problem was also discovered here
https://www.raspberrypi.org/forums/viewtopic.php?t=13892
but no solution was found. Since the delays from 10us to 14us are also happening every 125 us I think this might be the cause.
Has anybody an idea what causes those breaks and how to get rid of them?
Greetings

image0.jpg

image0.jpg

Hello again.

For those, who are interested, I found a solution how to get rid of the interrupts that appear every 125 us. It seems that some hidden interrupt-routines are causing the GPIO operation to be suspended for up to 4us.

The solution was to insert noInterrupts():

https://www.arduino.cc/reference/en/language/functions/interrupts/nointerrupts/

in front of the time critical operation and then re-enable interrupts with interrupts() afterwards. The result can be seen in the attached image.