Variable types in Arduino IDE

Development environment specific, Arduino, Eclipse, VS2013, Em::Blocks etc
Post Reply
Phono
Posts: 68
Joined: Thu Mar 19, 2020 9:32 am

Variable types in Arduino IDE

Post by Phono »

After years of use of the arduino IDE + Roger's core that kept evolving, I had a rather poor development environment that I would be unable to rebuild in case of a crash, due to the number of fixes and tweaks that were accumulated over time.
I have decided to build a new environment on a fresh machine, and I have installed Arduino 1.8.12 to which I added the STM32 board collection of the official repository (stm32duino/Arduino_core_STM32 from github), plus the STM32CubeProgrammer.
This worked rather easily.
Now I am starting to port my sketches and my special libraries to this environment, and I have a problem with the data types.
Previously I used libmaple_types.h as the base for declarations. It provided me with the definitions of uint8, int8, uint16, int16, uint32, and int32.
This library was obviously a legacy from the long defunct maple leaflabs environment. So, what can I do now to get these definitions? Does the STM32 core provide for this, even if the names are different?
I have checked the help file of the Arduino IDE, and I get a confusing landscape.
byte and unsigned byte are ok.
integer and unsigned integer are 16-bit long for AVR chips, but are 32-bit long for Arduino Due. What for STM32?
long integer and unsigned long integer are 32-bit long for AVR chips, but they say nothing about the Arduino Due.
Is there an official convention for the STM32 core?
fredbox
Posts: 125
Joined: Thu Dec 19, 2019 3:05 am
Answers: 2

Re: Variable types in Arduino IDE

Post by fredbox »

You can use the fixed width types without having to include any special headers:

Code: Select all

int8_t
uint8_t
int16_t
uint16_t
int32_t
uint32_t
int64_t
uint64_t
Something like

Code: Select all

#define int8 int8_t
or

Code: Select all

typedef int8_t int8;
should work to use your previous definitions.
Phono
Posts: 68
Joined: Thu Mar 19, 2020 9:32 am

Re: Variable types in Arduino IDE

Post by Phono »

Thank you, this problem is solved. However, I have yet another problem. In my sketch I massively used the __FLASH__ attribute to store string constants in flash and spare the RAM. This attribute is not accepted by the compiler any more. What is the new syntax for this?
stas2z
Posts: 131
Joined: Mon Feb 24, 2020 8:17 pm
Answers: 8

Re: Variable types in Arduino IDE

Post by stas2z »

Code: Select all

const
will be enough
fredbox
Posts: 125
Joined: Thu Dec 19, 2019 3:05 am
Answers: 2

Re: Variable types in Arduino IDE

Post by fredbox »

Code: Select all

char const * msg[] = 
{
  "test string 001",
  "test string 002",
  "test string 003",
  "test string 004",
  "test string 005",
  "test string 006"
};
Sketch uses 16456 bytes
Global variables use 3532 bytes

Change the first line to:

Code: Select all

char const * const msg[] = 
Sketch uses 16456 bytes
Global variables use 3508 bytes

The strings are saved to flash in either case. The second method also saves the pointers to flash.
Phono
Posts: 68
Joined: Thu Mar 19, 2020 9:32 am

Re: Variable types in Arduino IDE

Post by Phono »

Thanks, it worked.
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: Variable types in Arduino IDE

Post by mrburnette »

For reference and history, an adjunct to fredbox's answer: https://www.embedded.com/introduction-t ... -integers/

...the 1999 update to the International Organization for Standardization's (ISO) C standard (hereafter “C99”) did just that. The ISO has finally put the weight of its standard behind a preferred set of names for signed and unsigned fixed-size integer data types. The newly defined type names are:

8-bit: int8_t uint8_t
16-bit: int16_t uint16_t
32-bit: int32_t uint32_t
64-bit: int64_t uint64_t
According to the updated standard, this required set of typedef s (along with some others) is to be defined by compiler vendors and included in the new header file stdint.h .

If you're already using a C99-compliant compiler, this new language feature makes declaring each required fixed-width integer variable or register definition as straightforward as using one of the new type names.


For PC systems, C++11 compilers will likely support: https://en.cppreference.com/w/cpp/types/integer


Ray
fredbox
Posts: 125
Joined: Thu Dec 19, 2019 3:05 am
Answers: 2

Re: Variable types in Arduino IDE

Post by fredbox »

These integer types are also available for use in Roger's libmaple core.
Post Reply

Return to “IDE's”