diff --git a/stm-firmware/Makefile b/stm-firmware/Makefile index 897eea4..9f7c2c3 100644 --- a/stm-firmware/Makefile +++ b/stm-firmware/Makefile @@ -48,7 +48,7 @@ CFILES += pid-controller.c oven-driver.c CFILES += settings/settings.c settings/settings-sd-card.c CFILES += stm-periph/crc-unit.c CFILES += safety/safety-adc.c safety/safety-controller.c safety/watchdog.c safety/fault.c safety/safety-memory.c safety/stack-check.c - +CFILES += hw-version-detect.c CFILES += config-parser/config-parser.c INCLUDEPATH += -Iconfig-parser/include diff --git a/stm-firmware/hw-version-detect.c b/stm-firmware/hw-version-detect.c new file mode 100644 index 0000000..3cbbf28 --- /dev/null +++ b/stm-firmware/hw-version-detect.c @@ -0,0 +1,48 @@ +#include +#include +#include + +#define HW_REV_DETECT_GPIO GPIOE +#define HW_REV_DETECT_RCC_FIELD RCC_AHB1ENR_GPIOEEN +#define HW_REV_DETECT_PIN_LOW (8U) +#define HW_REV_DETECT_PIN_HIGH (15U) + +enum hw_revision get_pcb_hardware_version(void) +{ + uint8_t current_pin; + uint16_t port_bitmask = 0U; + static enum hw_revision revision = HW_REV_NOT_DETECTED; + + if (revision != HW_REV_NOT_DETECTED) + return revision; + + rcc_manager_enable_clock(&RCC->AHB1ENR, BITMASK_TO_BITNO(HW_REV_DETECT_RCC_FIELD)); + + /* Setup the pins as input with pull up */ + for (current_pin = HW_REV_DETECT_PIN_LOW; current_pin <= HW_REV_DETECT_PIN_HIGH; current_pin++) { + HW_REV_DETECT_GPIO->MODER &= MODER_DELETE(current_pin); + HW_REV_DETECT_GPIO->PUPDR &= PUPDR_DELETE(current_pin); + HW_REV_DETECT_GPIO->PUPDR |= PULLUP(current_pin); + } + + /* Loop again and read in the pin mask */ + for (current_pin = HW_REV_DETECT_PIN_LOW; current_pin <= HW_REV_DETECT_PIN_HIGH; current_pin++) { + port_bitmask <<= 1; + port_bitmask |= (HW_REV_DETECT_GPIO->IDR & (1 << current_pin)) ? 0x0 : 0x1; + } + + switch (port_bitmask) { + case 0U: + revision = HW_REV_V1_2; + break; + case 1U: + revision = HW_REV_V1_3; + break; + default: + revision = HW_REV_ERROR; + } + + rcc_manager_disable_clock(&RCC->AHB1ENR, BITMASK_TO_BITNO(HW_REV_DETECT_RCC_FIELD)); + + return revision; +} diff --git a/stm-firmware/shell.c b/stm-firmware/shell.c index b10f878..2640aef 100644 --- a/stm-firmware/shell.c +++ b/stm-firmware/shell.c @@ -40,6 +40,7 @@ #include #include #include +#include #ifndef GIT_VER #define GIT_VER "VERSION NOT SET" @@ -81,12 +82,28 @@ static shellmatta_retCode_t shell_cmd_ver(const shellmatta_handle_t handle, uint32_t low_id; uint32_t mid_id; uint32_t high_id; + const char *hw_rev_str; + enum hw_revision pcb_rev; unique_id_get(&high_id, &mid_id, &low_id); shellmatta_printf(handle, "Reflow Oven Controller Firmware " xstr(GIT_VER) "\r\n" "Compiled: " __DATE__ " at " __TIME__ "\r\n"); - shellmatta_printf(handle, "Serial: %08X-%08X-%08X", high_id, mid_id, low_id); + shellmatta_printf(handle, "Serial: %08X-%08X-%08X\r\n", high_id, mid_id, low_id); + + pcb_rev = get_pcb_hardware_version(); + switch (pcb_rev) { + case HW_REV_V1_2: + hw_rev_str = "Hardware: v1.2"; + break; + case HW_REV_V1_3: + hw_rev_str = "Hardware: v1.3"; + break; + default: + hw_rev_str = "Hardware: Unknown Revision. You might have to update the firmware!"; + break; + } + shellmatta_printf(handle, "%s", hw_rev_str); return SHELLMATTA_OK; }