sam4e8e: Fix bug in sam4e gpio.c (#563)

The bank_id was calculated erroneously. Also unify gpio_in_setup and gpio_out_setup a bit. Also disable make flash for the sam4e8e port as it currently references a version of bossac that is not present on all systems.

Signed-off-by: Florian Heilmann <Florian.Heilmann@gmx.net>
This commit is contained in:
Florian Heilmann 2018-08-24 19:17:53 +02:00 committed by KevinOConnor
parent a8a912fbb5
commit b065f51454
2 changed files with 14 additions and 5 deletions

View File

@ -33,5 +33,5 @@ $(OUT)klipper.bin: $(OUT)klipper.elf
$(Q)$(OBJCOPY) -O binary $< $@ $(Q)$(OBJCOPY) -O binary $< $@
flash: $(OUT)klipper.bin flash: $(OUT)klipper.bin
@echo " Flashing $^ to $(FLASH_DEVICE) via bossac" @echo ""
$(Q)tools/bossa/bin/bossac --port="$(FLASH_DEVICE)" -b -U -e -w -v $(OUT)klipper.bin -R @echo " The SAM4E8E build does not currently support 'make flash'"

View File

@ -72,9 +72,10 @@ gpio_out_setup(uint8_t pin, uint8_t val)
{ {
if (GPIO2PORT(pin) >= ARRAY_SIZE(digital_regs)) if (GPIO2PORT(pin) >= ARRAY_SIZE(digital_regs))
goto fail; goto fail;
Pio *regs = digital_regs[GPIO2PORT(pin)]; uint32_t port = GPIO2PORT(pin);
Pio *regs = digital_regs[port];
uint32_t bit = GPIO2BIT(pin); uint32_t bit = GPIO2BIT(pin);
uint32_t bank_id = ID_PIOA + GPIO2BIT(pin); uint32_t bank_id = ID_PIOA + port;
irqstatus_t flag = irq_save(); irqstatus_t flag = irq_save();
@ -129,15 +130,23 @@ gpio_in_setup(uint8_t pin, int8_t pull_up)
uint32_t port = GPIO2PORT(pin); uint32_t port = GPIO2PORT(pin);
Pio *regs = digital_regs[port]; Pio *regs = digital_regs[port];
uint32_t bit = GPIO2BIT(pin); uint32_t bit = GPIO2BIT(pin);
uint32_t bank_id = ID_PIOA + port;
regs->PIO_IDR = bit; regs->PIO_IDR = bit;
irqstatus_t flag = irq_save(); irqstatus_t flag = irq_save();
PMC->PMC_PCER0 = 1 << (ID_PIOA + port);
if ((PMC->PMC_PCSR0 & (1u << bank_id)) == 0) {
PMC->PMC_PCER0 = 1 << bank_id;
}
if (pull_up) if (pull_up)
regs->PIO_PUER = bit; regs->PIO_PUER = bit;
else else
regs->PIO_PUDR = bit; regs->PIO_PUDR = bit;
regs->PIO_ODR = bit; regs->PIO_ODR = bit;
regs->PIO_PER = bit; regs->PIO_PER = bit;
irq_restore(flag); irq_restore(flag);
return (struct gpio_in){ .pin=pin, .regs=regs, .bit=bit }; return (struct gpio_in){ .pin=pin, .regs=regs, .bit=bit };
fail: fail: