Skip to main content
Visitor II
January 23, 2019
Question

Unable to Initialize Uart (HAL_UART_Init())

  • January 23, 2019
  • 5 replies
  • 3451 views

Hi everyone,

I want to start using the H743ZI serial communication with an hyperterminal software but i am not able to compile my project. I am using the STM32Cube_FW_H7_V1.3.0 UART POLLING example as a reference but everytime i try to compile my project i get those errors

.ARM has both ordered and unordered sections

final link failed: Bad value

make: *** [uart2.elf] Error 1

recipe for target 'uart2.elf' failed makefile /uart2/Debug

In my intent to solve this problem i delete this part of code:

 if(HAL_UART_Init(&UartHandle) != HAL_OK)

 {

  Error_Handler();

 }

and get no errors, but doing that i am not able to initialize the uart port.

Here is my main code, wish you can help me to face this problem.

int main(void)

{

 /* Enable the CPU Cache */

 CPU_CACHE_Enable();

 /* STM32H7xx HAL library initialization:

    - Systick timer is configured by default as source of time base, but user

     can eventually implement his proper time base source (a general purpose

     timer for example or other time source), keeping in mind that Time base

     duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and

     handled in milliseconds basis.

    - Set NVIC Group Priority to 4

    - Low Level Initialization

   */

 HAL_Init();

 /* Configure the system clock to 400 MHz */

 SystemClock_Config();

 /* Configure LED1, LED2 and LED3 */

 BSP_LED_Init(LED1);

 BSP_LED_Init(LED2);

 BSP_LED_Init(LED3);

 /*##-1- Configure the UART peripheral ######################################*/

 /* Put the USART peripheral in the Asynchronous mode (UART Mode) */

 /* UART configured as follows:

   - Word Length = 8 Bits

   - Stop Bit = One Stop bit

   - Parity = None

   - BaudRate = 115200 baud

   - Hardware flow control disabled (RTS and CTS signals) */

 UartHandle.Instance    = USARTx;

 UartHandle.Init.BaudRate   = 115200;

 UartHandle.Init.WordLength  = UART_WORDLENGTH_8B;

 UartHandle.Init.StopBits   = UART_STOPBITS_1;

 UartHandle.Init.Parity    = UART_PARITY_NONE;

 UartHandle.Init.HwFlowCtl  = UART_HWCONTROL_NONE;

 UartHandle.Init.Mode     = UART_MODE_TX_RX;

 //UartHandle.Init.OverSampling = UART_OVERSAMPLING_16;

 //UartHandle.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;

 if(HAL_UART_DeInit(&UartHandle) != HAL_OK)

 {

  Error_Handler();

 }

 if(HAL_UART_Init(&UartHandle) != HAL_OK)

 {

  Error_Handler();

 }

 /* Infinite loop */

 while (1)

 {

 HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, sizeof(aTxBuffer), HAL_MAX_DELAY);

 HAL_Delay(1000);

 }

}

    This topic has been closed for replies.

    5 replies

    Graduate II
    January 23, 2019

    The error suggests the linker doesn't like something, perhaps the linker script. Look to see if there is more output.

    Sorry don't know enough about your build environment.

    MEscoAuthor
    Visitor II
    January 23, 2019

    0690X000006DCaIQAW.jpgSorry if i didn't explain very well. I am using a nucleo H743ZI board , version of HAL is STM32Cube_FW_H7_V1.3.0 and i am building my code on System Workbench for STM32 Eclipse.

    I attached an image to make it easier to understand

    Technical Moderator
    January 23, 2019

    Hello,

    After check, the application is compiled successfully.

    It seems that your problem is due to your linker options in the configuration of project and not the example code.

    Kind Regards,

    Imen

    MEscoAuthor
    Visitor II
    January 23, 2019

    Hi Imen, thanks for your answer. Can you explain me how you configure your linker options in case of using a nucleo H743ZI boards, please. I want to see where my mistake is.

    Visitor II
    April 27, 2019

    Hi

    I came across this same issue today, and got exactly the same error as described. I narrowed it down to an issue with one of the macros in stm32h7xx_hal_uart.h, UART_DIV_LPUART on line 1142, which is used in the UART_SetConfig method. After removing the (uint64_t) typecast from within the macro my code compiles without any issue. Putting the typecast back immediately brings the error back when trying to compile. I noted is that none of the other similar macros defined in that area of the header file use any typecasting in them.

    Visitor II
    July 19, 2019

    Hi,

    I also have this problem. I searched for the cause and found that the problem arises when the __aeabi_uldivmod internal function is called (in the UART_DIV_LPUART macro). This function is located in the libgcc.a library an is used by compiler to divide uint64_t numbers. The __aeabi_uldivmod function calls the __udivmoddi4 function (in the same library), which causes this error if is included in the project by compiler/linker.

    I use the SW4STM32 IDE and toolchain (and library) has version 1.17.0.201812190825. Project is for Nucleo STM32H743ZI2 board.

    You can also reproduce this problem by calling __udivmoddi4 from anywhere as follows:

    main.c:

    void __udivmoddi4();

    void main()

    {

       __udivmoddi4();

    }

    I don't know the exact reason, maybe the libgcc library is incorrectly builded, or my compiler or linker is incorrectly set, and unfortunately I don't have a good solution. But maybe this information will help someone.

    Of course it is possible to download the source file of __udivmoddi4 from https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads, unpack it, extract the definition of the __udivmoddi4 function (from the libgcc2.c file) and insert it to project in separate file. I tested it, it works, but it is not nice solution.

    Visitor II
    July 22, 2019

    Hi,

    check the linker script, and fix the ALIGN(32) values in .ARM block from value 32 to 4:

     .ARM : {

       . = ALIGN(4);

       __exidx_start = .;

       *(.ARM.exidx*)

       __exidx_end = .;

       . = ALIGN(4);

     } >ROM

    It works for me.

    Visitor II
    July 9, 2020

    Hello,

    Its about one year, but i confirm that your method works!! Anf uart works well. Thanks you very much @J�lius Kov�cs​