Skip to content

Commit

Permalink
f415: fixed GPIO for bootloader
Browse files Browse the repository at this point in the history
bl now works!
  • Loading branch information
tridge committed Aug 7, 2024
1 parent bdd4de0 commit 258157a
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions Mcu/f415/Inc/blutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,26 @@

static inline void gpio_mode_set_input(uint32_t pin, uint32_t pull_up_down)
{
if (pin < 8) {
if (pin < GPIO_PIN(8)) {
const uint32_t pin4 = (pin*pin*pin*pin);
input_port->cfglr = (input_port->cfglr & ~(pin4*0xfU)) | (pin4*(GPIO_MODE_INPUT | pull_up_down));
input_port->cfglr = (input_port->cfglr & ~(pin4*0xfU)) | (pin4*pull_up_down);
} else {
pin = (pin-8);
pin >>= 8U;
const uint32_t pin4 = (pin*pin*pin*pin);
input_port->cfghr = (input_port->cfglr & ~(pin4*0xfU)) | (pin4*(GPIO_MODE_INPUT | pull_up_down));
input_port->cfghr = (input_port->cfglr & ~(pin4*0xfU)) | (pin4*pull_up_down);
}
}

static inline void gpio_mode_set_output(uint32_t pin, uint32_t output_mode)
{
if (pin < 8) {
const uint32_t output_normal_strength = 2U;
if (pin < GPIO_PIN(8)) {
const uint32_t pin4 = (pin*pin*pin*pin);
input_port->cfglr = (input_port->cfglr & ~(pin4*0xfU)) | (pin4*(GPIO_MODE_OUTPUT | output_mode));
input_port->cfglr = (input_port->cfglr & ~(pin4*0xfU)) | (pin4*(output_normal_strength | output_mode));
} else {
pin = (pin-8);
pin >>= 8U;
const uint32_t pin4 = (pin*pin*pin*pin);
input_port->cfghr = (input_port->cfghr & ~(pin4*0xfU)) | (pin4*(GPIO_MODE_OUTPUT | output_mode));
input_port->cfghr = (input_port->cfghr & ~(pin4*0xfU)) | (pin4*(output_normal_strength | output_mode));
}
}

Expand Down Expand Up @@ -156,6 +157,7 @@ static inline void bl_clock_config(void)

static inline void bl_gpio_init(void)
{
crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE);
crm_periph_clock_enable(CRM_GPIOB_PERIPH_CLOCK, TRUE);
crm_periph_clock_enable(CRM_IOMUX_PERIPH_CLOCK , TRUE);
gpio_pin_remap_config(SWJTAG_GMUX_010, TRUE); // pb4 GPIO
Expand Down

0 comments on commit 258157a

Please sign in to comment.