Hello ArduPilot Community,
I’m currently working with a Pixhawk Orange Cube running ArduCopter 4.2.4 and ChibiOS firmware, and I have a question regarding the button circuit connected to the GPS1 port.
Setup Details:
Firmware: ArduCopter 4.2.4
Microcontroller: Pixhawk Orange Cube
Operating System: ChibiOS
Button Circuit Pinout (GPS1 Port):
Pin 1 (red) - VCC (5V)
Pin 2 (blk) - TX (OUT, 3.3V)
Pin 3 (blk) - RX (IN, 3.3V)
Pin 4 (blk) - SCL (I2C2, 3.3V)
Pin 5 (blk) - SDA (I2C2, 3.3V)
Pin 6 (blk) - Button (GND)
Pin 7 (blk) - Button LED (GND)
Pin 8 (blk) - GND (GND)
I am trying to locate the exact section of the source code that reads the hardware state of the button on the GPS1 port (not the safety state, but the actual electronics that detect the button press). Specifically, I want to understand how the system handles the button’s electrical input at the hardware layer, rather than the safety mechanism logic.
Could anyone guide me to the relevant files or functions in the ArduPilot source code that manage this button’s circuit and its interaction with the firmware?
If possible, I would appreciate information on how the code processes the signal coming from the button pin.
Thank you for your quick response and for the suggestion!
I did look at the code within the #ifdef HAL_GPIO_PIN_SAFETY_IN block, and I understand the logic behind it. However, the issue I’m encountering is that the code doesn’t seem to enter this block, even though the safety state appears to be changing correctly (so the button input is clearly being read at some point).
When I try to take the GPIO reading code outside of the #ifdef block, I receive a compiler error indicating that the HAL_GPIO_PIN_SAFETY_IN is out of scope.
Could you clarify if there’s a specific condition or configuration I might be missing for the GPIO reading to trigger inside that block? Or is there an alternate method to access the safety GPIO pin without running into the scope issue?
I’d appreciate any additional guidance on how to properly integrate this GPIO reading for the button in my setup.
And update to latest stable. There is no reason to start a project in 2025 using a branch that is years old and hundreds (if not thousands) of commits behind.
Hey Yuri, I appreciate your response, but that’s not quite what I’m looking for. I’m not interested in the safety state itself, which is handled by the _safety_switch_state() function. My focus is on where and how the actual button circuit is sampled — I want to understand the code that directly interacts with the hardware level of the button’s GPIO, not just the state after it’s read.
The link to the safety button code you provided is relevant for handling the state, but it doesn’t address the core issue, which is reading the electrical input from the button circuit in the first place.
And just to clarify, there’s no substantial difference in how the safety button is handled in the current stable version compared to older ones, so upgrading the code for this particular case isn’t going to help. I just need to find the part of the source code where the button’s input is sampled and processed directly, which seems to be what’s missing here.
I gave you the relevant code as a tool to get your answer and specifically said to trace the logic behind it. Search for that method’s implementation in your code editor or using GitHub search.
Just because that method may not have changed isn’t an excuse to use a very outdated version.
Hey yuri, I think i found it.
it is inside ardupilot/libraries/AP_IOMCU/iofirmware/iofirmware.cpp
this is the code under the function safety_update:
bool safety_pressed = palReadLine(HAL_GPIO_PIN_SAFETY_INPUT);
if (safety_pressed)
{
gcs().send_text(MAV_SEVERITY_CRITICAL, " Hola comosta Safety");
if (reg_status.flag_safety_off && (reg_setup.arming & P_SETUP_ARMING_SAFETY_DISABLE_ON))
{
safety_pressed = false;
}
else if ((!reg_status.flag_safety_off) && (reg_setup.arming & P_SETUP_ARMING_SAFETY_DISABLE_OFF))
{
safety_pressed = false;
}
}
if (safety_pressed)
{
safety_button_counter++;
}
else
{
safety_button_counter = 0;
}
if (safety_button_counter == 10)
{
// safety has been pressed for 1 second, change state
reg_status.flag_safety_off = !reg_status.flag_safety_off;
if (reg_status.flag_safety_off)
{
hal.rcout->force_safety_off();
}
else
{
hal.rcout->force_safety_on();
}
}
// update the armed state
hal.util->set_soft_armed((reg_setup.arming & P_SETUP_ARMING_FMU_ARMED) != 0);
but when I compile+ upload it the regular way - > ./waf copter --upload --upload-port=/dev/ttyACM0
it doesn’t compile i guess it because the copter and firmware are separates
could you please help with the right command ?
I dont need a force flash i need a way to compile and build like as you do with the copter
./waf copter --upload --upload-port=/dev/ttyACM0
bur for the iofirmware beacuse i made some modification to the code