How to flash .h and .cpp files to a device?

LOL! i discovered that trick last night. That is pretty cool. Thanks for the heads up on that one. I thought i was breaking something when i went to delete the .cpp. The error message looked pretty crazy.

i opened up the main.cpp and i do not have 2 of the files… application.h and stdint.h. Grrrrr…

Here’s what i have so far…

You should add #pragma once to the top of all your .h files.

Some of your redefinition messages come from the fact that the header files are not guarded against multiple inclusion. The instruction above does that.

You also should not have two sets of setup() and loop() (one in main.cpp and the other in macs.ino). Just copy the code from main.cpp to your macs.ino and remove main.cpp thereafter.

After all that, you’ll be left with two errors I can’t quite see where they come from without actually diving into the code for which I don’t have the time yet

../../../hal/src/photon/lib/STM32F2xx_Peripheral_Libraries.a(stm32f2xx_flash.o): In function `FLASH_Unlock':
/Users/avtolstoy/Development/particle/photon-wiced/WICED/platform/MCU/STM32F2xx/peripherals/libraries/src/stm32f2xx_flash.c:317: undefined reference to `__flash_acquire'
../../../hal/src/photon/lib/STM32F2xx_Peripheral_Libraries.a(stm32f2xx_flash.o): In function `FLASH_Lock':
/Users/avtolstoy/Development/particle/photon-wiced/WICED/platform/MCU/STM32F2xx/peripherals/libraries/src/stm32f2xx_flash.c:335: undefined reference to `__flash_release'

@avtolstoy, since these messages seem to point to some directory of yours, could you have a look where they come from, please?
I’ve reworked the code to also get rid of some warnings to get as little distraction as possible from the compiler :wink:

1 Like

Go with whatever @ScruffR points out and additionally:

I saw that you didn’t copy the contents of main.cpp into macs.ino. I would copy the contents of main.cpp into macs.ino, then delete main.cpp. The main.cpp contains your setup() and loop() which can only exist once in your entire project. If you have them also in macs.ino, it will not compile.

application.h isn’t a file you have to have… it provides a link into the Device OS. I think it’s there for Arduino compatibility. Particle provides a lot of compatibility for native-Arduino code so it should be fine.

stdint.h provides a link to standard C++ integer types. Again, it’s not a file you have to have but links into existing routines available in C++.

My explanation for application.h and stdint.h may not pass muster with the C++ gurus but I think it will suffice.

1 Like

Ok. I added the #pragma to the top of my .h files. i copied the contents of the main.cpp to the macs.ino file > verified > 2 error messages. You were right! Thanks for help! Here’s the link to the latest… I have to go and run an errand… i will return later this afternoon.

It’s failing to find the function FLASH_Lock() and FLASH_Unlock(). I cannot find that function in any of the file in your project. Since we have no way of knowing what those functions do, (@peekay123 knows below) I just commented them out in both the macs.ino and wifi_login.cpp. After that, it compiled.

Assuming this might have been something from the Arduino world, I googled the function names but didn’t get any good results.

@ninjatill, the errors I see are:

/Users/avtolstoy/Development/particle/photon-wiced/WICED/platform/MCU/STM32F2xx/peripherals/libraries/stm32f2xx_flash.c:317:0: undefined reference to "__flash_acquire"
/Users/avtolstoy/Development/particle/photon-wiced/WICED/platform/MCU/STM32F2xx/peripherals/libraries/stm32f2xx_flash.c:335:0: undefined reference to "__flash_release" 

The FLASH_Lock() function is a low level function defined in STM32F2xx_flash.c but the make plumbing seems to be off such that these errors pop up. @ScruffR, any thoughts?

1 Like

@stankcheeze, it seems that changes in the DeviceOS after 0.6.3 break the FLASH_Lock() call. Compiling with DeviceOS version 0.6.3 produces no errors so give that a shot.


Good find! how do i compile with 0.6.3? Or should i just comment those calls out?

In the Web IDE, click on the “Devices” menu and change the “System Firmware Target:” for your device to 0.6.3:


1 Like

For some more reading on the Web IDE, here are the references:

A while back I’ve seen a similar report and here is Rick’s response back then

1 Like

I changed the firmware target to 0.6.3 and it verified. However, when i go to flash it, it is giving “You are not including led.h log_backup.h rest_client.h wifi_login.h even though they are a part of this app. Are you sure you want to continue? To include these files, please hit cancel and add include lines to the top of the
to the top of the main app file”. Should i proceed?

That’s just an ignorant warning from the Web IDE which expects you to include these headers in your .ino file since it doesn’t know that you’ll be indirectly including it anyhow.
This doesn’t harm the program at all, but if you want, you can add the include statements to remove that message.

ok. i will try again this evening. thanks again everyone for your help.


update… i had to login with a different laptop at home. i was getting several more error messages. i removed the MACS app and readded them back in with the instructions from above. I copied the contents of the main.cpp into the macs.ino, added the #pragma once into the .h files (first line), set the rom level to 0.6.3 now i am getting one error message. undefined reference to “wlan_select_antenna”. i tried to bring back the app link that i sent out in this message, however, all i get is a blank screen when i click on the link. i have been working on this for hours and trying not to bother you…

Once you remove the base project from your account all shared revisions get invalidated too.
This is the version I’ve still got stored
This builds for me with 0.6.3 (as does yours)

1 Like

Having trouble opening shared files… When i click on your link (or any other shared app links), it opens up the Particle Web IDE page and I do not get anything else? Do i add it thru the libraries? I have tried copying the link directly into Chrome, Firefox, Internet Explorer and… (father forgive me… Edge).

I’m using Chrome and just clicking on the link should suffice.
However, when you copy/past the link make sure you are not also copying the view count that’s automatically appended to the link.
My link ends on 118 but when copy/paste it I get 1182 (currently two views have been registered).