Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STM32 Port #457

Merged
merged 4 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
bin/
doc/
contrib/
source/src/cip_objects/
!source/src/cip_objects/CMakeLists.txt
Expand All @@ -9,7 +8,6 @@ source/src/cip_objects/
*.*~
*~
CMakeCache.txt
*.patch
.idea/
*.a
*.cmake
Expand Down
172 changes: 172 additions & 0 deletions source/doc/STM32/LwIP_HTTP_Server_Netconn_RTOS_OpENer.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
diff --git a/Inc/lwipopts.h b/Inc/lwipopts.h
index ef9dbfa..6a8c593 100644
--- a/Inc/lwipopts.h
+++ b/Inc/lwipopts.h
@@ -56,7 +56,9 @@ a lot of data that needs to be copied, this should be set high. */
/* MEMP_NUM_SYS_TIMEOUT: the number of simulateously active
timeouts. */
#define MEMP_NUM_SYS_TIMEOUT 10
-
+/* MEMP_NUM_NETCONN: the number of struct netconns.
+ (only needed if you use the sequential API, like api_lib.c) */
+#define MEMP_NUM_NETCONN 12

/* ---------- Pbuf options ---------- */
/* PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */
@@ -94,6 +96,8 @@ a lot of data that needs to be copied, this should be set high. */
/* ---------- ICMP options ---------- */
#define LWIP_ICMP 1

+/* ---------- IGMP options ---------- */
+#define LWIP_IGMP 1

/* ---------- DHCP options ---------- */
#define LWIP_DHCP 1
@@ -113,6 +117,9 @@ a lot of data that needs to be copied, this should be set high. */
*/
#define LWIP_NETIF_LINK_CALLBACK 1

+/* ---------- Netif options ---------- */
+#define LWIP_NETIF_HOSTNAME 1
+
/*
--------------------------------------
---------- Checksum options ----------
@@ -178,7 +185,11 @@ The STM32F4x7 allows computing and verifying the IP, UDP, TCP and ICMP checksums
/**
* LWIP_SOCKET==1: Enable Socket API (require to use sockets.c)
*/
-#define LWIP_SOCKET 0
+#define LWIP_SOCKET 1
+/**
+ * SO_REUSE==1: Enable SO_REUSEADDR option.
+ */
+#define SO_REUSE 1

/*
------------------------------------
diff --git a/Inc/main.h b/Inc/main.h
index 36ca85f..fb7961c 100644
--- a/Inc/main.h
+++ b/Inc/main.h
@@ -31,7 +31,7 @@

/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
-#define USE_DHCP /* enable DHCP, if disabled static address is used*/
+//#define USE_DHCP // not used, replaced by LWIP_DHCP
#define USE_LCD

/*Static IP ADDRESS*/
diff --git a/SW4STM32/syscalls.c b/SW4STM32/syscalls.c
index fa8687f..6a84edb 100644
--- a/SW4STM32/syscalls.c
+++ b/SW4STM32/syscalls.c
@@ -15,7 +15,7 @@
#include <reent.h>
#include <unistd.h>
#include <sys/wait.h>
-
+#include <stm32f7xx_hal.h>


#define FreeRTOS
@@ -99,6 +99,15 @@ void _exit (int status)
while (1) {}
}

+#if REDIRECT_PRINTF_TO_SWV_ITM
+__attribute__((weak)) int _write(int file, char *ptr, int len) {
+ int DataIdx;
+ for (DataIdx = 0; DataIdx < len; DataIdx++) {
+ ITM_SendChar(*ptr++);
+ }
+ return len;
+}
+#else // standard output
int _write(int file, char *ptr, int len)
{
int DataIdx;
@@ -109,6 +118,7 @@ int _write(int file, char *ptr, int len)
}
return len;
}
+#endif // standard output

int _close(int file)
{
diff --git a/Src/app_ethernet.c b/Src/app_ethernet.c
index e3278ac..aab6265 100644
--- a/Src/app_ethernet.c
+++ b/Src/app_ethernet.c
@@ -28,6 +28,9 @@
#include "lcd_log.h"
#endif

+// for OpENer
+#include "opener.h"
+
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
@@ -55,6 +58,8 @@ void ethernet_link_status_updated(struct netif *netif)
uint8_t iptxt[20];
sprintf((char *)iptxt, "%s", ip4addr_ntoa(netif_ip4_addr(netif)));
LCD_UsrLog ("Static IP address: %s\n", iptxt);
+ /* Start Ethernet/IP Stack (OpENer) */
+ opener_init(netif);
#else
BSP_LED_On(LED1);
BSP_LED_Off(LED2);
@@ -124,6 +129,8 @@ void DHCP_Thread(void const * argument)
BSP_LED_On(LED1);
BSP_LED_Off(LED2);
#endif
+ /* Start Ethernet/IP Stack (OpENer) */
+ opener_init(netif);
}
else
{
@@ -148,6 +155,8 @@ void DHCP_Thread(void const * argument)
BSP_LED_On(LED1);
BSP_LED_Off(LED2);
#endif
+ /* Start Ethernet/IP Stack (OpENer) */
+ opener_init(netif);
}
}
}
diff --git a/Src/main.c b/Src/main.c
index c25dbd0..e3dda6c 100644
--- a/Src/main.c
+++ b/Src/main.c
@@ -71,6 +71,11 @@ int main(void)
/* Configure the system clock to 200 MHz */
SystemClock_Config();

+ /* For single step debug, e.g. timers with interrupts need to be stopped in Halt */
+ HAL_DBGMCU_EnableDBGStandbyMode();
+ HAL_DBGMCU_EnableDBGStopMode();
+ __HAL_DBGMCU_FREEZE_TIM6();
+
/* Initialize LCD and LEDs */
BSP_Config();

@@ -139,6 +144,8 @@ static void Netif_Config(void)

/* Registers the default network interface. */
netif_set_default(&gnetif);
+ /* Define the hostname, is also used by OpENer */
+ netif_set_hostname(&gnetif,"STM32");

ethernet_link_status_updated(&gnetif);

@@ -180,7 +187,7 @@ static void BSP_Config(void)
LCD_LOG_Init();

/* Show Header and Footer texts */
- LCD_LOG_SetHeader((uint8_t *)"Webserver Application Netconn API");
+ LCD_LOG_SetHeader((uint8_t *)"Webserver Application Netconn API & OpENer");
LCD_LOG_SetFooter((uint8_t *)"STM32746G-DISCO board");

LCD_UsrLog ((char *)" State: Ethernet Initialization ...\n");
86 changes: 86 additions & 0 deletions source/doc/STM32/OpENer STM32 Paths and Symbols.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<cdtprojectproperties>
<section name="org.eclipse.cdt.internal.ui.wizards.settingswizards.IncludePaths">
<language id="org.eclipse.cdt.core.assembly" name="s,S"/>
<language id="org.eclipse.cdt.core.gcc" name="C Source File">
<includepath>../../Inc</includepath>
<includepath>../../Src</includepath>
<includepath>../../Drivers/CMSIS/Device/ST/STM32F7xx/Include</includepath>
<includepath>../../Drivers/STM32F7xx_HAL_Driver/Inc</includepath>
<includepath>../../Drivers/BSP/STM32746G-Discovery</includepath>
<includepath>../../Drivers/BSP/Components/Common</includepath>
<includepath>../../Drivers/BSP/Components</includepath>
<includepath>../../Middlewares/Third_Party/LwIP/src/include</includepath>
<includepath>../../Middlewares/Third_Party/LwIP/system</includepath>
<includepath>../../Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM7/r0p1</includepath>
<includepath>../../Middlewares/Third_Party/FreeRTOS/Source</includepath>
<includepath>../../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS</includepath>
<includepath>../../Middlewares/Third_Party/FreeRTOS/Source/include</includepath>
<includepath>../../Utilities</includepath>
<includepath>../../Utilities/Log</includepath>
<includepath>../../Drivers/CMSIS/Include</includepath>
<includepath>../../Middlewares/Third_Party/OpENer</includepath>
<includepath>../../Middlewares/Third_Party/OpENer/cip</includepath>
<includepath>../../Middlewares/Third_Party/OpENer/enet_encap</includepath>
<includepath>../../Middlewares/Third_Party/OpENer/ports</includepath>
<includepath>../../Middlewares/Third_Party/OpENer/ports/STM32</includepath>
<includepath>../../Middlewares/Third_Party/OpENer/ports/STM32/sample_application</includepath>
<includepath>../../Middlewares/Third_Party/OpENer/utils</includepath>
</language>
<language name="Object File"/>
</section>
<section name="org.eclipse.cdt.internal.ui.wizards.settingswizards.Macros">
<language id="org.eclipse.cdt.core.assembly" name="s,S"/>
<language id="org.eclipse.cdt.core.gcc" name="C Source File">
<macro>
<name>USE_HAL_DRIVER</name>
<value/>
</macro>
<macro>
<name>STM32F746xx</name>
<value/>
</macro>
<macro>
<name>USE_STM32746G_DISCOVERY</name>
<value/>
</macro>
<macro>
<name>RESTRICT</name>
<value>__restrict</value>
</macro>
<macro>
<name>STM32</name>
<value/>
</macro>
<macro>
<name>_POSIX_C_SOURCE</name>
<value>200112L</value>
</macro>
<macro>
<name>_GNU_SOURCE</name>
<value/>
</macro>
<macro>
<name>OPENER_TRACE_LEVEL</name>
<value>15</value>
</macro>
<macro>
<name>OPENER_CONSUMED_DATA_HAS_RUN_IDLE_HEADER</name>
<value>1</value>
</macro>
<macro>
<name>OPENER_WITH_TRACES</name>
<value>1</value>
</macro>
<macro>
<name>PC_OPENER_ETHERNET_BUFFER_SIZE</name>
<value>512</value>
</macro>
<macro>
<name>REDIRECT_PRINTF_TO_SWV_ITM</name>
<value>1</value>
</macro>
</language>
<language name="Object File"/>
</section>
</cdtprojectproperties>
Binary file added source/doc/STM32/OpENer STM32 Port.pdf
Binary file not shown.
2 changes: 2 additions & 0 deletions source/src/enet_encap/endianconv.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#ifdef WIN32
#include <winsock2.h>
#elif defined STM32
#include "lwip/inet.h"
#else
#include <netinet/in.h>
#include <sys/socket.h>
Expand Down
53 changes: 37 additions & 16 deletions source/src/opener_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
#include "ciptypes.h"
#include "ciperror.h"

#if defined(STM32) /** STM32 target -> uses a struct for the network interface */
#define TcpIpInterface struct netif
#else /** other targets -> string for the network interface */
#define TcpIpInterface const char
#endif /** other targets */

/** @defgroup CIP_API OpENer User interface
* @brief This is the public interface of the OpENer. It provides all function
* needed to implement an EtherNet/IP enabled slave-device.
Expand All @@ -21,56 +27,71 @@
/** @ingroup CIP_API
* @brief Read network configuration data from specified hardware interface
*
* @param iface address of string specifying the hardware interface
* @param iface_cfg address of interface configuration structure
* @return kEipStatusOk on success,
* kEipStatusError on error with @p errno set
* @param iface address specifying the network interface
* @param iface_cfg address of interface configuration structure
* @return kEipStatusOk on success,
* kEipStatusError on error with @p errno set
*
* This function reads all information needed to fill the iface_cfg structure
* of type @ref CipTcpIpInterfaceConfiguration from the hardware interface
* specified by the iface string.
*
*/
EipStatus IfaceGetConfiguration(const char *iface,
EipStatus IfaceGetConfiguration(TcpIpInterface *iface,
CipTcpIpInterfaceConfiguration *iface_cfg);

/** @ingroup CIP_API
* @brief Read and return the MAC address of the Ethernet interface
*
* @param iface string of interface name or interface index
* @param physical_address hardware MAC address of the network interface
* @return kEipStatusOk: all fine
* kEipStatusError: failure, errno set
* @param iface address specifying the network interface
* @param physical_address hardware MAC address of the network interface
* @return kEipStatusOk: all fine
* kEipStatusError: failure, errno set
*/
EipStatus IfaceGetMacAddress(const char *iface,
EipStatus IfaceGetMacAddress(TcpIpInterface *iface,
uint8_t *const physical_address);

/** @ingroup CIP_API
* @brief Wait for the network interface having an IP address
*
* @param timeout in seconds; max: INT_MAX/10, -1: wait for ever
* @param do_run stop waiting if this parameter becomes zero
* @return kEipStatusOk on success,
* kEipStatusError on error with @p errno set
* @param iface address specifying the network interface
* @param timeout in seconds; max: INT_MAX/10, -1: wait for ever
* @param abort_wait stop waiting if this parameter becomes zero
* @return kEipStatusOk on success,
* kEipStatusError on error with @p errno set
*
* This function waits for the network interface getting an IP address but
* only @p timeout seconds (set to -1 to wait for ever).
* The polling wait process can be aborted by setting @p abort_wait to
* a non zero value from another thread.
*/
EipStatus IfaceWaitForIp(const char *const iface,
EipStatus IfaceWaitForIp(TcpIpInterface *const iface,
int timeout,
volatile int *const abort_wait);

#if defined(STM32) /** STM32 target, the hostname is linked to the network interface */
/** @ingroup CIP_API
* @brief Get host name from platform
*
* @param iface address specifying the network interface
* @param hostname address of CipString destination structure
*
* This function reads the host name from the platform and returns it
* via the hostname parameter.
*/
void GetHostName(TcpIpInterface *iface,
CipString *hostname);
#else /** other targets */
/** @ingroup CIP_API
* @brief Get host name from platform
*
* @param hostname address of CipString destination structure
* @param hostname address of CipString destination structure
*
* This function reads the host name from the platform and returns it
* via the hostname parameter.
*/
void GetHostName(CipString *hostname);
#endif /** other targets */

/** @ingroup CIP_API
* @brief Set the CIP revision of the device's identity object.
Expand Down
Loading
Loading