Browse Source

It pings!

Dmitry Yu Okunev 4 years ago
parent
commit
7d14d23d01

+ 1 - 1
Drivers/enc28j60

@@ -1 +1 @@
-Subproject commit 25374e420a63a6142c9ce6c8723cc499a0ca6697
+Subproject commit 4890274cf111b0c272648f1c1f00d8eb82c498c2

+ 1 - 1
Makefile

@@ -64,7 +64,7 @@ BIN = $(CP) -O binary -S
 #######################################
 # macros for gcc
 AS_DEFS =
-C_DEFS = -D__weak=__attribute__\(\(weak\)\) -D__packed=__attribute__\(\(__packed__\)\) -DUSE_HAL_DRIVER -DSTM32F091xC
+C_DEFS = -D__weak=__attribute__\(\(weak\)\) -D__packed=__attribute__\(\(__packed__\)\) -DUSE_HAL_DRIVER -DSTM32F091xC -DSTM32F0xx
 # includes for gcc
 AS_INCLUDES =
 C_INCLUDES = -IInc

File diff suppressed because it is too large
+ 2 - 2
SW4STM32/nucleo-f091rc-rs232-enc28j60 Configuration/.cproject


+ 36 - 36
SW4STM32/nucleo-f091rc-rs232-enc28j60 Configuration/.project

@@ -27,6 +27,42 @@
 	<linkedResources>
 		
 	<link>
+			<name>Drivers/STM32F0xx_HAL_Driver/stm32f0xx_hal_spi.c</name>
+			<type>1</type>
+			<location>PARENT-2-PROJECT_LOC/Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_spi.c</location>
+		</link><link>
+			<name>Application/User/stm32f0xx_hal_msp.c</name>
+			<type>1</type>
+			<location>PARENT-2-PROJECT_LOC/Src/stm32f0xx_hal_msp.c</location>
+		</link><link>
+			<name>Application/User/main.c</name>
+			<type>1</type>
+			<location>PARENT-2-PROJECT_LOC/Src/main.c</location>
+		</link><link>
+			<name>Drivers/STM32F0xx_HAL_Driver/stm32f0xx_hal_rcc.c</name>
+			<type>1</type>
+			<location>PARENT-2-PROJECT_LOC/Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_rcc.c</location>
+		</link><link>
+			<name>Drivers/STM32F0xx_HAL_Driver/stm32f0xx_hal_spi_ex.c</name>
+			<type>1</type>
+			<location>PARENT-2-PROJECT_LOC/Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_spi_ex.c</location>
+		</link><link>
+			<name>Drivers/STM32F0xx_HAL_Driver/stm32f0xx_hal_pwr.c</name>
+			<type>1</type>
+			<location>PARENT-2-PROJECT_LOC/Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_pwr.c</location>
+		</link><link>
+			<name>Drivers/STM32F0xx_HAL_Driver/stm32f0xx_hal_gpio.c</name>
+			<type>1</type>
+			<location>PARENT-2-PROJECT_LOC/Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_gpio.c</location>
+		</link><link>
+			<name>Drivers/STM32F0xx_HAL_Driver/stm32f0xx_hal.c</name>
+			<type>1</type>
+			<location>PARENT-2-PROJECT_LOC/Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal.c</location>
+		</link><link>
+			<name>Drivers/STM32F0xx_HAL_Driver/stm32f0xx_hal_rcc_ex.c</name>
+			<type>1</type>
+			<location>PARENT-2-PROJECT_LOC/Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_rcc_ex.c</location>
+		</link><link>
 			<name>Drivers/STM32F0xx_HAL_Driver/stm32f0xx_hal_dma.c</name>
 			<type>1</type>
 			<location>PARENT-2-PROJECT_LOC/Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_dma.c</location>
@@ -66,41 +102,5 @@
 			<name>Drivers/CMSIS/system_stm32f0xx.c</name>
 			<type>1</type>
 			<location>PARENT-2-PROJECT_LOC/Drivers/CMSIS/Device/ST/STM32F0xx/Source/Templates/system_stm32f0xx.c</location>
-		</link><link>
-			<name>Drivers/STM32F0xx_HAL_Driver/stm32f0xx_hal_spi.c</name>
-			<type>1</type>
-			<location>PARENT-2-PROJECT_LOC/Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_spi.c</location>
-		</link><link>
-			<name>Application/User/stm32f0xx_hal_msp.c</name>
-			<type>1</type>
-			<location>PARENT-2-PROJECT_LOC/Src/stm32f0xx_hal_msp.c</location>
-		</link><link>
-			<name>Application/User/main.c</name>
-			<type>1</type>
-			<location>PARENT-2-PROJECT_LOC/Src/main.c</location>
-		</link><link>
-			<name>Drivers/STM32F0xx_HAL_Driver/stm32f0xx_hal_rcc.c</name>
-			<type>1</type>
-			<location>PARENT-2-PROJECT_LOC/Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_rcc.c</location>
-		</link><link>
-			<name>Drivers/STM32F0xx_HAL_Driver/stm32f0xx_hal_spi_ex.c</name>
-			<type>1</type>
-			<location>PARENT-2-PROJECT_LOC/Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_spi_ex.c</location>
-		</link><link>
-			<name>Drivers/STM32F0xx_HAL_Driver/stm32f0xx_hal_pwr.c</name>
-			<type>1</type>
-			<location>PARENT-2-PROJECT_LOC/Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_pwr.c</location>
-		</link><link>
-			<name>Drivers/STM32F0xx_HAL_Driver/stm32f0xx_hal_gpio.c</name>
-			<type>1</type>
-			<location>PARENT-2-PROJECT_LOC/Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_gpio.c</location>
-		</link><link>
-			<name>Drivers/STM32F0xx_HAL_Driver/stm32f0xx_hal.c</name>
-			<type>1</type>
-			<location>PARENT-2-PROJECT_LOC/Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal.c</location>
-		</link><link>
-			<name>Drivers/STM32F0xx_HAL_Driver/stm32f0xx_hal_rcc_ex.c</name>
-			<type>1</type>
-			<location>PARENT-2-PROJECT_LOC/Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_rcc_ex.c</location>
 		</link></linkedResources>
 </projectDescription>

+ 86 - 9
Src/main.c

@@ -35,6 +35,9 @@
 
 /* USER CODE BEGIN Includes */
 
+#include "EtherShield.h"
+#define BUF_SIZE (1<<10)
+
 /* USER CODE END Includes */
 
 /* Private variables ---------------------------------------------------------*/
@@ -56,6 +59,53 @@ static void MX_USART3_UART_Init(void);
 /* USER CODE BEGIN PFP */
 /* Private function prototypes -----------------------------------------------*/
 
+void error (float error_num, char infinite) {
+	//printf("%u\r\n", error_num);
+	if (infinite)
+		while (1) {
+			int i = 0;
+			while (i++ < ((int)((float)(error_num) / 1) + 1) ) {
+				GPIOA->BSRR = GPIO_PIN_5;
+				HAL_Delay(1000 / error_num);
+				GPIOA->BSRR = GPIO_PIN_5 << 16;
+				HAL_Delay(1000 / error_num);
+			}
+		};
+
+	GPIOA->BSRR = GPIO_PIN_5;
+	HAL_Delay(1000);
+	GPIOA->BSRR = GPIO_PIN_5 << 16;
+
+	int i=0;
+	while (i++ < error_num) {
+		GPIOA->BSRR = GPIO_PIN_5;
+		HAL_Delay(300);
+		GPIOA->BSRR = GPIO_PIN_5 << 16;
+		HAL_Delay(200);
+	}
+
+	HAL_Delay(500);
+	NVIC_SystemReset();
+
+	return;
+}
+
+static inline void blink(int times, int delay) {
+	int i = 0;
+	while (i++ < times) {
+		GPIOA->BSRR = GPIO_PIN_5;
+		HAL_Delay(delay);
+		GPIOA->BSRR = GPIO_PIN_5 << 16;
+		HAL_Delay(delay);
+	}
+
+	return;
+}
+
+void ES_PingCallback(void) {
+	//STM_EVAL_LEDToggle(LED4);
+}
+
 /* USER CODE END PFP */
 
 /* USER CODE BEGIN 0 */
@@ -88,13 +138,40 @@ int main(void)
 
   /* Infinite loop */
   /* USER CODE BEGIN WHILE */
-  while (1)
-  {
+
+	uint8_t mac[] = {02, 03, 04, 05, 06, 07};
+	uint8_t ip[]  = {10,4,33,123};
+	static uint8_t buf[BUF_SIZE + 1];
+
+	ES_enc28j60SpiInit(&hspi1);
+	ES_enc28j60Init(mac);
+
+	uint8_t enc28j60_rev = ES_enc28j60Revision();
+
+	if (enc28j60_rev <= 0)
+		error(2, 0);
+
+	ES_init_ip_arp_udp_tcp(mac, ip, 23);
+
+	while (1)
+	{
+		uint16_t dat_p;
+
+		// read packet, handle ping and wait for a tcp packet:
+		dat_p = ES_packetloop_icmp_tcp(buf,
+				ES_enc28j60PacketReceive(BUF_SIZE, buf));
+
+		/* dat_p will be unequal to zero if there is a valid
+		 * http get */
+		if (dat_p == 0) {
+			// no http request
+			continue;
+		}
   /* USER CODE END WHILE */
 
   /* USER CODE BEGIN 3 */
 
-  }
+	}
   /* USER CODE END 3 */
 
 }
@@ -112,7 +189,7 @@ void SystemClock_Config(void)
   RCC_OscInitStruct.HSEState = RCC_HSE_ON;
   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
-  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL8;
+  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL12;
   RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV2;
   HAL_RCC_OscConfig(&RCC_OscInitStruct);
 
@@ -139,11 +216,11 @@ void MX_SPI1_Init(void)
   hspi1.Instance = SPI1;
   hspi1.Init.Mode = SPI_MODE_MASTER;
   hspi1.Init.Direction = SPI_DIRECTION_2LINES;
-  hspi1.Init.DataSize = SPI_DATASIZE_4BIT;
+  hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
   hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
   hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
-  hspi1.Init.NSS = SPI_NSS_HARD_OUTPUT;
-  hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4;
+  hspi1.Init.NSS = SPI_NSS_SOFT;
+  hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
   hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
   hspi1.Init.TIMode = SPI_TIMODE_DISABLED;
   hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
@@ -206,8 +283,8 @@ void MX_GPIO_Init(void)
   GPIO_InitStruct.Alternate = GPIO_AF1_USART2;
   HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 
-  /*Configure GPIO pin : PA5 */
-  GPIO_InitStruct.Pin = GPIO_PIN_5;
+  /*Configure GPIO pins : PA4 PA5 */
+  GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5;
   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
   GPIO_InitStruct.Pull = GPIO_NOPULL;
   GPIO_InitStruct.Speed = GPIO_SPEED_LOW;

+ 0 - 11
Src/stm32f0xx_hal_msp.c

@@ -71,18 +71,10 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
     __SPI1_CLK_ENABLE();
   
     /**SPI1 GPIO Configuration    
-    PA4     ------> SPI1_NSS
     PB3     ------> SPI1_SCK
     PB4     ------> SPI1_MISO
     PB5     ------> SPI1_MOSI 
     */
-    GPIO_InitStruct.Pin = GPIO_PIN_4;
-    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
-    GPIO_InitStruct.Pull = GPIO_NOPULL;
-    GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
-    GPIO_InitStruct.Alternate = GPIO_AF0_SPI1;
-    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
-
     GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5;
     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
     GPIO_InitStruct.Pull = GPIO_NOPULL;
@@ -109,13 +101,10 @@ void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
     __SPI1_CLK_DISABLE();
   
     /**SPI1 GPIO Configuration    
-    PA4     ------> SPI1_NSS
     PB3     ------> SPI1_SCK
     PB4     ------> SPI1_MISO
     PB5     ------> SPI1_MOSI 
     */
-    HAL_GPIO_DeInit(GPIOA, GPIO_PIN_4);
-
     HAL_GPIO_DeInit(GPIOB, GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5);
 
   }

+ 22 - 21
nucleo-f091rc-rs232-enc28j60.ioc

@@ -56,8 +56,8 @@ PA3.GPIO_PuPd=GPIO_NOPULL
 PA3.GPIO_Speed=GPIO_SPEED_LOW
 PA3.Locked=true
 PA3.Signal=USART2_RX
-PA4.Mode=NSS_Signal_Hard
-PA4.Signal=SPI1_NSS
+PA4.Locked=true
+PA4.Signal=GPIO_Output
 PA5.GPIOParameters=GPIO_ModeDefaultOutputPP,GPIO_Label,GPIO_Speed,GPIO_PuPd,GPIO_Mode
 PA5.GPIO_Label=LD2 [Green Led]
 PA5.GPIO_Mode=GPIO_MODE_OUTPUT_PP
@@ -123,36 +123,37 @@ ProjectManager.ProjectFileName=nucleo-f091rc-rs232-enc28j60.ioc
 ProjectManager.ProjectName=nucleo-f091rc-rs232-enc28j60
 ProjectManager.TargetToolchain=SW4STM32
 ProjectManager.ToolChainLocation=
-RCC.AHBFreq_Value=32000000
-RCC.APB1Freq_Value=32000000
-RCC.APB1TimFreq_Value=32000000
+RCC.AHBFreq_Value=48000000
+RCC.APB1Freq_Value=48000000
+RCC.APB1TimFreq_Value=48000000
 RCC.CECFreq_Value=32786.88524590164
-RCC.FCLKCortexFreq_Value=32000000
+RCC.FCLKCortexFreq_Value=48000000
 RCC.FLatency-AdvancedSettings=FLASH_LATENCY_1
 RCC.FamilyName=M
-RCC.HCLKFreq_Value=32000000
+RCC.HCLKFreq_Value=48000000
 RCC.HSICECFreq_Value=32786.88524590164
-RCC.I2SFreq_Value=32000000
+RCC.I2SFreq_Value=48000000
 RCC.IPParameters=HCLKFreq_Value,SYSCLKFreq_VALUE,FamilyName,PLLCLKFreq_Value,PREFETCH_ENABLE-AdvancedSettings,PLLMCOFreq_Value,SYSCLKSource,CECFreq_Value,FCLKCortexFreq_Value,FLatency-AdvancedSettings,PLLMUL,HSICECFreq_Value,MCOFreq_Value,I2SFreq_Value,USART2Freq_Value,APB1TimFreq_Value,APB1Freq_Value,USART1Freq_Value,AHBFreq_Value,TimSysFreq_Value,USART3Freq_Value,PLLDivider,PLLSource
-RCC.MCOFreq_Value=32000000
-RCC.PLLCLKFreq_Value=32000000
+RCC.MCOFreq_Value=48000000
+RCC.PLLCLKFreq_Value=48000000
 RCC.PLLDivider=RCC_PREDIV_DIV2
-RCC.PLLMCOFreq_Value=32000000
-RCC.PLLMUL=RCC_PLL_MUL8
+RCC.PLLMCOFreq_Value=48000000
+RCC.PLLMUL=RCC_PLL_MUL12
 RCC.PLLSource=RCC_PLLSOURCE_HSE
 RCC.PREFETCH_ENABLE-AdvancedSettings=1
-RCC.SYSCLKFreq_VALUE=32000000
+RCC.SYSCLKFreq_VALUE=48000000
 RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK
-RCC.TimSysFreq_Value=32000000
-RCC.USART1Freq_Value=32000000
-RCC.USART2Freq_Value=32000000
-RCC.USART3Freq_Value=32000000
+RCC.TimSysFreq_Value=48000000
+RCC.USART1Freq_Value=48000000
+RCC.USART2Freq_Value=48000000
+RCC.USART3Freq_Value=48000000
 SH.GPXTI13.0=GPIO_EXTI13
 SH.GPXTI13.ConfNb=1
-SPI1.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_4
-SPI1.CalculateBaudRate=8.0 MBits/s
-SPI1.IPParameters=Mode,BaudRatePrescaler,CalculateBaudRate,VirtualNSS
+SPI1.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_8
+SPI1.CRCCalculation=SPI_CRCCALCULATION_DISABLED
+SPI1.CalculateBaudRate=6.0 MBits/s
+SPI1.DataSize=SPI_DATASIZE_8BIT
+SPI1.IPParameters=Mode,BaudRatePrescaler,CalculateBaudRate,DataSize,CRCCalculation
 SPI1.Mode=SPI_MODE_MASTER
-SPI1.VirtualNSS=VM_NSSHARD
 board=NUCLEO-F091RC
 boardIOC=true