STM8S103F3 IAR Error - Page 1
Forum section: electronics / general

author: maurosmartins
author_rank: Regular Contributor
timestamp: May 27, 2016, 10:19:33 am
content: Hello all,I've just installed the 8k limited version of IAR for STM8 controllers and I'm testing it with the stm8s103f3P6.When testing the interrupts I've included the "iostm8s103f3.h" header and started having the following error:Code:Error: expected a ")" C:\Program Files (x86)\IAR Systems\Embedded Workbench 7.3\stm8\inc\iostm8s103f3.h 1164inspecting the header file I see that the error is being generated by the OPT bit in the following structure:Code:/* Flash control register 2 */#ifdef __IAR_SYSTEMS_ICC__typedef struct{unsigned char PRG : 1;unsigned char : 3;unsigned char FPRG : 1;unsigned char ERASE : 1;unsigned char WPRG : 1;unsigned char OPT : 1;} __BITS_FLASH_CR2;#endif__IO_REG8_BIT(FLASH_CR2, 0x505B, __READ_WRITE, __BITS_FLASH_CR2);If I change the OPT bit name for OOPT for example the error disappears and everything is ok.Does someone know why does this happens?Thanks in advanced,best regards, Mauro.

author: richardman
author_rank: Frequent Contributor
timestamp: May 27, 2016, 10:24:39 am
content: Do you have other header files before this one that might have defined OPT?

author: maurosmartins
author_rank: Regular Contributor
timestamp: May 27, 2016, 10:33:39 am
content: Hello richardman, thank you for your reply.my code is just a sample code from STM8S StdPeriph Examples (GPIO) it includes stm8s.h and after the iostm8s103f3.h.after your post I've checked the stm8s.h and it declares OPT as follows:Code:#define OPT ((OPT_TypeDef *) OPT_BaseAddress)You are right, I can't test it now but this should be the cause.I take the opportunity to ask do I need to include stm8s.h to use the standard peripheral libraries? what would a valid project configuration be?Thanks, Mauro.

author: richardman
author_rank: Frequent Contributor
timestamp: May 27, 2016, 10:44:52 am
content: No idea, I am just a compiler writer so I see this sort of problem all the times from users :-)

author: maurosmartins
author_rank: Regular Contributor
timestamp: May 27, 2016, 10:46:41 am
content: Hello, richardmannevertheless thank you for your comment, it helped me a lot understanding what is wrong!Best regards, Mauro.

author: dannyf
author_rank: Super Contributor
timestamp: May 27, 2016, 03:06:54 pm
content: I'm not convinced that that's the problem.You certainly can have a variable and an element of a struct to share the same name. Nothing wrong with that.Something else is at fault here, I think.

author: richardman
author_rank: Frequent Contributor
timestamp: May 27, 2016, 05:13:12 pm
content: Quote from: dannyf on May 27, 2016, 03:06:54 pmNope :-) If you look at the #define he finds, when expanded, it creates a bad C code in the original code snippet

author: dannyf
author_rank: Super Contributor
timestamp: May 27, 2016, 06:31:48 pm
content: QuoteYes.QuoteThe specifics are slight different but at a minimal, you will need to select the right chip, define USE_STDPERIPH_DRIVER, and define the chip name. You may also need to define the (external) oscillator frequency if used - there is a bug in the STD driver on that front -> that portion of the std lib is definitely coded by an intern,Obviously, set the include path as well.I tried the following on 1.1x, 1.2x, 1.3x, and 1.4x - the only thing I didn't try is the 2.2x. they all compiled flawlessly.Code:#include <iostm8s103f3.h>unsigned char OPT=0;typedef struct{unsigned char PRG : 1;unsigned char : 3;unsigned char FPRG : 1;unsigned char ERASE : 1;unsigned char WPRG : 1;unsigned char OPT : 1;} __myBITS_FLASH_CR2;__IO_REG8_BIT(myFLASH_CR2, 0x505B, __READ_WRITE, __myBITS_FLASH_CR2);int main( void ) {return 0;}

author: dannyf
author_rank: Super Contributor
timestamp: May 27, 2016, 06:46:27 pm
content: I usually don't use the device specific header files. Even if I don't use the std periph lib, I still use stm8s.h for the struct-like register layout.project configurations can be gleaned from the stm8s.h file.

author: maurosmartins
author_rank: Regular Contributor
timestamp: May 27, 2016, 10:55:03 pm
content: Hello all, thank you for your replies!dannyf, I have defined the microcontroller and USE_STDPERIPH_DRIVER as follows:I've also removed the controller specific header. But, this way where can I check the interrupt vectors? do you write the vector directly?Best regards, Mauro.

author: dannyf
author_rank: Super Contributor
timestamp: May 28, 2016, 02:05:11 am
content: The right way is to read the compiler manual;The wrong way is to read stm8s.h, towards the end.