Function pointers work with spark compile but not particle compile

Hi,

I have the following function declaration that compiled and ran successfully on the spark core using spark compile:

     void download(HttpDownloadRequest &aRequest, HttpDownloadResponse &aResponse, HttpDownloadHeader headers[], void(*callback)(byte*, int, void*), void* callbackParam);

The pentultimate param is a c++ function pointer. When I compile with particle compile for my photon, I get this:
HttpDownload.h:62:128: error: expected ‘,’ or ‘…’ before ‘(’ token

Did the compiler change? Are function pointers no longer supported?

Thanks,
Ryan

C99/C++11, and with it, function pointers, is still fully supported.

The code that you pasted looks fine. And I can paste this into the WebIDE


class HttpDownloadRequest;
class HttpDownloadResponse;
class HttpDownloadHeader;

void download(HttpDownloadRequest &aRequest, HttpDownloadResponse &aResponse, HttpDownloadHeader headers[], void(*callback)(byte*, int, void*), void* callbackParam);

Which compiles fine. So it would seem the error lies somewhere else. If you can paste a link to the code that I can try I’m happy to help you investigate other possible causes of the error.

Weird.

‘particle compile core’ compiles the project correctly.
‘particle compile photon’ fails.

Let me take a look at the source with fresh eyes in the morning and see if I can see anything weird.

Thanks,
Ryan

1 Like

The problem above was caused by my code not including application.h and using the “byte” typedef - not required on the core, but needed on the photon, apparently :smile:

Now I have problems with PIN_MAP, but there are other threads I need to read through on that. I’m guessing the libraries I’m using aren’t updated yet.

Consider this one resolved.

Thanks!
Ryan

@rsteckler, you are correct regarding the PIN_MAP issue. The upcoming firmware release will include a set of fast IO functions that will replace the “direct” PIN_MAP reference with inline functions. This will also make its way to the new Core firmware released that is planned. So this will allow for a standardized way to do fast IO on any existing and future Particle platforms :smile:

BTW - a bit write with the new fast IO code takes about 30 nanoseconds :stuck_out_tongue:

Thanks, @peekay123 .

For now, is there a simple way to get the old PIN_MAP code working? It’s being used in the sd2card library I’m using.

Thanks!
Ryan

Yes, in the meantime you can use

#if defined(PLATFORM_ID)
#include "pinmap_hal.h"
static STM32_Pin_Info* PIN_MAP = HAL_Pin_Map();
#endif

Hmm. I get this:
Sd2Card.cpp:768:40: error: ‘struct GPIO_TypeDef’ has no member named 'BSRR’
PIN_MAP[mosiPin_].gpio_peripheral->BSRR = PIN_MAP[mosiPin_].gpio_pin; // Data High

Sd2Card.cpp:770:40: error: ‘struct GPIO_TypeDef’ has no member named 'BRR’
PIN_MAP[mosiPin_].gpio_peripheral->BRR = PIN_MAP[mosiPin_].gpio_pin; // Data Low

Sd2Card.cpp:772:40: error: ‘struct GPIO_TypeDef’ has no member named 'BSRR’
PIN_MAP[clockPin_].gpio_peripheral->BSRR = PIN_MAP[clockPin_].gpio_pin; // Clock High

Sd2Card.cpp:778:40: error: ‘struct GPIO_TypeDef’ has no member named 'BRR’
PIN_MAP[clockPin_].gpio_peripheral->BRR = PIN_MAP[clockPin_].gpio_pin; // Clock Low

Nevermind. Got it :smile:

The answer is here: https://github.com/sazp96/SparkCore-SD/commit/2a077274a96738de561ac07db36352a0b4f74b10