STM32 Uart and PWM doesn't work at the same time

I know this is the Arduino forum but I am writing because I have urgent work. In the code I have, pwm is written as bare metal and uart is written with hal. I am using the STM32 F401RE model. PWM uses TIM1 CH1 and Ch2, TIM 10, TIM11, and Uart is with the TIM 2 Hal library. When I run the code alone, both of them work separately but when I combine them, they do not work. Since the codes are a bit long, I am sending them as a file. Your ideas are very valuable, please help.
DC_MOTORS.c (1.2 KB)
main (13).c (11.3 KB)

Sorry I cannot follow your code but from your description it is blocking in both the motor and UART sections.

Please show the code as text

Okey, I send the important part of the code, not fully.


uint8_t rxbuff[8];
uint8_t txempty;
uint8_t rxfull;

int32_t linear_number;
int32_t angular_number;

int16_t linear_pwm_value=0;
int16_t angular_pwm_value=0;


void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart){
  if (huart == &huart2)
  {
    rxfull = 1;
  }
}



void GPIO_Init(void) {
    // GPIOA ve GPIOB saatlerini etkinleştir
    RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN_Msk | RCC_AHB1ENR_GPIOBEN_Msk;

    // PB8 (TIM10_CH1), PB9 (TIM11_CH1) - AF3
    GPIOB->MODER &= ~(GPIO_MODER_MODE8_Msk | GPIO_MODER_MODE9_Msk);
    GPIOB->MODER |= GPIO_MODER_MODE8_1 | GPIO_MODER_MODE9_1;
    GPIOB->AFR[1] &= ~(GPIO_AFRH_AFSEL8_Msk | GPIO_AFRH_AFSEL9_Msk);
    GPIOB->AFR[1] |= (0b0011 << GPIO_AFRH_AFSEL8_Pos) | (0b0011 << GPIO_AFRH_AFSEL9_Pos);

    RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN_Msk;



    // === PA0: TIM5_CH1 ===
    GPIOA->MODER &= ~GPIO_MODER_MODE0_Msk;
    GPIOA->MODER |= GPIO_MODER_MODE0_1;  // Alternate Function
    GPIOA->AFR[0] &= ~GPIO_AFRL_AFSEL0_Msk;
    GPIOA->AFR[0] |= (0b0010 << GPIO_AFRL_AFSEL0_Pos);  // AF2 (TIM5_CH1)

    // === PA1: TIM5_CH2 ===
    GPIOA->MODER &= ~GPIO_MODER_MODE1_Msk;
    GPIOA->MODER |= GPIO_MODER_MODE1_1;  // Alternate Function
    GPIOA->AFR[0] &= ~GPIO_AFRL_AFSEL1_Msk;
    GPIOA->AFR[0] |= (0b0010 << GPIO_AFRL_AFSEL1_Pos);  // AF2 (TIM5_CH2)
}


void TIM5_Init(void) {
    RCC->APB1ENR |= RCC_APB1ENR_TIM5EN;  // TIM5 saatini etkinleştir

    // Kanal 1 (PA0) ve Kanal 2 (PA1) için PWM mode 1 yapılandırması
    TIM5->CCMR1 &= ~TIM_CCMR1_OC1M_Msk;  // Kanal 1 için mod temizle
    TIM5->CCMR1 |= TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_1;  // PWM Mode 1 (kanal 1)
    TIM5->CCMR1 |= TIM_CCMR1_OC1PE;  // Preload enable

    TIM5->CCMR1 &= ~TIM_CCMR1_OC2M_Msk;  // Kanal 2 için mod temizle
    TIM5->CCMR1 |= TIM_CCMR1_OC2M_2 | TIM_CCMR1_OC2M_1;  // PWM Mode 1 (kanal 2)
    TIM5->CCMR1 |= TIM_CCMR1_OC2PE;  // Preload enable

    // Kanal 1 ve Kanal 2'yi etkinleştir
    TIM5->CCER |= TIM_CCER_CC1E | TIM_CCER_CC2E;

    // Timer ayarları
    TIM5->PSC = 0;   // Prescaler (Timer frekansı için uygun değeri ayarlayın)
    TIM5->ARR = 50000;  // Otomatik yeniden yükleme değeri
    TIM5->CCR1 = 25000; // Kanal 1 için %50 duty cycle
    TIM5->CCR2 = 25000; // Kanal 2 için %50 duty cycle

    // Timer'ı başlat
    TIM5->CR1 |= TIM_CR1_ARPE;  // Auto-reload preload etkinleştir
    TIM5->EGR |= TIM_EGR_UG;    // Update event
    TIM5->CR1 |= TIM_CR1_CEN;   // Timer'ı çalıştır
}

void TIM10_Init(void) {
    RCC->APB2ENR |= RCC_APB2ENR_TIM10EN;

    TIM10->CCMR1 |= TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1PE;
    TIM10->CCER |= TIM_CCER_CC1E;

    TIM10->PSC = 0;
    TIM10->ARR = 50000;  // Otomatik yeniden yükleme değeri
    TIM10->CCR1 = 25000; // Kanal 1 için %50 duty cycle


    TIM10->CR1 |= TIM_CR1_ARPE | TIM_CR1_CEN;
}

void TIM11_Init(void) {
    RCC->APB2ENR |= RCC_APB2ENR_TIM11EN;

    TIM11->CCMR1 |= TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1PE;
    TIM11->CCER |= TIM_CCER_CC1E;

    TIM11->PSC = 0;
    TIM11->ARR = 50000;  // Otomatik yeniden yükleme değeri
    TIM11->CCR1 = 25000; // Kanal 1 için %50 duty cycle



    TIM11->CR1 |= TIM_CR1_ARPE | TIM_CR1_CEN;
}

/* USER CODE END 0 */

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{
  /* USER CODE BEGIN 1 */
	GPIO_Init();
	TIM5_Init();
	TIM10_Init();
	TIM11_Init();

  /* 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_USART2_UART_Init();
  /* USER CODE BEGIN 2 */


  HAL_UART_Receive_DMA(&huart2, rxbuff, 8);
  rxfull = 0;

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {

    /* USER CODE BEGIN 3 */
      if (rxfull == 1){
        rxfull = 0;
        linear_number = (int32_t)(rxbuff[0]<<24) + (int32_t)(rxbuff[1]<<16) + (int32_t)(rxbuff[2]<<8) + rxbuff[3];
        angular_number = (int32_t)(rxbuff[4]<<24) + (int32_t)(rxbuff[5]<<16) + (int32_t)(rxbuff[6]<<8) + rxbuff[7];

        linear_pwm_value = (linear_number/12500);
        angular_pwm_value = (angular_number/12500);
        DC_Control(15000,0);
      }
    /* USER CODE END WHILE */

  }
  /* USER CODE END 3 */
}

In the code, the dc_motor function is working and the arr of the channels is changing dynamically (for frequency change) but when does the uart come into play, we guess it does not enter the if statement because it does not receive data.

I sent it.