How to use HAL_UART_RxCpltCallback function

Post here first, or if you can't find a relevant section!
JimEli
Posts: 20
Joined: Sat Apr 17, 2021 11:33 pm

How to use HAL_UART_RxCpltCallback function

Post by JimEli »

I am using an Adafruit STM32F405 Feather board with the Arduino IDE. I’m trying to setup a UART DMA receive channel and want to access the HAL_UART_RxCpltCallback callback. However, the compiler always fails with a multiple definition error:
c:/users/default.laptop-7v09roba/appdata/local/arduino15/packages/stm32/tools/xpack-arm-none-eabi-gcc/9.2.1-1.1/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\default.LAPTOP-7V09ROBA\Documents\Arduino\Build\libraries\SrcWrapper\stm32\uart.c.o: in function `HAL_UART_RxCpltCallback':
uart.c:(.text.HAL_UART_RxCpltCallback+0x0): multiple definition of `HAL_UART_RxCpltCallback'; C:\Users\default.LAPTOP-7V09ROBA\Documents\Arduino\Build\sketch\stm32f405_dma_uart_int.ino.cpp.o:stm32f405_dma_uart_int.ino.cpp:(.text.HAL_UART_RxCpltCallback+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
Using library SrcWrapper at version 1.0.1 in folder: C:\Users\default.LAPTOP-7V09ROBA\AppData\Local\Arduino15\packages\STM32\hardware\stm32\1.9.0\libraries\SrcWrapper
exit status 1
Error compiling for board Generic STM32F4 series.

I have tried adding a build_opt.h file to the folder with -DHAL_UART_MODULE_ONLY, but that fails too.
by fpiSTM » Sun Apr 18, 2021 8:54 am
Which environment you used ? Arduino IDE ?

Using HAL_UART_MODULE_ONLY is the correct way but it seems not take in account during your build.
As you can see here https://github.com/stm32duino/Arduino_C ... art.c#L791 the HAL_UART_RxCpltCallback is well under this switch.

One common issue is to build first without the build_opt.h then rebuild with it but it is not take in account due to cache issue.
See the warning section: https://github.com/stm32duino/wiki/wiki ... .h#warning

Simply try to restart the IDE.
Go to full post
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: How to use HAL_UART_RxCpltCallback function

Post by fpiSTM »

Which environment you used ? Arduino IDE ?

Using HAL_UART_MODULE_ONLY is the correct way but it seems not take in account during your build.
As you can see here https://github.com/stm32duino/Arduino_C ... art.c#L791 the HAL_UART_RxCpltCallback is well under this switch.

One common issue is to build first without the build_opt.h then rebuild with it but it is not take in account due to cache issue.
See the warning section: https://github.com/stm32duino/wiki/wiki ... .h#warning

Simply try to restart the IDE.
JimEli
Posts: 20
Joined: Sat Apr 17, 2021 11:33 pm

Re: How to use HAL_UART_RxCpltCallback function

Post by JimEli »

I'm using the Arduino IDE.

And it looks like the IDE needed a restart to pick up my option in the build_opt.h file I'm using, -DHAL_UART_MODEL_ONLY

Thanks for your help.
JimEli
Posts: 20
Joined: Sat Apr 17, 2021 11:33 pm

Re: How to use HAL_UART_RxCpltCallback function

Post by JimEli »

Is it possible to use the USART_2_IRQHandler in a Feather STM32F405 board with the Arduino IDE and the official STM core?

Whenever try to use the handler in my program, I receive a multiple definition error during compile. I have tried defining both HAL_MODULE_UART_ENABLED and HAL_MODULE_UART_ONLY (and in combination) and neither works.

What am I doing wrong?
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: How to use HAL_UART_RxCpltCallback function

Post by fpiSTM »

Where did you defined them?
Look in the wiki build_opt.h
JimEli
Posts: 20
Joined: Sat Apr 17, 2021 11:33 pm

Re: How to use HAL_UART_RxCpltCallback function

Post by JimEli »

I put them in the build_opt.h file located inside the sketch folder. I thought I was having cache issues, so I made Tool menu changes to command a complete rebuild, so I don't think that is the issue.
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: How to use HAL_UART_RxCpltCallback function

Post by fpiSTM »

Do you use extern "C" before the function definition?

Share your code it will be easier to help.
JimEli
Posts: 20
Joined: Sat Apr 17, 2021 11:33 pm

Re: How to use HAL_UART_RxCpltCallback function

Post by JimEli »

This code does nothing, but presents the problem I am experiencing.

Here is the error I get:

c:/users/default.laptop-7v09roba/appdata/local/arduino15/packages/stm32/tools/xpack-arm-none-eabi-gcc/9.2.1-1.1/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\default.LAPTOP-7V09ROBA\Documents\Arduino\Build\libraries\SrcWrapper\stm32\uart.c.o: in function `USART2_IRQHandler':
uart.c:(.text.USART2_IRQHandler+0x0): multiple definition of `USART2_IRQHandler'; C:\Users\default.LAPTOP-7V09ROBA\Documents\Arduino\Build\sketch\sketch_may28a.ino.cpp.o:sketch_may28a.ino.cpp:(.text.USART2_IRQHandler+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
Using library SrcWrapper at version 1.0.1 in folder: C:\Users\default.LAPTOP-7V09ROBA\AppData\Local\Arduino15\packages\STM32\hardware\stm32\1.9.0\libraries\SrcWrapper
exit status 1
Error compiling for board Generic STM32F4 series.

Code: Select all

//sketch file
UART_HandleTypeDef huart2;

extern "C" void USART2_IRQHandler(void) {
  HAL_UART_IRQHandler(&huart2);
  // do something here...
}

static void MX_USART2_UART_Init(void) {
  GPIO_InitTypeDef GPIO_InitStruct = {0};

  huart2.Instance = USART2;
  huart2.Init.BaudRate = 9600;
  huart2.Init.WordLength = UART_WORDLENGTH_8B;
  huart2.Init.StopBits = UART_STOPBITS_1;
  huart2.Init.Parity = UART_PARITY_NONE;
  huart2.Init.Mode = UART_MODE_TX_RX;
  huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  if (HAL_UART_Init(&huart2) != HAL_OK)
    while(1);

  __HAL_RCC_USART2_CLK_ENABLE();
  __HAL_RCC_GPIOA_CLK_ENABLE();
  GPIO_InitStruct.Pin = GPIO_PIN_2 | GPIO_PIN_3;
  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  HAL_NVIC_SetPriority(USART2_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(USART2_IRQn);
 }

void setup(void)
{
  MX_USART2_UART_Init();
}

void loop(void) { 
  // do something here...
}

Code: Select all

//build_opt.h
-DHAL_UART_MODULE_ENABLED
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: How to use HAL_UART_RxCpltCallback function

Post by fpiSTM »

I did not check the code but before do that please try with 2.0.0 core version.
JimEli
Posts: 20
Joined: Sat Apr 17, 2021 11:33 pm

Re: How to use HAL_UART_RxCpltCallback function

Post by JimEli »

Same thing after the update.

If I use -DHAL_UART_MODULE_ENABLED, I get a duplicate definition.
If I use -DHAL_UART_MODULE_ONLY, the HAL UART modules are not included.

c:/users/default.laptop-7v09roba/appdata/local/arduino15/packages/stmicroelectronics/tools/xpack-arm-none-eabi-gcc/9.3.1-1.3/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\default.LAPTOP-7V09ROBA\Documents\Arduino\Build\libraries\SrcWrapper\stm32\uart.c.o: in function `USART2_IRQHandler':
uart.c:(.text.USART2_IRQHandler+0x0): multiple definition of `USART2_IRQHandler'; C:\Users\default.LAPTOP-7V09ROBA\Documents\Arduino\Build\sketch\sketch_may28a.ino.cpp.o:sketch_may28a.ino.cpp:(.text.USART2_IRQHandler+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
Using library SrcWrapper at version 1.0.1 in folder: C:\Users\default.LAPTOP-7V09ROBA\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.0.0\libraries\SrcWrapper
exit status 1
Error compiling for board Generic STM32F4 series.
Post Reply

Return to “General discussion”