diff --git a/Makefile b/Makefile index 106da718..dabe04c9 100644 --- a/Makefile +++ b/Makefile @@ -37,6 +37,13 @@ LDFLAGS += -nostartfiles -nodefaultlibs ${CFLAGS} -lgcc CFLAGS += -ffunction-sections -fdata-sections -Wno-attributes LDFLAGS += -Wl,--gc-sections -Wl,--build-id=sha1 +ifdef BTS +BUILD_TIMESTAMP := $(shell date "+%Y-%m-%d %H:%M:%S") +CFLAGS += -DMIOS_BUILD_TIMESTAMP="\"${BUILD_TIMESTAMP}\"" +# Make sure the version.c gets recompiled for new timestamp +.PHONY: ${SRC}/version.c +endif + # Needed for linker script includes LDFLAGS += -L${SRC} diff --git a/src/platform/stm32h7/stm32h7_eth.c b/src/platform/stm32h7/stm32h7_eth.c index 08534439..64400a3b 100644 --- a/src/platform/stm32h7/stm32h7_eth.c +++ b/src/platform/stm32h7/stm32h7_eth.c @@ -674,9 +674,9 @@ stm32h7_eth_init(gpio_t phyrst, const uint8_t *gpios, size_t gpio_count, gpio_conf_output(phyrst, GPIO_PUSH_PULL, GPIO_SPEED_LOW, GPIO_PULL_NONE); gpio_set_output(phyrst, 0); - udelay(10); + udelay(50); gpio_set_output(phyrst, 1); - udelay(10); + udelay(4000); } clk_enable(CLK_ETH1MACEN); diff --git a/src/platform/stm32h7/stm32h7_i2c.c b/src/platform/stm32h7/stm32h7_i2c.c index 5db5e1cb..b7c33f10 100644 --- a/src/platform/stm32h7/stm32h7_i2c.c +++ b/src/platform/stm32h7/stm32h7_i2c.c @@ -55,8 +55,7 @@ void irq_96(void) { i2c_irq(g_i2c[3]); } i2c_t * -stm32h7_i2c_create(unsigned int instance, gpio_t scl, gpio_t sda, - gpio_pull_t pull, int scl_freq) +stm32h7_i2c_create_unit(unsigned int instance, int scl_freq) { instance--; if(instance > ARRAYSIZE(i2c_configs)) @@ -74,9 +73,6 @@ stm32h7_i2c_create(unsigned int instance, gpio_t scl, gpio_t sda, panic("i2c-%d: Unsupported timing", instance + 1); } - gpio_conf_af(scl, 4, GPIO_OPEN_DRAIN, GPIO_SPEED_HIGH, pull); - gpio_conf_af(sda, 4, GPIO_OPEN_DRAIN, GPIO_SPEED_HIGH, pull); - clk_enable(c->clk_id); stm32_i2c_t *d = stm32_i2c_create(c->base_addr); diff --git a/src/platform/stm32h7/stm32h7_i2c.h b/src/platform/stm32h7/stm32h7_i2c.h index 5cdafe20..54300b69 100644 --- a/src/platform/stm32h7/stm32h7_i2c.h +++ b/src/platform/stm32h7/stm32h7_i2c.h @@ -2,5 +2,59 @@ #include -i2c_t *stm32h7_i2c_create(unsigned int instance, gpio_t scl, gpio_t sda, - gpio_pull_t pull, int scl_freq); +i2c_t *stm32h7_i2c_create_unit(unsigned int instance, int scl_freq); + +extern int stm32h7_i2c_invalid_af_for_pin; // never defined — link error on bad pin + +static inline int __attribute__((always_inline)) +stm32h7_i2c_pin_af(unsigned int instance, gpio_t pin) +{ + switch(instance) { + case 1: + switch(pin) { + case GPIO_PB(5): case GPIO_PB(6): case GPIO_PB(7): + case GPIO_PB(8): case GPIO_PB(9): + return 4; + } + break; + case 2: + switch(pin) { + case GPIO_PB(10): case GPIO_PB(11): case GPIO_PB(12): + case GPIO_PF(0): case GPIO_PF(1): + case GPIO_PH(4): case GPIO_PH(5): + return 4; + } + break; + case 3: + switch(pin) { + case GPIO_PA(8): + case GPIO_PC(9): + case GPIO_PH(7): case GPIO_PH(8): + return 4; + } + break; + case 4: + switch(pin) { + case GPIO_PB(6): case GPIO_PB(7): + case GPIO_PB(8): case GPIO_PB(9): + return 6; + case GPIO_PD(12): case GPIO_PD(13): + case GPIO_PF(14): case GPIO_PF(15): + case GPIO_PH(11): case GPIO_PH(12): + return 4; + } + break; + } + return stm32h7_i2c_invalid_af_for_pin; +} + +static inline i2c_t * __attribute__((always_inline)) +stm32h7_i2c_create(unsigned int instance, gpio_t scl, gpio_t sda, + gpio_pull_t pull, int scl_freq) +{ + gpio_conf_af(scl, stm32h7_i2c_pin_af(instance, scl), + GPIO_OPEN_DRAIN, GPIO_SPEED_HIGH, pull); + gpio_conf_af(sda, stm32h7_i2c_pin_af(instance, sda), + GPIO_OPEN_DRAIN, GPIO_SPEED_HIGH, pull); + return stm32h7_i2c_create_unit(instance, scl_freq); +} diff --git a/src/version.c b/src/version.c index 42188e10..4a1cc87e 100644 --- a/src/version.c +++ b/src/version.c @@ -70,6 +70,9 @@ mios_print_version(stream_t *s) stprintf(s, "Mios version:"); stprintversion(s, _miosversion); +#ifdef MIOS_BUILD_TIMESTAMP + stprintf(s, "Build time: %s\n", MIOS_BUILD_TIMESTAMP); +#endif stprintf(s, "BuildID: "); sthexstr(s, mios_build_id(), 20);