Author Topic: how can i solve uart error in iar compiler  (Read 987 times)

0 Members and 1 Guest are viewing this topic.

Offline ُSTP.AsghariTopic starter

  • Newbie
  • Posts: 7
  • Country: ir
how can i solve uart error in iar compiler
« on: November 13, 2023, 06:41:39 am »
Hi everyone

I encounter an error in the iar compiler when entering the following code.

Code: [Select]
#define Enter    HAL_UART_Transmit(&huart1,(unsigned char*)E,1,10);

#define CR       HAL_UART_Transmit(&huart1,(unsigned char*)C,1,10);

#define GIM      HAL_UART_Transmit(&huart1,(unsigned char*)G,1,10);

#define SUB      HAL_UART_Transmit(&huart1,(unsigned char*)S,1,10);



The error is written in the following line:

Code: [Select]
Error[Pe136]: struct "<unnamed>#35" (declared Hat line 326 of "H:\IAR Codes\3- Sim800\sim800\Drivers\CMSIS\Device\ST\STM32F4xx\Include\stm32f401xc.h"h) has no field "HAL_UART_Transmit" H:\IAR Codes\3- Sim800\sim800\Core\Src\main.c 207




Please tell me why this error occurred and how to solve it. thank you.
 

Online Psi

  • Super Contributor
  • ***
  • Posts: 9953
  • Country: nz
Re: how can i solve uart error in iar compiler
« Reply #1 on: November 13, 2023, 07:04:45 am »
This bit looks a bit wrong. Why is there two h.
stm32f401xc.h"h)

But that may not be your issue.

Maybe check stm32f401xc.h and see if it actually has that HAL_UART_Transmit function in it.
And check if there's any #if or #ifdef around HAL_UART_Transmit that might not be including it.


Also, this isn't the problem but, don't put a ; on the end of your #define's. 
It may work for a function macro like that, but it breaks things if you want to define numbers and then use them, Like in an array index.
You end up with this.. which isnt what you wanted.
#define MyNumber 40;

MyArray[MyNumber] = 1;
Becomes..
MyArray[40;] = 1;
« Last Edit: November 13, 2023, 07:12:04 am by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline Jeroen3

  • Super Contributor
  • ***
  • Posts: 4078
  • Country: nl
  • Embedded Engineer
    • jeroen3.nl
Re: how can i solve uart error in iar compiler
« Reply #2 on: November 13, 2023, 07:21:59 am »
Please post where you are using those preprocessor directives.

struct "<unnamed>#35"  is suspect.

 

Offline ُSTP.AsghariTopic starter

  • Newbie
  • Posts: 7
  • Country: ir
Re: how can i solve uart error in iar compiler
« Reply #3 on: November 14, 2023, 07:50:01 am »
the problem solved :
at line 2 : CR was defined in main and stm32f401xc.h And because of this, the compiler gave an error. I changed CR to CR1 in the main and the problem was solved.
 

Offline radiolistener

  • Super Contributor
  • ***
  • Posts: 3374
  • Country: ua
Re: how can i solve uart error in iar compiler
« Reply #4 on: November 14, 2023, 11:16:59 pm »
you're needs to make sure that include file containing HAL_UART_Transmit definition is placed before your define which using it
 

Online Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3362
  • Country: nl
Re: how can i solve uart error in iar compiler
« Reply #5 on: November 15, 2023, 03:44:56 pm »
Also, macro's are simple text replacement, and not C statements. When defining a macro you should not put an semicolon at the end of the line, because that results in the semicolon being copied too, which results in extra (empty) statements (Which the C compiler accepts without complaining)

I don't like the use of such macro's, such short names are too easy to collide in some way. And what is up with those four single character variables (E, C, G and S) as function parameters? Trying to search for them will get many false positives. Personally I never ever use variable names that are shorter then 3 characters, even for temporary local variables. This got confirmed when I used an IDE that can automatically highlight all instances a variable is used, but it required a minimum 3 character length to avoid too many false positives. That is a very nice function to have, both when reviewing unfamiliar code or your own code you have not seen for a few years.
« Last Edit: November 15, 2023, 03:54:01 pm by Doctorandus_P »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf