/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file : main.c * @brief : Main program body ****************************************************************************** * @attention * * Copyright (c) 2023 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "dma.h" #include "lwip.h" #include "spi.h" #include "gpio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ #include "tcp_echoclient.h" //#include "tcp_echoclient.c" /* 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 ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ uint8_t buffer[1536]; int LENGTHSEND; uint8_t data1[1200]; uint8_t buffert[1500];//copied used 7+13824+1=13832 uint8_t arrayspi4_u1[13840];//SPI4 ARRAY FOR U1 uint8_t datarxflagok; uint8_t sot1flag,sot2flag; uint16_t datasrno; uint8_t transfer,ecounter=0; /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); /* USER CODE BEGIN PFP */ /* USER CODE END PFP */ /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ #include "stdio.h" #include "stdlib.h" /* 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(); /* USER CODE BEGIN SysInit */ void HAL_ETH_RxCpltCallback(ETH_HandleTypeDef *heth); /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_DMA_Init(); MX_LWIP_Init(); MX_SPI4_Init(); /* USER CODE BEGIN 2 */ udp_echoclient_connect();//it is ok //tcp_echoclient_connect(); /*##-3- Configure the NVIC for SPI #########################################*/ /* NVIC for SPI */ HAL_NVIC_SetPriority(SPI4_IRQn, 0, 1); HAL_NVIC_EnableIRQ(SPI4_IRQn); HAL_NVIC_SetPriority(ETH_IRQn, 1, 1); HAL_NVIC_EnableIRQ(ETH_IRQn); // tcp_echoclient_connect(); // Enable the SPI interrupt // __HAL_SPI_ENABLE_IT(&hspi4, SPI_IT_TXE); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ HAL_GPIO_WritePin(GPIOE,GPIO_PIN_4,GPIO_PIN_SET);//SPI4 CS/NSS uint8_t my_array[5]; uint8_t my_array1[5]; my_array[0] = 0x10; my_array[1] = 0x20; my_array[2] = 0x30; my_array[3] = 0x40; my_array[4] = 0x50; // if(buffert[0]=='A'||buffer[0]=='B') //HAL_SPI_TransmitReceive(&hspi4, (uint8_t *)my_array, (uint8_t *)my_array1, 1,9000); //HAL_SPI_Transmit(&hspi4, (uint8_t*)my_array,3, 5000);//TIMEOUT IN MS //memset(Rx_data,0,sizeof(Rx_data); //__HAL_ETH_DMA_ENABLE_IT((heth), ETH_DMA_IT_NIS | ETH_DMA_IT_R|ETH_DMA_IT_T); //__HAL_ETH_DMATXDESC_ENABLE_IT(heth); tcp_echoclient_connect(); uint8_t count; HAL_GPIO_WritePin(GPIOE,GPIO_PIN_1,GPIO_PIN_SET);//LED CONN OFF HAL_GPIO_WritePin(GPIOE,GPIO_PIN_0,GPIO_PIN_SET);//SYNC LED OFF // int _write(int file, char *ptr, int len) { // for (int i = 0; i < len; i++) { // ITM_SendChar(*ptr++); // } //return len; //} while (1) { uint8_t count; printf ("test= %d\n",count); count++; // fflush(stdout); MX_LWIP_Process(); //tcp_echoclient_connect(); /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ // if(echoclient_pcb != NULL) //{} // tcpconnectioncheck(); /* if(buffer[0]=='A'& buffer[1]=='B') { tcp_echoclient_connect();} if(buffert[0]=='A'& buffert[1]=='B')*/ //buffert[0]=='ab'&& buffert[1]=='cd'&& if( datarxflagok==1) {//ecounter++; // if(ecounter%2==0) // {HAL_GPIO_WritePin(GPIOE,GPIO_PIN_1,GPIO_PIN_RESET);//LED ON // HAL_GPIO_WritePin(GPIOE,GPIO_PIN_0,GPIO_PIN_SET);}//LED CONN off //else //{ HAL_GPIO_WritePin(GPIOE,GPIO_PIN_0,GPIO_PIN_RESET);//LED ON // HAL_GPIO_WritePin(GPIOE,GPIO_PIN_1,GPIO_PIN_SET);}//SYNC LED OFF // HAL_GPIO_WritePin(GPIOE,GPIO_PIN_4,GPIO_PIN_RESET);//SPI4 CS/NSS // while (__HAL_SPI_GET_FLAG(hspi4, SPI_FLAG_TXE)) // for(int g=0;g<13824;g++) // if(g%2==0) // {arrayspi4_u1[g]=0XE1;} // / Transmit the data in multiple bursts // for (uint32_t i = 0; i < 13824; i += 1024) { if(transfer==0) { HAL_SPI_Transmit_DMA(&hspi4, &arrayspi4_u1[0],13824); datarxflagok=0; } } //HAL_SPI_Transmit_IT(&hspi4,(uint8_t*)&arrayspi4_u1,13824);okworking //HAL_GPIO_WritePin(GPIOE,GPIO_PIN_4,GPIO_PIN_SET);//SPI4 CS/NSS // datarxflagok=0; // buffert[0]='c'; //}//end of if mainTIMEOUT IN MS // ethernetif_input(&gnetif); // sys_check_timeouts(); } /* USER CODE END 3 */ } /** * @brief System Clock Configuration * @retval None */ void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; /** Configure the main internal regulator output voltage */ __HAL_RCC_PWR_CLK_ENABLE(); __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); /** Initializes the RCC Oscillators according to the specified parameters * in the RCC_OscInitTypeDef structure. */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLM = 25; RCC_OscInitStruct.PLL.PLLN = 360; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; RCC_OscInitStruct.PLL.PLLQ = 4; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { Error_Handler(); } /** Activate the Over-Drive mode */ if (HAL_PWREx_EnableOverDrive() != 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_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK) { Error_Handler(); } HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSE, RCC_MCODIV_1); } /* USER CODE BEGIN 4 */ void HAL_ETH_RxCpltCallback(ETH_HandleTypeDef *heth) {int a=0; /* Clear the interrupt flags */ // _HAL_ETH_DMA_CLEAR_IT(heth, ETH_DMA_FLAG_AIS); a++; } void SPI_DMATransmitCplt(SPI_HandleTypeDef *hspi4) {while(HAL_SPI_GetState(&hspi4) != HAL_SPI_STATE_READY); } void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi) { if (hspi == &hspi4) { // DMA transfer completed successfully transfer=0; // Add your post-transfer code here if needed } } int _write(int file, char *ptr, int len) { (void)file; int DataIdx; for (DataIdx = 0; DataIdx < len; DataIdx++) { ITM_SendChar(*ptr++);// __io_putchar(*ptr++); } return len; } /* USER CODE END 4 */ /** * @brief This function is executed in case of error occurrence. * @retval None */ void Error_Handler(void) { /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); while (1) { } /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t *file, uint32_t line) { /* USER CODE BEGIN 6 */ /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */