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

Re: [BluePill+] problem with USART interrups

Posted: Sat Jul 12, 2025 5:56 pm
by trimarco232
I can not change Serial , because I need it for the USB
Can you please tell me where I can find the function "USART3_IRQHandler" in the core , which folder and which file : I was looking for it in Arduino15 , but with no success yet

Re: [BluePill+] problem with USART interrups

Posted: Sun Jul 13, 2025 12:36 am
by ozcar
For me Windows File Explorer search (if that is what you did) often tricks me, but I was just looking at another core interrupt routine a few days ago, so I had a clue where to start, and I found it in
Arduino15\packages\STMicroelectronics\hardware\stm32\<version>\libraries\SrcWrapper\src\stm32\uart.c

Re: [BluePill+] problem with USART interrups

Posted: Wed Jul 16, 2025 8:42 pm
by trimarco232
yes , that was it , thank you all !
I just modified the name of the function "USART3_IRQHandler" in the uart.c file , and now it works fine (even if I consider it to be a shame to have to do it this way ; I will look for some better HAL function instead)
(But the most important thing is that I can continue and probably finish my project , still no error on my PCB)

Re: [BluePill+] problem with USART interrups

Posted: Thu Jul 17, 2025 5:02 am
by fpiSTM
If you used USB you should be able to define HAL_UART_MODULE_ONLY then no need to change core file.