Page 1 of 1

[BluePill+] problem with USART interrups

Posted: Sat Jul 12, 2025 9:19 am
by trimarco232
Hi,
in my current project , I am dealing with RS485 , on my way. I am writing directly into the registers , in order to know exactly what I am doing , and what happens
The problem here is that after receiving a byte , the program stops ; I don't now if it is just before it enters the ISR (USART3_IRQHandler) ,or later .
I have put the same code in CubeIDE , it works , so I wonder what happens in STM32duino ? Thanks !
(my skills to debug in STM32duino are limited because of the terrible each time to compile)

Code: Select all

/* rs.h x : rs485 on usart3 /* ua_rt.h */

#define DE485 PB12

void usart3_setup() {

  RCC->APB1ENR |= RCC_APB1ENR_USART3EN;  // Enable clock

  // Configure PB10 (TX) and PB11 (RX)
  GPIOB->CRH &= ~(GPIO_CRH_CNF10 | GPIO_CRH_MODE10 | GPIO_CRH_CNF11 | GPIO_CRH_MODE11);  /// pas nécessaire ...
  GPIOB->CRH |= (GPIO_CRH_CNF10_1 | GPIO_CRH_MODE10_0 | GPIO_CRH_CNF11_0);               // alternate PP // input ... PU

  // Configure USART3
  USART3->BRR = 72000000 / 2 / 57600;                            // 57600 baud rate , APB1 is CLK/2
  USART3->CR1 = USART_CR1_TE | USART_CR1_RE | USART_CR1_RXNEIE;  // Enable TX and RX  // Enable RXNE interrupt
  USART3->CR1 |= USART_CR1_UE;                                   // Enable USART
  NVIC_EnableIRQ(USART3_IRQn);

  pinMode(DE485, OUTPUT);
}

void USART3_IRQHandler(void) {
  uint16_t data = USART3->DR;
   Serial.print("USART3->DR:");
  Serial.println(data);
}

Re: [BluePill+] problem with USART interrups

Posted: Sat Jul 12, 2025 10:06 am
by fpiSTM

Code: Select all

extern "C" void USART3_IRQHandler(void)
And avoid print in ISR.

Re: [BluePill+] problem with USART interrups

Posted: Sat Jul 12, 2025 11:10 am
by trimarco232
thanks ,
I tried it but got : (.text.USART3_IRQHandler+0x0): multiple definition of `USART3_IRQHandler';
(ok to avoid to print in ISR)

Re: [BluePill+] problem with USART interrups

Posted: Sat Jul 12, 2025 12:23 pm
by fpiSTM
That is normal. The handler is already defined for the serial. You have to comment it in the core if you want use Serial. Else you can define the HAL_UART_MODULE_ONLY but Serial instance will be disabled.

https://github.com/stm32duino/Arduino_C ... odule-only