Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed compile errors for STM32 boards #179

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Silveryard
Copy link

For stm32 (like the STM32F103C8T6 aka BluePill) we need to manually include stdarg.h.
Also avr/pgmspace.h does not define vsnprintf_P so this has to be done manually.

In the second commit I fixed some compiler warnings. There´s still 2 left though regarding a possible buffer overflow in EspDrv::sendData:


.piolibdeps\WiFiEsp\src\utility\EspDrv.cpp: In static member function 'static bool EspDrv::sendData(uint8_t, const uint8_t*, uint16_t)':
.piolibdeps\WiFiEsp\src\utility\EspDrv.cpp:803:6: warning: 'sprintf' may write a terminating nul past the end of the destination [-Wformat-overflow=]
bool EspDrv::sendData(uint8_t sock, const uint8_t *data, uint16_t len)
^~~~~~
In file included from C:\users\sebif\.platformio\packages\framework-arduinoststm32-maple\STM32F1\cores\maple/WString.h:29:0,
from C:\users\sebif\.platformio\packages\framework-arduinoststm32-maple\STM32F1\cores\maple/wirish.h:47,
from C:\users\sebif\.platformio\packages\framework-arduinoststm32-maple\STM32F1\cores\maple/Arduino.h:30,
from .piolibdeps\WiFiEsp\src\utility\EspDrv.cpp:19:
C:\users\sebif\.platformio\packages\framework-arduinoststm32-maple\STM32F1\cores\maple/avr/pgmspace.h:28:37: note: 'sprintf' output between 15 and 21 bytes into a destination of size 20
#define sprintf_P(s, f, ...) sprintf((s), (f), __VA_ARGS__)
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
.piolibdeps\WiFiEsp\src\utility\EspDrv.cpp:808:2: note: in expansion of macro 'sprintf_P'
sprintf_P(cmdBuf, PSTR("AT+CIPSEND=%d,%u"), sock, len);
^~~~~~~~~
.piolibdeps\WiFiEsp\src\utility\EspDrv.cpp: In static member function 'static bool EspDrv::sendData(uint8_t, const __FlashStringHelper*, uint16_t, bool)':
.piolibdeps\WiFiEsp\src\utility\EspDrv.cpp:831:6: warning: 'sprintf' may write a terminating nul past the end of the destination [-Wformat-overflow=]
bool EspDrv::sendData(uint8_t sock, const __FlashStringHelper *data, uint16_t len, bool appendCrLf)
^~~~~~
In file included from C:\users\sebif\.platformio\packages\framework-arduinoststm32-maple\STM32F1\cores\maple/WString.h:29:0,
from C:\users\sebif\.platformio\packages\framework-arduinoststm32-maple\STM32F1\cores\maple/wirish.h:47,
from C:\users\sebif\.platformio\packages\framework-arduinoststm32-maple\STM32F1\cores\maple/Arduino.h:30,
from .piolibdeps\WiFiEsp\src\utility\EspDrv.cpp:19:
C:\users\sebif\.platformio\packages\framework-arduinoststm32-maple\STM32F1\cores\maple/avr/pgmspace.h:28:37: note: 'sprintf' output between 15 and 21 bytes into a destination of size 20
#define sprintf_P(s, f, ...) sprintf((s), (f), __VA_ARGS__)
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
.piolibdeps\WiFiEsp\src\utility\EspDrv.cpp:837:2: note: in expansion of macro 'sprintf_P'
sprintf_P(cmdBuf, PSTR("AT+CIPSEND=%d,%u"), sock, len2);
^~~~~~~~~

@Silveryard Silveryard changed the title Fixed compile errors for STM32 architecture Fixed compile errors for STM32 boards May 10, 2019
@aster94
Copy link

aster94 commented Mar 24, 2020

I can confirm that this fixes the problem, @bportaluri also note that the problem is not relevant only to stm32 but also to others, see: #55
the above fix doesn't break compile compatibility on arduino UNO

@hawkliao
Copy link

hawkliao commented Apr 13, 2021

I've added some updates in the #define in order to be compatible to stm32duino, with Blue Pill:
http://dan.drown.org/stm32duino/package_STM32duino_index.json

The updates:

#if defined(ARDUINO_ARCH_STM32) || defined (STM32_MCU_SERIES)
//For va_start
#include <stdarg.h>

//vsnprintf_P is not defined in avr/pgmspace.h for ststm32-maple
#define vsnprintf_P vsnprintf
#endif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants