diff --git a/shared/common.h b/shared/common.h index bd0f77bc..ac133707 100644 --- a/shared/common.h +++ b/shared/common.h @@ -68,7 +68,7 @@ typedef struct { union { struct { uint8_t buf; - uint8_t enable : 1; + uint32_t enable : 1; enum packet_to_hv_cmd_type_t { VOLT_MODE = 0, CURRENT_MODE, @@ -80,6 +80,7 @@ typedef struct { PHASE_180_2PH, PHASE_180_3PH, } phase_type : 3; + uint32_t ignore_fault_pin : 1; } flags; uint32_t padding; }; diff --git a/shared/f3hw.h b/shared/f3hw.h index 62350dc3..72340bcb 100644 --- a/shared/f3hw.h +++ b/shared/f3hw.h @@ -3,9 +3,9 @@ #define HV_EN_PIN GPIO_PIN_15 #define HV_EN_PORT GPIOA //fault pin cannot be used, as it is sometimes reset by the iram due to 15v ripple -//#define HV_FAULT_PIN GPIO_PIN_7 -//#define HV_FAULT_PORT GPIOB -//#define HV_FAULT_POLARITY GPIO_PIN_RESET +#define HV_FAULT_PIN GPIO_PIN_7 +#define HV_FAULT_PORT GPIOB +#define HV_FAULT_POLARITY GPIO_PIN_RESET #define LED_PIN GPIO_PIN_8 #define LED_PORT GPIOA diff --git a/src/comps/hv.c b/src/comps/hv.c index d58be777..9b7393a3 100644 --- a/src/comps/hv.c +++ b/src/comps/hv.c @@ -43,6 +43,7 @@ HAL_PIN(hv_temp); HAL_PIN(mot_temp); HAL_PIN(core_temp); HAL_PIN(fault); //fault from hv +HAL_PIN(ignore_fault_pin); HAL_PIN(y); HAL_PIN(u_fb); HAL_PIN(v_fb); @@ -366,6 +367,7 @@ static void frt_func(float period, volatile void *ctx_ptr, volatile hal_pin_inst ctx->to_hv.packet_to_hv.q_cmd = 0.0; ctx->to_hv.packet_to_hv.flags.enable = 0; } + ctx->to_hv.packet_to_hv.flags.ignore_fault_pin = PIN(ignore_fault_pin) > 0.0; ctx->to_hv.packet_to_hv.flags.cmd_type = PIN(cmd_mode); ctx->to_hv.packet_to_hv.flags.phase_type = PIN(phase_mode); ctx->to_hv.packet_to_hv.pos = pos; @@ -485,7 +487,9 @@ static void frt_func(float period, volatile void *ctx_ptr, volatile hal_pin_inst } if(ctx->send_state > 1){ - tx_size = 0; + if(flash_state != SLAVE_IN_APP){ + tx_size = 0; + } ctx->send_state = 0; } ctx->send_state++; @@ -534,7 +538,7 @@ static void nrt_func(volatile void *ctx_ptr, volatile hal_pin_inst_t *pin_ptr) { printf("hv_update: status: %i%%\n", (int)(100.0 * ctx->addr * 4. / (float)((uint32_t) & (_binary_obj_hvf3_hvf3_bin_size)))); last_addr = ctx->addr; } - + if(last_flash_state != flash_state) { switch(flash_state) { case SLAVE_IN_APP: diff --git a/stm32f303/src/comps/io.c b/stm32f303/src/comps/io.c index 63de3fd6..4988f640 100644 --- a/stm32f303/src/comps/io.c +++ b/stm32f303/src/comps/io.c @@ -48,6 +48,8 @@ HAL_PIN(hv_en); //fault output HAL_PIN(fault); +HAL_PIN(ignore_fault_pin); + volatile uint32_t adc_12_buf[6]; @@ -103,7 +105,7 @@ float r2temp(float r) { return (-(r - b) / (a - b) * step + i * step + start); } } - return (temp[ARRAY_SIZE(temp)] + step); // TODO fix + return (temp[ARRAY_SIZE(temp) - 1] + step); // TODO fix } static void nrt_init(volatile void *ctx_ptr, volatile hal_pin_inst_t *pin_ptr) { @@ -241,8 +243,8 @@ static void rt_func(float period, volatile void *ctx_ptr, volatile hal_pin_inst_ if(ctx->fault == NO_ERROR) { #ifdef HV_FAULT_PIN //read fault pin from driver - if(err_filter(&(ctx->fault_pin_error), 5.0, 0.01, HAL_GPIO_ReadPin(HV_FAULT_PORT, HV_FAULT_PIN) == HV_FAULT_POLARITY)) { - ctx->fault = HV_HV_FAULT; + if(PIN(ignore_fault_pin) <= 0.0 && err_filter(&(ctx->fault_pin_error), 5.0, 0.01, HAL_GPIO_ReadPin(HV_FAULT_PORT, HV_FAULT_PIN) == HV_FAULT_POLARITY)) { + ctx->fault = HV_FAULT_ERROR; } #endif //Master out enable is cleared by timer break input. diff --git a/stm32f303/src/comps/ls.c b/stm32f303/src/comps/ls.c index 598ed3fa..b5beae6f 100644 --- a/stm32f303/src/comps/ls.c +++ b/stm32f303/src/comps/ls.c @@ -43,6 +43,7 @@ HAL_PIN(hv_temp); HAL_PIN(mot_temp); HAL_PIN(core_temp); HAL_PIN(fault_in); //fault code send to f4 +HAL_PIN(ignore_fault_pin); HAL_PIN(y); HAL_PIN(u_fb); HAL_PIN(v_fb); @@ -214,6 +215,7 @@ static void rt_func(float period, volatile void *ctx_ptr, volatile hal_pin_inst_ PIN(en) = ctx->packet_to_hv.flags.enable; PIN(phase_mode) = ctx->packet_to_hv.flags.phase_type; PIN(cmd_mode) = ctx->packet_to_hv.flags.cmd_type; + PIN(ignore_fault_pin) = ctx->packet_to_hv.flags.ignore_fault_pin; PIN(d_cmd) = ctx->packet_to_hv.d_cmd; PIN(q_cmd) = ctx->packet_to_hv.q_cmd; PIN(pos) = ctx->packet_to_hv.pos; diff --git a/stm32f303/src/main.c b/stm32f303/src/main.c index a990d316..45308d7a 100644 --- a/stm32f303/src/main.c +++ b/stm32f303/src/main.c @@ -352,6 +352,7 @@ int main(void) { hal_parse("curpid0.en = ls0.en"); hal_parse("curpid0.cmd_mode = ls0.cmd_mode"); hal_parse("hv0.arr = ls0.arr"); + hal_parse("io0.ignore_fault_pin = ls0.ignore_fault_pin"); hal_parse("debug_level 0"); // hal parse config