Safe mode - init output

Good morning.
I made a shield for the photon. It has some digital inputs/outputs and 2 analog outputs.
I have to initialize the analog outputs and 2 digital outputs to HIGH when the photon starts or goes into safe mode… how can I do it? Have I to rebuild the firmware? And in that case, what function I have to edit to do that?
Thanks a lot
Flavio

write these lines in void setup () function

pinMode(<your_pin_variable>, OUTPUT);
digitalWrite(<pin_var>, HIGH);

Thanks, but I don’t think it will work in safe mode…
In normal state the firmware is working ok, my problem is only in safe mode.
Thanks, Flavio

but if you want to define some constraints thats the only way out or set an endpoint and there write thost line so while you are hitting thost endpoints using api that lines would probably be executed first. letme know if it works

@TheAnonymusMaker, Safe Mode does not execute any user code.
What @flavio.ferrandi actually wants to know (I guess :blush:) is where to alter a “private” version of system firmware by building with a local toolchain.

But before going into that: @flavio.ferrandi, have you thought of pulling the pins high externally instead?
If that was a way open for your use case, that’d make things a lot easier for you :wink:

Thanks @ScruffR, you are right.
The problem is that I have already done a production of the boards, and I just discovered the problem… Right now it’s not possible to fix this in hw way…
I’ve already build my “private” system firmware some time ago, before the softap…
But I don’t understand where is the part of code of the safe mode…
Thanks, Flavio

You could look at main.cpp void manage_safe_mode() as a starting point.

Or in the same file in void app_loop(bool threaded) you’ll find this part

                if (system_mode()!=SAFE_MODE)
                 setup();

there you could add an else branch that does your own pin setup.

Thank you, I’ll try it
Flavio

Hello again.
I’m trying to add a void safemode() function that will be called on app_loop if it is in safe_mode status (instead of setup). the safemode() function could be implemented in the user firmware.

In main.cpp

void app_loop(bool threaded)
...
   if (system_mode()!=SAFE_MODE)
        setup();
   else
        safemode();
...

and in system_user.h

...
void setup();
void loop();
void safemode();
...

It’s the first time i edit system folder. I use to edi only the main folder.
When I make the firmware, I receive:
firmware-0.5.3/main/src/main.cpp:513: undefined reference to `safemode’

Where have I to declare it? I don’t find the right header…
Thanks a lot
Flavio

system_user.h might be a good place to put the prototype, but there are several copies of that file, which one did you use?

On the other hand due to the dynamic linking of HAL there might be another set of setup() & loop() which is indicated by this
user_part_export.c

/**
 * Export these functions with a fuller name so they don't clash with the setup/loop wrappers in the system module.
 */
void module_user_setup() {
    setup();
}

void module_user_loop() {
    loop();
    _post_loop();
}

#include "user_dynalib.h"

So the quickest way to get your pins set in Safe Mode might be to set them there and then in main.cpp

1 Like

Hi! I wasn’t able to create a function called when in safe mode…
But I was able to init some pins to HIGH or LOW. It’s good enough for my target.
If anyone is interested in it, we could open a pull request to call a user function on safemode start.
Flavio