Skip to content

Commit dd5b538

Browse files
committed
Initial bms HIL test mode implementation
1 parent 8390dc0 commit dd5b538

10 files changed

Lines changed: 129 additions & 14 deletions

File tree

Core/Inc/bms_config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
#define DEBUG_MODE_ENABLED true
55
#define DEBUG_STATS
66

7+
#ifndef HIL_TEST_MODE_ENABLED
8+
#define HIL_TEST_MODE_ENABLED true
9+
#endif // HIL_TEST_MODE_ENABLED
10+
711
// Hardware definition
812
#define NUM_SEGMENTS 5
913
#define NUM_CHIPS_PER_SEGMENT 2

Core/Src/adi6830_interaction.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,10 @@ void read_adbms_data(cell_asic chips[NUM_CHIPS], uint8_t command[2], TYPE type,
313313
uint32_t adBmsPollAdc_indicator(cell_asic chips[NUM_CHIPS],
314314
uint8_t poll_type[2])
315315
{
316-
uint32_t result = adBmsPollAdc6830(NUM_CHIPS, chips, poll_type);
316+
uint32_t result = 0U;
317+
#if (HIL_TEST_MODE_ENABLED == false)
318+
result = adBmsPollAdc6830(NUM_CHIPS, chips, poll_type);
319+
#endif // HIL_TEST_MODE_ENABLED
317320
return result;
318321
}
319322

Core/Src/analyzer.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ void vAnalyzer(ULONG thread_input)
425425

426426
mutex_put(&analyzer_mutex);
427427

428+
set_flag(SANITIZER_FLAG);
428429
set_flag(DEBUG_FLAG);
429430

430431
// send out telemetry data sourced from the above functions

Core/Src/cell_temp_sanitizer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ void vSanitizer(ULONG thread_input)
119119
temp_sanitizer_init(sanitizer);
120120

121121
for (;;) {
122+
get_flag(SANITIZER_FLAG, TX_WAIT_FOREVER);
122123
temp_sanitizer_run(sanitizer, analyzer);
123-
tx_thread_sleep(MS_TO_TICKS(500));
124124
}
125125
}
126126

Core/Src/main.c

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ IWDG_HandleTypeDef hiwdg;
6060

6161
UART_HandleTypeDef hlpuart1;
6262
UART_HandleTypeDef huart4;
63+
UART_HandleTypeDef huart9;
6364
DMA_HandleTypeDef handle_GPDMA1_Channel4;
6465

6566
SPI_HandleTypeDef hspi1;
@@ -105,6 +106,7 @@ static void MX_TIM2_Init(void);
105106
static void MX_TIM4_Init(void);
106107
static void MX_TIM6_Init(void);
107108
static void MX_IWDG_Init(void);
109+
static void MX_UART9_Init(void);
108110
/* USER CODE BEGIN PFP */
109111

110112
/* USER CODE END PFP */
@@ -191,6 +193,7 @@ int main(void)
191193
MX_TIM4_Init();
192194
MX_TIM6_Init();
193195
MX_IWDG_Init();
196+
MX_UART9_Init();
194197
/* USER CODE BEGIN 2 */
195198
init_can1(&hfdcan2);
196199
/* USER CODE END 2 */
@@ -668,6 +671,54 @@ static void MX_UART4_Init(void)
668671

669672
}
670673

674+
/**
675+
* @brief UART9 Initialization Function
676+
* @param None
677+
* @retval None
678+
*/
679+
static void MX_UART9_Init(void)
680+
{
681+
682+
/* USER CODE BEGIN UART9_Init 0 */
683+
684+
/* USER CODE END UART9_Init 0 */
685+
686+
/* USER CODE BEGIN UART9_Init 1 */
687+
688+
/* USER CODE END UART9_Init 1 */
689+
huart9.Instance = UART9;
690+
huart9.Init.BaudRate = 115200;
691+
huart9.Init.WordLength = UART_WORDLENGTH_8B;
692+
huart9.Init.StopBits = UART_STOPBITS_1;
693+
huart9.Init.Parity = UART_PARITY_NONE;
694+
huart9.Init.Mode = UART_MODE_TX_RX;
695+
huart9.Init.HwFlowCtl = UART_HWCONTROL_NONE;
696+
huart9.Init.OverSampling = UART_OVERSAMPLING_16;
697+
huart9.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
698+
huart9.Init.ClockPrescaler = UART_PRESCALER_DIV1;
699+
huart9.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
700+
if (HAL_UART_Init(&huart9) != HAL_OK)
701+
{
702+
Error_Handler();
703+
}
704+
if (HAL_UARTEx_SetTxFifoThreshold(&huart9, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
705+
{
706+
Error_Handler();
707+
}
708+
if (HAL_UARTEx_SetRxFifoThreshold(&huart9, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
709+
{
710+
Error_Handler();
711+
}
712+
if (HAL_UARTEx_DisableFifoMode(&huart9) != HAL_OK)
713+
{
714+
Error_Handler();
715+
}
716+
/* USER CODE BEGIN UART9_Init 2 */
717+
718+
/* USER CODE END UART9_Init 2 */
719+
720+
}
721+
671722
/**
672723
* @brief SPI1 Initialization Function
673724
* @param None
@@ -1224,8 +1275,8 @@ static void MX_GPIO_Init(void)
12241275
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
12251276
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
12261277

1227-
/*Configure GPIO pins : PD13 PD14 PD15 */
1228-
GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
1278+
/*Configure GPIO pin : PD13 */
1279+
GPIO_InitStruct.Pin = GPIO_PIN_13;
12291280
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
12301281
GPIO_InitStruct.Pull = GPIO_NOPULL;
12311282
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

Core/Src/segment.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,9 @@ void segment_retrieve_charging_data(cell_asic chips[NUM_CHIPS],
163163
// read from ADC convs
164164
get_c_adc_voltages(chips, hspi);
165165

166+
#if (HIL_TEST_MODE_ENABLED == false)
166167
read_status_registers(chips, hspi);
168+
#endif // HIL_TEST_MODE_ENABLED
167169

168170
// Read configuration registers to monitor burning status and the like
169171
read_config_register_a(chips, hspi);
@@ -180,8 +182,10 @@ void segment_retrieve_debug_data(cell_asic chips[NUM_CHIPS],
180182
// poll stuff like vref, etc.
181183
adc_and_read_aux_registers(chips, hspi);
182184

185+
#if (HIL_TEST_MODE_ENABLED == false)
183186
// read the above into status registers
184187
read_status_registers(chips, hspi);
188+
#endif // HIL_TEST_MODE_ENABLED
185189

186190
// Read configuration registers to monitor burning status and the like
187191
read_config_register_a(chips, hspi);

Core/Src/shep_tasks.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,8 +587,10 @@ uint8_t shep_threads_init(TX_BYTE_POOL *byte_pool)
587587
CATCH_ERROR(create_thread(byte_pool, &_can_receive_thread), U_SUCCESS);
588588
CATCH_ERROR(create_thread(byte_pool, &_can_dispatch_thread), U_SUCCESS);
589589
CATCH_ERROR(create_thread(byte_pool, &_segment_data_thread), U_SUCCESS);
590+
#if (HIL_TEST_MODE_ENABLED == false)
590591
CATCH_ERROR(create_thread(byte_pool, &_hv_plate_data_thread),
591592
U_SUCCESS);
593+
#endif // HIL_TEST_MODE_ENABLED
592594
CATCH_ERROR(create_thread(byte_pool, &_sanitizer_thread), U_SUCCESS);
593595
CATCH_ERROR(create_thread(byte_pool, &_bms_algorithms_thread),
594596
U_SUCCESS);

Core/Src/stm32h5xx_hal_msp.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,40 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart)
530530

531531
/* USER CODE END UART4_MspInit 1 */
532532
}
533+
else if(huart->Instance==UART9)
534+
{
535+
/* USER CODE BEGIN UART9_MspInit 0 */
536+
537+
/* USER CODE END UART9_MspInit 0 */
538+
539+
/** Initializes the peripherals clock
540+
*/
541+
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_UART9;
542+
PeriphClkInitStruct.Uart9ClockSelection = RCC_UART9CLKSOURCE_PCLK1;
543+
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
544+
{
545+
Error_Handler();
546+
}
547+
548+
/* Peripheral clock enable */
549+
__HAL_RCC_UART9_CLK_ENABLE();
550+
551+
__HAL_RCC_GPIOD_CLK_ENABLE();
552+
/**UART9 GPIO Configuration
553+
PD14 ------> UART9_RX
554+
PD15 ------> UART9_TX
555+
*/
556+
GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15;
557+
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
558+
GPIO_InitStruct.Pull = GPIO_NOPULL;
559+
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
560+
GPIO_InitStruct.Alternate = GPIO_AF11_UART9;
561+
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
562+
563+
/* USER CODE BEGIN UART9_MspInit 1 */
564+
565+
/* USER CODE END UART9_MspInit 1 */
566+
}
533567

534568
}
535569

@@ -582,6 +616,24 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
582616

583617
/* USER CODE END UART4_MspDeInit 1 */
584618
}
619+
else if(huart->Instance==UART9)
620+
{
621+
/* USER CODE BEGIN UART9_MspDeInit 0 */
622+
623+
/* USER CODE END UART9_MspDeInit 0 */
624+
/* Peripheral clock disable */
625+
__HAL_RCC_UART9_CLK_DISABLE();
626+
627+
/**UART9 GPIO Configuration
628+
PD14 ------> UART9_RX
629+
PD15 ------> UART9_TX
630+
*/
631+
HAL_GPIO_DeInit(GPIOD, GPIO_PIN_14|GPIO_PIN_15);
632+
633+
/* USER CODE BEGIN UART9_MspDeInit 1 */
634+
635+
/* USER CODE END UART9_MspDeInit 1 */
636+
}
585637

586638
}
587639

Drivers/adbms

Submodule adbms updated from b72575e to b1a6b59

TSECU-Shepherd.ioc

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,15 @@ Mcu.IP25=TIM4
109109
Mcu.IP26=TIM5
110110
Mcu.IP27=TIM6
111111
Mcu.IP28=UART4
112+
Mcu.IP29=UART9
112113
Mcu.IP3=ETH
113114
Mcu.IP4=FDCAN2
114115
Mcu.IP5=GPDMA1
115116
Mcu.IP6=I2C1
116117
Mcu.IP7=I2C2
117118
Mcu.IP8=ICACHE
118119
Mcu.IP9=IWDG
119-
Mcu.IPNb=29
120+
Mcu.IPNb=30
120121
Mcu.Name=STM32H563ZITx
121122
Mcu.Package=LQFP144
122123
Mcu.Pin0=PE2
@@ -353,6 +354,7 @@ PC7.GPIO_Label=FAN_PWM0
353354
PC7.Locked=true
354355
PC7.Signal=S_TIM3_CH2
355356
PCC.Checker=false
357+
PCC.Display=Plot\: All Steps
356358
PCC.Line=STM32H563/H573
357359
PCC.MCU=STM32H563ZITx
358360
PCC.PartNumber=STM32H563ZITx
@@ -374,11 +376,11 @@ PD13.Locked=true
374376
PD13.PinAttribute=Free
375377
PD13.Signal=GPXTI13
376378
PD14.Locked=true
377-
PD14.Signal=GPXTI14
378-
PD15.GPIOParameters=PinAttribute
379+
PD14.Mode=Asynchronous
380+
PD14.Signal=UART9_RX
379381
PD15.Locked=true
380-
PD15.PinAttribute=Free
381-
PD15.Signal=GPXTI15
382+
PD15.Mode=Asynchronous
383+
PD15.Signal=UART9_TX
382384
PD3.Locked=true
383385
PD3.Mode=Full_Duplex_Master
384386
PD3.Signal=SPI2_SCK
@@ -591,10 +593,6 @@ RCC.VCOPLL2OutputFreq_Value=320000000
591593
RCC.VCOPLL3OutputFreq_Value=516000000
592594
SH.GPXTI13.0=GPIO_EXTI13
593595
SH.GPXTI13.ConfNb=1
594-
SH.GPXTI14.0=GPIO_EXTI14
595-
SH.GPXTI14.ConfNb=1
596-
SH.GPXTI15.0=GPIO_EXTI15
597-
SH.GPXTI15.ConfNb=1
598596
SH.GPXTI7.0=GPIO_EXTI7
599597
SH.GPXTI7.ConfNb=1
600598
SH.GPXTI8.0=GPIO_EXTI8

0 commit comments

Comments
 (0)