Files
proxmark3/common_arm/gpio/gpio_hw_at91.c
T
iceman1001andClaude Opus 5 (1M context) 708d400c57 gpio: let an AT91 board without an FPGA power switch build
PLATFORM=PM3ICOPYX has not compiled at all -- it dies on obj/start.o,
before anything else is built:

    common_arm/gpio/gpio_hw_at91.h:77: error: 'GPIO_FPGA_ON' undeclared
        (first use in this function); did you mean 'GPIO_FPGA_DONE'?

PA26 has two different jobs depending on the FPGA, per
config_gpio_proxmark3.h:

    #if defined XC3
    #define GPIO_FPGA_SWITCH    AT91C_PIO_PA26
    #else
    #define GPIO_FPGA_ON        AT91C_PIO_PA26
    #endif

ICopyX has no FPGA power rail to switch; that pin selects the FPGA
instead. But Gpio_FPGA_ON_High(), Gpio_FPGA_ON_Low() and
gpio_fpga_on_setup() all referenced GPIO_FPGA_ON unconditionally, so the
symbol simply does not exist on XC3.

'This board has no FPGA power switch' is already a supported case: the
AT32 port stubs both accessors with a bare '// Unsupported' comment, and
PM5 depends on that, while Gpio_FPGA_SWITCH_High()/Low() two functions
further down in this same header are guarded with #ifdef for the mirror
case. The AT91 header just never grew the XC3 arm. All three now carry
the same guard.

fpga_loader.c calls Gpio_FPGA_ON_High() from shared code; on ICopyX that
compiles to nothing, which is correct -- the rail is always on.

Verified: fullimage builds for PM3ICOPYX (356832 bytes, with
PLATFORM_EXTRAS=FLASH), and for PM3RDV4, PM3GENERIC, PM3ULTIMATE and
PM5. For the boards that do have the pin the guard costs nothing -- the
.text section is byte-identical before and after, 289464 bytes on
PM3RDV4 and 243584 on PM3GENERIC; only the embedded build timestamp and
source hash move in the full ELF.

Co-Authored-By: Claude Opus 5 (1M context)
2026-09-14 18:20:35 +02:00

160 lines
4.8 KiB
C

#include "gpio_apis.h"
#include "at91sam7s512.h"
#include "config_gpio.h"
void gpio_button_setup(void) {
AT91C_BASE_PIOA->PIO_PER = GPIO_BUTTON;
AT91C_BASE_PIOA->PIO_ODR = GPIO_BUTTON;
}
void gpio_leds_setup(void) {
AT91C_BASE_PIOA->PIO_PER = AT91C_BASE_PIOA->PIO_OER = // Chained assignment
GPIO_LED_A |
GPIO_LED_B |
GPIO_LED_C |
GPIO_LED_D;
}
void gpio_arm_power_on_setup(void) {
// Currently, there are no devices with AT91 as the core that support power control.
}
void gpio_inter_usb_spi_role_setup(void) {
// Unsupported
}
void gpio_sw_i2c_rst_setup(void) {
// Configure reset pin, close up pull, push-pull output, default high
AT91C_BASE_PIOA->PIO_PPUDR = GPIO_I2C_RST;
AT91C_BASE_PIOA->PIO_MDDR = GPIO_I2C_RST;
// Configure I2C pin, open up, open leakage
AT91C_BASE_PIOA->PIO_PPUER |= (GPIO_I2C_SCL | GPIO_I2C_SDA);
AT91C_BASE_PIOA->PIO_MDER |= (GPIO_I2C_SCL | GPIO_I2C_SDA);
// default three lines all pull up
AT91C_BASE_PIOA->PIO_SODR |= (GPIO_I2C_SCL | GPIO_I2C_SDA | GPIO_I2C_RST);
AT91C_BASE_PIOA->PIO_OER |= (GPIO_I2C_SCL | GPIO_I2C_SDA | GPIO_I2C_RST);
AT91C_BASE_PIOA->PIO_PER |= (GPIO_I2C_SCL | GPIO_I2C_SDA | GPIO_I2C_RST);
}
void gpio_fpga_switch_setup(void) {
#ifdef GPIO_FPGA_SWITCH
AT91C_BASE_PIOA->PIO_PER = GPIO_FPGA_SWITCH;
AT91C_BASE_PIOA->PIO_OER = GPIO_FPGA_SWITCH;
#endif
}
void gpio_adc_mux_setup(void) {
AT91C_BASE_PIOA->PIO_PER = AT91C_BASE_PIOA->PIO_OER = // Chained assignment
GPIO_MUXSEL_HIPKD |
#ifndef WITH_FPC_USART // FPC USART uses HIRAW/LOWRAW pins, so they are excluded here.
GPIO_MUXSEL_LORAW |
GPIO_MUXSEL_HIRAW |
#endif
GPIO_MUXSEL_LOPKD;
}
void gpio_fpga_download_setup(void) {
/**
* ICopyx(XC3S100E) reuse M1 & M2(M2,M3) pin for spi communication.
* When M2 & M3 is high before enter configuration, The mode 'Slave Serial (M[2:0] = 110)' selected.
* It is also to reuse the download code of xc2s30.
* Therefore, after the configuration mode is selected, these two PINs will free, so they can be reused as SPI communication ports.
* See docs at Table 44: Spartan-3E Configuration Mode Options and Pin Settings
*/
// PIO controls the following pins for 'Slave Serial', need disable peripheral functions.
AT91C_BASE_PIOA->PIO_PER =
GPIO_FPGA_NINIT |
GPIO_FPGA_DONE |
#if defined XC3
// ICopyX(3S100E) M2 & M3 PIO ENA
GPIO_SPCK |
GPIO_MOSI |
#endif
GPIO_FPGA_NPROGRAM |
GPIO_FPGA_CCLK |
GPIO_FPGA_DIN;
// These pins are inputs
AT91C_BASE_PIOA->PIO_ODR = GPIO_FPGA_NINIT | GPIO_FPGA_DONE;
AT91C_BASE_PIOA->PIO_PPUER = GPIO_FPGA_NINIT | GPIO_FPGA_DONE; // Enable pull-ups
// These pins are outputs
AT91C_BASE_PIOA->PIO_OER =
GPIO_FPGA_NPROGRAM |
GPIO_FPGA_CCLK |
#if defined XC3
// ICopyX(3S100E) M2 & M3 OUTPUT ENA
GPIO_SPCK |
GPIO_MOSI |
#endif
GPIO_FPGA_DIN;
}
void gpio_fpga_on_setup(void) {
#ifdef GPIO_FPGA_ON
AT91C_BASE_PIOA->PIO_OER = GPIO_FPGA_ON;
AT91C_BASE_PIOA->PIO_PER = GPIO_FPGA_ON;
#endif
}
void gpio_fpga_mod_feedback_setup(void) {
AT91C_BASE_PIOA->PIO_PER = GPIO_SSC_DOUT | GPIO_SSC_CLK;
AT91C_BASE_PIOA->PIO_OER = GPIO_SSC_DOUT;
AT91C_BASE_PIOA->PIO_ODR = GPIO_SSC_CLK;
}
void gpio_fpga_mod_only_setup(void) {
AT91C_BASE_PIOA->PIO_PER = GPIO_SSC_DOUT;
AT91C_BASE_PIOA->PIO_OER = GPIO_SSC_DOUT;
}
void gpio_sysboot_setup(void) {
// Kill all the pullups, especially the one on USB D+; leave them for
// the unused pins, though.
AT91C_BASE_PIOA->PIO_PPUDR =
GPIO_USB_PU |
GPIO_LED_A |
GPIO_LED_B |
GPIO_LED_C |
GPIO_LED_D |
GPIO_FPGA_DIN |
GPIO_FPGA_DOUT |
GPIO_FPGA_CCLK |
GPIO_FPGA_NINIT |
GPIO_FPGA_NPROGRAM |
GPIO_FPGA_DONE |
GPIO_MUXSEL_HIPKD |
GPIO_MUXSEL_HIRAW |
GPIO_MUXSEL_LOPKD |
GPIO_MUXSEL_LORAW |
GPIO_RELAY |
GPIO_NVDD_ON;
// (and add GPIO_FPGA_ON)
// These pins are outputs
AT91C_BASE_PIOA->PIO_OER =
GPIO_LED_A |
GPIO_LED_B |
GPIO_LED_C |
GPIO_LED_D |
GPIO_RELAY |
GPIO_NVDD_ON;
// PIO controls the following pins
AT91C_BASE_PIOA->PIO_PER =
GPIO_USB_PU |
GPIO_LED_A |
GPIO_LED_B |
GPIO_LED_C |
GPIO_LED_D;
gpio_button_setup();
}
void gpio_vusb_setup(void) {
// Unsupported!
}