Relay state after reboot


we struggle with the following situation. We would like the relays to start in an ‘on’ state after a reboot. If need be, I am willing to modify the source code (available on github) to achieve this goal, unfortunately I have been unable to locate any build instructions so far.



You can compile the source code with the IDE mplab x and compiler XC32.
You’ll need the PRO version (i think there’s a 30day trial).

Open the project and compile.
If there’s any problem, just post it here.

Am I missing a bootloader project?

Output from the mplab x ide underneath

[quote]make -f nbproject/ SUBPROJECTS= .build-conf
make[1]: Entering directory ‘C:/Projects/VM204-Firmware-master’
cd /D …/Bootloader/MPLAB_X_Workspace/ETH_Btl_ETH_StarterKit.X && make MAKE_OPTIONS=" -j 16" -f Makefile CONF=default
The system cannot find the path specified.
make[1]: *** [.build-subprojects] Error 1
make[1]: *** Waiting for unfinished jobs…
nbproject/ recipe for target ‘.build-subprojects’ failed
“User defined pre-build step: [“C:\Projects\VM204-Firmware-master”\utils\ResourceCompiler\bin\rc.exe “C:\Projects\VM204-Firmware-master”\resources\ “C:\Projects\VM204-Firmware-master”\Main\res.c]”







test.json (27 bytes)

api_reference.shtml (7240 bytes)




settings_json.shtml (2557 bytes)




grids-responsive-min.css (9796 bytes)




  side-menu-old-ie.css (1955 bytes)

  side-menu.css (2075 bytes)

pure-min.css (17286 bytes)

vm204.css (1290 bytes)

index.shtml (7765 bytes)




jquery.min.js (93868 bytes)

ui.js (360 bytes)

vm204.js (13494 bytes)

settings.shtml (17305 bytes)

vm204.png (29456 bytes)

205068 bytes successfully written !

make: *** [.build-impl] Error 2
make[1]: Leaving directory ‘C:/Projects/VM204-Firmware-master’
nbproject/ recipe for target ‘.build-impl’ failed

BUILD FAILED (exit value 2, total time: 412ms)[/quote]


Yes you’ll need the bootloader.
Download this first and extract the hex file. …

In MPLAB X open the Loadables folder.
And rightclick on ETH_Btl_ETH_Starterkit and hit remove.
After that rightclick on the Loadables folder and select “Add Loadable File”
Then select the file you’ve previously downloaded.

And try compiling again

Best Regards

Great! Thanks for the help, and the clear instructions. The situation has improved (a lot :-)), but I still seem to be missing a .h file (plib.h). Where can I find this one?

[quote]“C:\Program Files (x86)\Microchip\xc32\v1.42\bin\xc32-gcc.exe” -g -x c -c -mprocessor=32MX695F512H -ffunction-sections -O1 -DUSE_PIC32_ETH_STARTER_KIT -D__XC -Icyclone_crypto -Icyclone_ssl -Icyclone_tcp -Icommon -Icommon/freertos/portable/mplab/pic32mx -Icommon/freertos/include -IMain -I…/…/…/…/Downloads/CycloneTCP_SSL_Crypto_Open_1_6_0/demo/common/microchip/boards/pic32_eth_starter_kit -I…/…/VM204.X/cyclone_tcp -MMD -MF build/default/production/Main/main.o.d -o build/default/production/Main/main.o Main/main.c -DXPRJ_default=default -no-legacy-libc
nbproject/ recipe for target ‘build/default/production/Main/main.o’ failed
“C:\Program Files (x86)\Microchip\xc32\v1.42\bin\xc32-gcc.exe” -g -x c -c -mprocessor=32MX695F512H -ffunction-sections -O1 -DUSE_PIC32_ETH_STARTER_KIT -D__XC -Icyclone_crypto -Icyclone_ssl -Icyclone_tcp -Icommon -Icommon/freertos/portable/mplab/pic32mx -Icommon/freertos/include -IMain -I…/…/…/…/Downloads/CycloneTCP_SSL_Crypto_Open_1_6_0/demo/common/microchip/boards/pic32_eth_starter_kit -I…/…/VM204.X/cyclone_tcp -MMD -MF build/default/production/cyclone_tcp/std_services/daytime.o.d -o build/default/production/cyclone_tcp/std_services/daytime.o cyclone_tcp/std_services/daytime.c -DXPRJ_default=default -no-legacy-libc
Main/main.c:32:18: fatal error: plib.h: No such file or directory
#include <plib.h>
compilation terminated.
make[2]: *** [build/default/production/Main/main.o] Error 1[/quote]

edit: I found a plib.h under the lega-c directory, but it is filled with references to other header files that are also not found (and most I can’t seem to find anywhere else)

[quote]#include <peripheral/adc10.h>
#include <peripheral/bmx.h>
#include <peripheral/cmp.h>
#include <peripheral/cvref.h>
#include <peripheral/dma.h>
#include <peripheral/i2c.h>
#include <peripheral/incap.h>
#include <peripheral/int.h>
#include <peripheral/nvm.h>
#include <peripheral/outcompare.h>
#include <peripheral/pcache.h>
#include <peripheral/pmp.h>
#include <peripheral/ports.h>
#include <peripheral/power.h>
#include <peripheral/reset.h>
#include <peripheral/rtcc.h>
#include <peripheral/spi.h>
#include <peripheral/system.h>
#include <peripheral/timer.h>
#include <peripheral/uart.h>
#include <peripheral/wdt.h>
#include <peripheral/eth.h>
#include <peripheral/CAN.h>[/quote]


Since V1.40 of XC32 the plib files are not included anymore.

You can download them here seperately … e=en574270

Best Regards

Hi again,

pulls hair out this is an extremely frustrating (and slow) process.

I managed to download the libraries, but now I obviously need to somehow convince MPLabs to look into the correct folders to find this(these) file(s). I don’t have much experience with the MPlab IDE and I have tried adding a path to the 1.40 folders in the project settings, but this has then led to MPLab not finding base c includes anymore. Adding more folders to the settings created new and strange warnings and errors.

Could anyone please explain how I can get this code to compile and output a useful hex file. If need be I will start over from scratch.


I’ll try to make a version for you.

EDIT: I’ve checked and I know now why I didn’t implement the feature. I write the settings to an external Flash IC. The IC has an endurance of 100,000 write cycles. If I say write every second to the flash it would only last just over a day.

I can implement it, but the card would be broken in a few days.

I must be dense, but I don’t understand what you mean. Even if you were to restart the relay in the state they were at shutdown, this would only require recording their state at reception of an instruction to change their state. But even that is not required: all we want is that the relays start in an ON (closed) state after a powercycle (independent of what state they were in at the time of shutdown), I fail to see how this affects writing to an EEPROM.

To clarify, we use the VM204 to powercycle devices in remote locations when these devices crash (which does not happen very often, or when they reauire a powercycle to update their firmware). The problem with the situation as it is now is that after the site suffers a blackout (which happens every now and then), the devices fail to reboot automatically (since the VM204 defaults to a relays off state), until we send commands to the VM204 to turn the relays back on.

The changes required to the firmware are thus quite limited, but I need to be able to compile a valid hex-file, which I so far have completely failed to do.

Hope this help clarify things a bit,



Sorry I’ve interpreted incorrectly. I thought the relay state must be kept after a reboot.

Anyways, the relays will be on when the cards boots up.

Here’s your custom firmware. …

Thanks a lot!

Edit: tested it - works perfectly as expected!

I’ve updated the firmware, only relay 1,2,3 were on.