/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file : main.c * @brief : Main program body ****************************************************************************** * @attention * *

© Copyright (c) 2022 STMicroelectronics. * All rights reserved.

* * This software component is licensed by ST under BSD 3-Clause license, * the "License"; You may not use this file except in compliance with the * License. You may obtain a copy of the License at: * opensource.org/licenses/BSD-3-Clause * ****************************************************************************** */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ #include "charger_control.h" #include "slave_handler.h" #include "can.h" #include "b_cccv_algo.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN PTD */ /* USER CODE END PTD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ FDCAN_HandleTypeDef hfdcan1; I2C_HandleTypeDef hi2c4; LTDC_HandleTypeDef hltdc; SD_HandleTypeDef hsd2; UART_HandleTypeDef huart5; UART_HandleTypeDef huart10; PCD_HandleTypeDef hpcd_USB_OTG_HS; SDRAM_HandleTypeDef hsdram1; uint16_t setpoint = 0; float currentsetpoint = 0.0; float voltagesetpoint = 3.8; /* USER CODE BEGIN PV */ /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); void PeriphCommonClock_Config(void); static void MX_GPIO_Init(void); static void MX_FDCAN1_Init(void); static void MX_FMC_Init(void); static void MX_I2C4_Init(void); static void MX_SDMMC2_SD_Init(void); static void MX_USART10_UART_Init(void); static void MX_USB_OTG_HS_PCD_Init(void); static void MX_UART5_Init(void); static void MX_LTDC_Init(void); /* USER CODE BEGIN PFP */ uint32_t MemoryCheck(UART_HandleTypeDef *uart_console, SDRAM_HandleTypeDef *sram); /* USER CODE END PFP */ /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ #define RAM_TEST_BLOCKSIZE 4096 __attribute__((section(".ahb_sec"))) uint32_t testarray[RAM_TEST_BLOCKSIZE]; /* USER CODE END 0 */ /** * @brief The application entry point. * @retval int */ int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration--------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* Configure the peripherals common clocks */ PeriphCommonClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_FDCAN1_Init(); //MX_FMC_Init(); MX_I2C4_Init(); //MX_SDMMC2_SD_Init(); MX_USART10_UART_Init(); MX_USB_OTG_HS_PCD_Init(); MX_UART5_Init(); //MX_LTDC_Init(); /* USER CODE BEGIN 2 */ //uint32_t sdramcheck = MemoryCheck(&huart5, &hsdram1); //MX_LTDC_Init(); slave_handler_init(); initCan(&hfdcan1); charger_control_init(&hi2c4); initChargerAlgo(102, 4.15); setchargecurrent(0.0); setchargevoltage(102, 0); charger_control_disable_remote(); //HAL_LTDC_Reload(&hltdc, LTDC_RELOAD_IMMEDIATE); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ uint32_t lasttick = HAL_GetTick(); while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ if((HAL_GetTick() - lasttick) > 1000) { // float maxvoltage = slaves_get_maximum_voltage(); // lasttick = HAL_GetTick(); // chargingloop(slaves_get_maximum_voltage()); HAL_GPIO_TogglePin(STATUS_LED_2_GPIO_Port, STATUS_LED_2_Pin); } // HAL_Delay(500); } /* USER CODE END 3 */ } /** * @brief System Clock Configuration * @retval None */ void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; /*AXI clock gating */ RCC->CKGAENR = 0xFFFFFFFF; /** Supply configuration update enable */ HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY); /** Configure the main internal regulator output voltage */ __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2); while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {} /** Macro to configure the PLL clock source */ __HAL_RCC_PLL_PLLSOURCE_CONFIG(RCC_PLLSOURCE_HSE); /** Initializes the RCC Oscillators according to the specified parameters * in the RCC_OscInitTypeDef structure. */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48|RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.HSI48State = RCC_HSI48_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLM = 1; RCC_OscInitStruct.PLL.PLLN = 20; RCC_OscInitStruct.PLL.PLLP = 2; RCC_OscInitStruct.PLL.PLLQ = 4; RCC_OscInitStruct.PLL.PLLR = 2; RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_3; RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE; RCC_OscInitStruct.PLL.PLLFRACN = 0; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { Error_Handler(); } /** Initializes the CPU, AHB and APB buses clocks */ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2 |RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV1; RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV2; RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV2; RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2; RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV2; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK) { Error_Handler(); } } /** * @brief Peripherals Common Clock Configuration * @retval None */ void PeriphCommonClock_Config(void) { RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0}; /** Initializes the peripherals clock */ PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_FMC|RCC_PERIPHCLK_SDMMC; PeriphClkInitStruct.PLL2.PLL2M = 1; PeriphClkInitStruct.PLL2.PLL2N = 20; PeriphClkInitStruct.PLL2.PLL2P = 2; PeriphClkInitStruct.PLL2.PLL2Q = 4; PeriphClkInitStruct.PLL2.PLL2R = 2; PeriphClkInitStruct.PLL2.PLL2RGE = RCC_PLL2VCIRANGE_3; PeriphClkInitStruct.PLL2.PLL2VCOSEL = RCC_PLL2VCOWIDE; PeriphClkInitStruct.PLL2.PLL2FRACN = 0; PeriphClkInitStruct.FmcClockSelection = RCC_FMCCLKSOURCE_PLL2; PeriphClkInitStruct.SdmmcClockSelection = RCC_SDMMCCLKSOURCE_PLL2; if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) { Error_Handler(); } } /** * @brief FDCAN1 Initialization Function * @param None * @retval None */ static void MX_FDCAN1_Init(void) { /* USER CODE BEGIN FDCAN1_Init 0 */ /* USER CODE END FDCAN1_Init 0 */ /* USER CODE BEGIN FDCAN1_Init 1 */ /* USER CODE END FDCAN1_Init 1 */ hfdcan1.Instance = FDCAN1; hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC; hfdcan1.Init.Mode = FDCAN_MODE_NORMAL; hfdcan1.Init.AutoRetransmission = DISABLE; hfdcan1.Init.TransmitPause = DISABLE; hfdcan1.Init.ProtocolException = DISABLE; hfdcan1.Init.NominalPrescaler = 2; hfdcan1.Init.NominalSyncJumpWidth = 1; hfdcan1.Init.NominalTimeSeg1 = 63; hfdcan1.Init.NominalTimeSeg2 = 16; hfdcan1.Init.DataPrescaler = 1; hfdcan1.Init.DataSyncJumpWidth = 1; hfdcan1.Init.DataTimeSeg1 = 1; hfdcan1.Init.DataTimeSeg2 = 1; hfdcan1.Init.MessageRAMOffset = 0; hfdcan1.Init.StdFiltersNbr = 32; hfdcan1.Init.ExtFiltersNbr = 0; hfdcan1.Init.RxFifo0ElmtsNbr = 16; hfdcan1.Init.RxFifo0ElmtSize = FDCAN_DATA_BYTES_8; hfdcan1.Init.RxFifo1ElmtsNbr = 0; hfdcan1.Init.RxFifo1ElmtSize = FDCAN_DATA_BYTES_8; hfdcan1.Init.RxBuffersNbr = 0; hfdcan1.Init.RxBufferSize = FDCAN_DATA_BYTES_8; hfdcan1.Init.TxEventsNbr = 0; hfdcan1.Init.TxBuffersNbr = 0; hfdcan1.Init.TxFifoQueueElmtsNbr = 1; hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; hfdcan1.Init.TxElmtSize = FDCAN_DATA_BYTES_8; if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN FDCAN1_Init 2 */ /* USER CODE END FDCAN1_Init 2 */ } /** * @brief I2C4 Initialization Function * @param None * @retval None */ static void MX_I2C4_Init(void) { /* USER CODE BEGIN I2C4_Init 0 */ /* USER CODE END I2C4_Init 0 */ /* USER CODE BEGIN I2C4_Init 1 */ /* USER CODE END I2C4_Init 1 */ hi2c4.Instance = I2C4; hi2c4.Init.Timing = 0x10909CEC; hi2c4.Init.OwnAddress1 = 0; hi2c4.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; hi2c4.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; hi2c4.Init.OwnAddress2 = 0; hi2c4.Init.OwnAddress2Masks = I2C_OA2_NOMASK; hi2c4.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE; hi2c4.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE; if (HAL_I2C_Init(&hi2c4) != HAL_OK) { Error_Handler(); } /** Configure Analogue filter */ if (HAL_I2CEx_ConfigAnalogFilter(&hi2c4, I2C_ANALOGFILTER_ENABLE) != HAL_OK) { Error_Handler(); } /** Configure Digital filter */ if (HAL_I2CEx_ConfigDigitalFilter(&hi2c4, 0) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN I2C4_Init 2 */ /* USER CODE END I2C4_Init 2 */ } /** * @brief LTDC Initialization Function * @param None * @retval None */ static void MX_LTDC_Init(void) { /* USER CODE BEGIN LTDC_Init 0 */ /* USER CODE END LTDC_Init 0 */ LTDC_LayerCfgTypeDef pLayerCfg = {0}; /* USER CODE BEGIN LTDC_Init 1 */ /* USER CODE END LTDC_Init 1 */ hltdc.Instance = LTDC; hltdc.Init.HSPolarity = LTDC_HSPOLARITY_AL; hltdc.Init.VSPolarity = LTDC_VSPOLARITY_AL; hltdc.Init.DEPolarity = LTDC_DEPOLARITY_AL; hltdc.Init.PCPolarity = LTDC_PCPOLARITY_IPC; hltdc.Init.HorizontalSync = 19; hltdc.Init.VerticalSync = 2; hltdc.Init.AccumulatedHBP = 159; hltdc.Init.AccumulatedVBP = 22; hltdc.Init.AccumulatedActiveW = 1183; hltdc.Init.AccumulatedActiveH = 622; hltdc.Init.TotalWidth = 1343; hltdc.Init.TotalHeigh = 634; hltdc.Init.Backcolor.Blue = 0; hltdc.Init.Backcolor.Green = 0; hltdc.Init.Backcolor.Red = 0; if (HAL_LTDC_Init(&hltdc) != HAL_OK) { Error_Handler(); } pLayerCfg.WindowX0 = 0; pLayerCfg.WindowX1 = 0; pLayerCfg.WindowY0 = 0; pLayerCfg.WindowY1 = 0; pLayerCfg.PixelFormat = LTDC_PIXEL_FORMAT_RGB888; pLayerCfg.Alpha = 0; pLayerCfg.Alpha0 = 0; pLayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_CA; pLayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_CA; pLayerCfg.FBStartAdress = 201326592; pLayerCfg.ImageWidth = 1024; pLayerCfg.ImageHeight = 600; pLayerCfg.Backcolor.Blue = 100; pLayerCfg.Backcolor.Green = 0; pLayerCfg.Backcolor.Red = 0; if (HAL_LTDC_ConfigLayer(&hltdc, &pLayerCfg, 0) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN LTDC_Init 2 */ __HAL_LTDC_ENABLE(&hltdc); __HAL_LTDC_LAYER_ENABLE(&hltdc,1); /* USER CODE END LTDC_Init 2 */ } /** * @brief SDMMC2 Initialization Function * @param None * @retval None */ static void MX_SDMMC2_SD_Init(void) { /* USER CODE BEGIN SDMMC2_Init 0 */ /* USER CODE END SDMMC2_Init 0 */ /* USER CODE BEGIN SDMMC2_Init 1 */ /* USER CODE END SDMMC2_Init 1 */ hsd2.Instance = SDMMC2; hsd2.Init.ClockEdge = SDMMC_CLOCK_EDGE_RISING; hsd2.Init.ClockPowerSave = SDMMC_CLOCK_POWER_SAVE_DISABLE; hsd2.Init.BusWide = SDMMC_BUS_WIDE_1B; hsd2.Init.HardwareFlowControl = SDMMC_HARDWARE_FLOW_CONTROL_DISABLE; hsd2.Init.ClockDiv = 0; if (HAL_SD_Init(&hsd2) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN SDMMC2_Init 2 */ /* USER CODE END SDMMC2_Init 2 */ } /** * @brief UART5 Initialization Function * @param None * @retval None */ static void MX_UART5_Init(void) { /* USER CODE BEGIN UART5_Init 0 */ /* USER CODE END UART5_Init 0 */ /* USER CODE BEGIN UART5_Init 1 */ /* USER CODE END UART5_Init 1 */ huart5.Instance = UART5; huart5.Init.BaudRate = 115200; huart5.Init.WordLength = UART_WORDLENGTH_8B; huart5.Init.StopBits = UART_STOPBITS_1; huart5.Init.Parity = UART_PARITY_NONE; huart5.Init.Mode = UART_MODE_TX_RX; huart5.Init.HwFlowCtl = UART_HWCONTROL_NONE; huart5.Init.OverSampling = UART_OVERSAMPLING_16; huart5.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; huart5.Init.ClockPrescaler = UART_PRESCALER_DIV1; huart5.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; if (HAL_UART_Init(&huart5) != HAL_OK) { Error_Handler(); } if (HAL_UARTEx_SetTxFifoThreshold(&huart5, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) { Error_Handler(); } if (HAL_UARTEx_SetRxFifoThreshold(&huart5, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) { Error_Handler(); } if (HAL_UARTEx_DisableFifoMode(&huart5) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN UART5_Init 2 */ /* USER CODE END UART5_Init 2 */ } /** * @brief USART10 Initialization Function * @param None * @retval None */ static void MX_USART10_UART_Init(void) { /* USER CODE BEGIN USART10_Init 0 */ /* USER CODE END USART10_Init 0 */ /* USER CODE BEGIN USART10_Init 1 */ /* USER CODE END USART10_Init 1 */ huart10.Instance = USART10; huart10.Init.BaudRate = 115200; huart10.Init.WordLength = UART_WORDLENGTH_8B; huart10.Init.StopBits = UART_STOPBITS_1; huart10.Init.Parity = UART_PARITY_NONE; huart10.Init.Mode = UART_MODE_TX_RX; huart10.Init.HwFlowCtl = UART_HWCONTROL_NONE; huart10.Init.OverSampling = UART_OVERSAMPLING_16; huart10.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; huart10.Init.ClockPrescaler = UART_PRESCALER_DIV1; huart10.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; if (HAL_UART_Init(&huart10) != HAL_OK) { Error_Handler(); } if (HAL_UARTEx_SetTxFifoThreshold(&huart10, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) { Error_Handler(); } if (HAL_UARTEx_SetRxFifoThreshold(&huart10, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) { Error_Handler(); } if (HAL_UARTEx_DisableFifoMode(&huart10) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN USART10_Init 2 */ /* USER CODE END USART10_Init 2 */ } /** * @brief USB_OTG_HS Initialization Function * @param None * @retval None */ static void MX_USB_OTG_HS_PCD_Init(void) { /* USER CODE BEGIN USB_OTG_HS_Init 0 */ /* USER CODE END USB_OTG_HS_Init 0 */ /* USER CODE BEGIN USB_OTG_HS_Init 1 */ /* USER CODE END USB_OTG_HS_Init 1 */ hpcd_USB_OTG_HS.Instance = USB_OTG_HS; hpcd_USB_OTG_HS.Init.dev_endpoints = 9; hpcd_USB_OTG_HS.Init.speed = PCD_SPEED_FULL; hpcd_USB_OTG_HS.Init.dma_enable = DISABLE; hpcd_USB_OTG_HS.Init.phy_itface = USB_OTG_EMBEDDED_PHY; hpcd_USB_OTG_HS.Init.Sof_enable = DISABLE; hpcd_USB_OTG_HS.Init.low_power_enable = DISABLE; hpcd_USB_OTG_HS.Init.lpm_enable = DISABLE; hpcd_USB_OTG_HS.Init.vbus_sensing_enable = ENABLE; hpcd_USB_OTG_HS.Init.use_dedicated_ep1 = DISABLE; hpcd_USB_OTG_HS.Init.use_external_vbus = DISABLE; if (HAL_PCD_Init(&hpcd_USB_OTG_HS) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN USB_OTG_HS_Init 2 */ /* USER CODE END USB_OTG_HS_Init 2 */ } /* FMC initialization function */ static void MX_FMC_Init(void) { /* USER CODE BEGIN FMC_Init 0 */ /* USER CODE END FMC_Init 0 */ FMC_SDRAM_TimingTypeDef SdramTiming = {0}; /* USER CODE BEGIN FMC_Init 1 */ /* USER CODE END FMC_Init 1 */ /** Perform the SDRAM1 memory initialization sequence */ hsdram1.Instance = FMC_SDRAM_DEVICE; /* hsdram1.Init */ hsdram1.Init.SDBank = FMC_SDRAM_BANK1; hsdram1.Init.ColumnBitsNumber = FMC_SDRAM_COLUMN_BITS_NUM_9; hsdram1.Init.RowBitsNumber = FMC_SDRAM_ROW_BITS_NUM_13; hsdram1.Init.MemoryDataWidth = FMC_SDRAM_MEM_BUS_WIDTH_16; hsdram1.Init.InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4; hsdram1.Init.CASLatency = FMC_SDRAM_CAS_LATENCY_3; hsdram1.Init.WriteProtection = FMC_SDRAM_WRITE_PROTECTION_DISABLE; hsdram1.Init.SDClockPeriod = FMC_SDRAM_CLOCK_PERIOD_2; hsdram1.Init.ReadBurst = FMC_SDRAM_RBURST_DISABLE; hsdram1.Init.ReadPipeDelay = FMC_SDRAM_RPIPE_DELAY_1; /* SdramTiming */ SdramTiming.LoadToActiveDelay = 2; SdramTiming.ExitSelfRefreshDelay = 5; SdramTiming.SelfRefreshTime = 3; SdramTiming.RowCycleDelay = 4; SdramTiming.WriteRecoveryTime = 3; SdramTiming.RPDelay = 3; SdramTiming.RCDDelay = 2; if (HAL_SDRAM_Init(&hsdram1, &SdramTiming) != HAL_OK) { Error_Handler( ); } /* USER CODE BEGIN FMC_Init 2 */ FMC_SDRAM_CommandTypeDef command; HAL_StatusTypeDef status; command.CommandTarget = FMC_SDRAM_CMD_TARGET_BANK1; command.CommandMode = FMC_SDRAM_CMD_CLK_ENABLE; command.AutoRefreshNumber = 1; command.ModeRegisterDefinition = 0; status = HAL_SDRAM_SendCommand(&hsdram1, &command, 1000); HAL_Delay(1); command.CommandMode = FMC_SDRAM_CMD_PALL; command.AutoRefreshNumber = 8; command.ModeRegisterDefinition = 0; status = HAL_SDRAM_SendCommand(&hsdram1, &command, 1000); command.CommandMode = FMC_SDRAM_CMD_LOAD_MODE; command.AutoRefreshNumber = 1; command.ModeRegisterDefinition = 0x130; status = HAL_SDRAM_SendCommand(&hsdram1, &command, 1000); command.CommandMode = FMC_SDRAM_CMD_AUTOREFRESH_MODE; command.AutoRefreshNumber = 8; command.ModeRegisterDefinition = 0; status = HAL_SDRAM_SendCommand(&hsdram1, &command, 1000); status = HAL_SDRAM_ProgramRefreshRate(&hsdram1, 0x0595); /* USER CODE END FMC_Init 2 */ } /** * @brief GPIO Initialization Function * @param None * @retval None */ static void MX_GPIO_Init(void) { GPIO_InitTypeDef GPIO_InitStruct = {0}; /* GPIO Ports Clock Enable */ __HAL_RCC_GPIOE_CLK_ENABLE(); __HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOF_CLK_ENABLE(); __HAL_RCC_GPIOH_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); __HAL_RCC_GPIOG_CLK_ENABLE(); __HAL_RCC_GPIOD_CLK_ENABLE(); /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(GPIOF, STATUS_LED_1_Pin|STATUS_LED_2_Pin, GPIO_PIN_RESET); /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(GPIOC, Display_Reset_Pin|Display_Standby_Pin|Display_Left_Right_Pin|Display_Up_Down_Pin, GPIO_PIN_RESET); /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(Charger_Relay_GPIO_Port, Charger_Relay_Pin, GPIO_PIN_RESET); /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(Charger_Remote_Shutdown_GPIO_Port, Charger_Remote_Shutdown_Pin, GPIO_PIN_RESET); /*Configure GPIO pins : STATUS_LED_1_Pin STATUS_LED_2_Pin */ GPIO_InitStruct.Pin = STATUS_LED_1_Pin|STATUS_LED_2_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOF, &GPIO_InitStruct); /*Configure GPIO pins : Display_Reset_Pin Display_Standby_Pin Display_Left_Right_Pin Display_Up_Down_Pin */ GPIO_InitStruct.Pin = Display_Reset_Pin|Display_Standby_Pin|Display_Left_Right_Pin|Display_Up_Down_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); /*Configure GPIO pins : Charger_CC_Status_Pin Charger_OT_Pin Charger_LIM_Pin Charger_DC_FAIL_Pin */ GPIO_InitStruct.Pin = Charger_CC_Status_Pin|Charger_OT_Pin|Charger_LIM_Pin|Charger_DC_FAIL_Pin; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOG, &GPIO_InitStruct); /*Configure GPIO pin : Charger_Relay_Pin */ GPIO_InitStruct.Pin = Charger_Relay_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(Charger_Relay_GPIO_Port, &GPIO_InitStruct); /*Configure GPIO pin : Charger_AC_Fail_Pin */ GPIO_InitStruct.Pin = Charger_AC_Fail_Pin; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(Charger_AC_Fail_GPIO_Port, &GPIO_InitStruct); /*Configure GPIO pin : Charger_Remote_Shutdown_Pin */ GPIO_InitStruct.Pin = Charger_Remote_Shutdown_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(Charger_Remote_Shutdown_GPIO_Port, &GPIO_InitStruct); } /* USER CODE BEGIN 4 */ /** @brief run a Memory Check over the complete SDRAM Area * */ uint32_t MemoryCheck(UART_HandleTypeDef *uart_console, SDRAM_HandleTypeDef *sram) { uint32_t totalerrors = 0; uint32_t numberofsectors = 400; uint32_t testadr = 0xC0000000; //*testpointer = 1; for(uint32_t startaddress = 0; startaddress < numberofsectors*RAM_TEST_BLOCKSIZE; startaddress += RAM_TEST_BLOCKSIZE) { for(uint32_t i = 0; i < RAM_TEST_BLOCKSIZE; i++) { testarray[i] = 0xFFFF00FF; } //*testadr = (uint32_t*) ; HAL_StatusTypeDef status = HAL_SDRAM_Write_32b(sram, (uint32_t*)(testadr+startaddress), testarray, RAM_TEST_BLOCKSIZE); //testadr = (uint32_t*) (startaddress + 0xC0000000); for(uint32_t i = 0; i < RAM_TEST_BLOCKSIZE; i++) { testarray[i] = 0; } status = HAL_SDRAM_Read_32b(sram,(uint32_t*)(testadr+startaddress), testarray, RAM_TEST_BLOCKSIZE); uint32_t errorcounter = 0; for(uint32_t i = 0; i