diff --git a/demos/bsp/boards/embedded_artists/board_ea4357.c b/demos/bsp/boards/embedded_artists/board_ea4357.c
index a415c793..92d2bc49 100644
--- a/demos/bsp/boards/embedded_artists/board_ea4357.c
+++ b/demos/bsp/boards/embedded_artists/board_ea4357.c
@@ -50,10 +50,11 @@ void board_init(void)
{
CGU_Init();
-//#if TUSB_CFG_OS != TUSB_OS_CMSIS_RTX // TODO may move to main.c
+#if TUSB_CFG_OS == TUSB_OS_NONE // TODO may move to main.c
SysTick_Config(CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE) / CFG_TICKS_PER_SECOND); // 1 msec tick timer
-//#endif
+#endif
+ //------------- USB -------------//
// USB0 Power: EA4357 channel B U20 GPIO26 active low (base board), P2_3 on LPC4357
scu_pinmux(0x2, 3, MD_PUP | MD_EZI, FUNC7); // USB0 VBus Power
@@ -66,28 +67,51 @@ void board_init(void)
GPIO_ClearValue(5, BIT_(18));
+ //------------- I2C (required by LED) -------------//
// init I2C and set up MIC2555 to have 15k pull-down on USB1 D+ & D-
I2C_Init(LPC_I2C0, 100000);
I2C_Cmd(LPC_I2C0, ENABLE);
- pca9532_init(); // Leds Init
+ //------------- LED -------------//
+ pca9532_init();
// ASSERT_INT(0x058d, mic255_get_vendorid(), (void) 0); // verify vendor id
// ASSERT( mic255_regs_write(6, BIN8(1100)), (void) 0); // pull down D+/D- for host
#if CFG_UART_ENABLE
- //------------- UART init -------------//
- scu_pinmux(BOARD_UART_PIN_PORT, BOARD_UART_PIN_TX, MD_PDN , FUNC1);
- scu_pinmux(BOARD_UART_PIN_PORT, BOARD_UART_PIN_RX, MD_PLN|MD_EZI|MD_ZI, FUNC1);
+ //------------- UART -------------//
+ scu_pinmux(BOARD_UART_PIN_PORT, BOARD_UART_PIN_TX, MD_PDN, FUNC1);
+ scu_pinmux(BOARD_UART_PIN_PORT, BOARD_UART_PIN_RX, MD_PLN | MD_EZI | MD_ZI, FUNC1);
- UART_CFG_Type UARTConfigStruct;
+ UART_CFG_Type UARTConfigStruct;
UART_ConfigStructInit(&UARTConfigStruct);
- UARTConfigStruct.Baud_rate = CFG_UART_BAUDRATE;
- UARTConfigStruct.Clock_Speed = 0;
+ UARTConfigStruct.Baud_rate = CFG_UART_BAUDRATE;
+ UARTConfigStruct.Clock_Speed = 0;
- UART_Init(BOARD_UART_PORT, &UARTConfigStruct);
- UART_TxCmd(BOARD_UART_PORT, ENABLE); // Enable UART Transmit
+ UART_Init(BOARD_UART_PORT, &UARTConfigStruct);
+ UART_TxCmd(BOARD_UART_PORT, ENABLE); // Enable UART Transmit
#endif
+
+#if 0
+ //------------- Ethernet -------------//
+ LPC_CREG->CREG6 &= ~0x7;
+
+ /* RMII mode setup only */
+ LPC_CREG->CREG6 |= 0x4;
+
+ scu_pinmux(0x1, 18, (MD_EHS | MD_PLN | MD_ZI) , FUNC3); // ENET TXD0
+ scu_pinmux(0x1, 20, (MD_EHS | MD_PLN | MD_ZI) , FUNC3); // ENET TXD1
+ scu_pinmux(0x0, 1 , (MD_EHS | MD_PLN | MD_ZI) , FUNC6); // ENET TX Enable
+
+ scu_pinmux(0x1, 15, (MD_EHS | MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET RXD0
+ scu_pinmux(0x0, 0 , (MD_EHS | MD_PLN | MD_EZI | MD_ZI), FUNC2); // ENET RXD1
+ scu_pinmux(0x1, 16, (MD_EHS | MD_PLN | MD_EZI | MD_ZI), FUNC7); // ENET RX Data Valid
+
+ scu_pinmux(0x1, 19, (MD_EHS | MD_PLN | MD_EZI | MD_ZI), FUNC0); // ENET REF CLK
+ scu_pinmux(0x1, 17, (MD_EHS | MD_PLN | MD_EZI | MD_ZI), FUNC3); // ENET MDIO
+ scu_pinmux(0xC, 1 , (MD_EHS | MD_PLN | MD_ZI) , FUNC3); // ENET MDC
+#endif
+
}
//--------------------------------------------------------------------+
diff --git a/demos/bsp/boards/embedded_artists/board_ea4357.h b/demos/bsp/boards/embedded_artists/board_ea4357.h
index 138e6e19..0cef1735 100644
--- a/demos/bsp/boards/embedded_artists/board_ea4357.h
+++ b/demos/bsp/boards/embedded_artists/board_ea4357.h
@@ -66,8 +66,8 @@
#include "oem_base_board/pca9532.h" // LEDs
-#define CFG_PRINTF_TARGET PRINTF_TARGET_SWO
-//#define CFG_PRINTF_TARGET PRINTF_TARGET_UART
+//#define CFG_PRINTF_TARGET PRINTF_TARGET_SWO
+#define CFG_PRINTF_TARGET PRINTF_TARGET_UART
/*=========================================================================
HARDWARE MAC ADDRESS
diff --git a/demos/host/host_freertos/.cproject b/demos/host/host_freertos/.cproject
index 68cd0b2e..f8c6f115 100644
--- a/demos/host/host_freertos/.cproject
+++ b/demos/host/host_freertos/.cproject
@@ -89,8 +89,8 @@
-
-
+
+
@@ -754,8 +754,8 @@
-
-
+
+
diff --git a/demos/host/host_freertos/lwipopts.h b/demos/host/host_freertos/lwipopts.h
index 9f3e4f49..96758296 100644
--- a/demos/host/host_freertos/lwipopts.h
+++ b/demos/host/host_freertos/lwipopts.h
@@ -49,7 +49,7 @@
/* the number of buffers in the pbuf pool. In zero-copy mode, these buffers are
located in peripheral RAM. In copied mode, they are located in internal IRAM */
-#define PBUF_POOL_SIZE 7
+#define PBUF_POOL_SIZE 5
#define ETH_PAD_SIZE 0
@@ -77,18 +77,18 @@
#define LWIP_PLATFORM_BYTESWAP 0
/* Non-static memory, used with DMA pool */
-#define MEM_SIZE (12 * 1024)
+#define MEM_SIZE (6 * 1024)
//--------------------------------------------------------------------+
// Protocols
//--------------------------------------------------------------------+
-#define LWIP_RAW 1
-#define LWIP_DHCP 1
+#define LWIP_RAW 0
+#define LWIP_DHCP 0
#define LWIP_SNMP 0
#define LWIP_IGMP 0
#define LWIP_DNS 0
-#define LWIP_UDP 1
+#define LWIP_UDP 0
#define LWIP_TCP 1
/* Hostname can be used */
@@ -103,9 +103,13 @@
#define TCP_MSS 1460
#define TCP_SND_BUF (2 * TCP_MSS)
+//--------------------------------------------------------------------+
+// API
+//--------------------------------------------------------------------+
#define LWIP_SOCKET 0
-#define LWIP_NETCONN 0
-#define MEMP_NUM_SYS_TIMEOUT 300 // FIXME check settings
+#define LWIP_NETCONN 1
+
+#define MEMP_NUM_SYS_TIMEOUT 100 // FIXME check settings
//--------------------------------------------------------------------+
// Statistics options
@@ -117,35 +121,38 @@
//--------------------------------------------------------------------+
// DEBUG options
//--------------------------------------------------------------------+
+#define LWIP_DEBUG
+
/* There are more *_DEBUG options that can be selected.
See opts.h. Make sure that LWIP_DEBUG is defined when
building the code to use debug. */
-#define TCP_DEBUG LWIP_DBG_OFF
+#define TCP_DEBUG LWIP_DBG_TRACE
#define ETHARP_DEBUG LWIP_DBG_OFF
#define PBUF_DEBUG LWIP_DBG_OFF
-#define IP_DEBUG LWIP_DBG_OFF
+#define IP_DEBUG LWIP_DBG_TRACE
#define TCPIP_DEBUG LWIP_DBG_OFF
#define DHCP_DEBUG LWIP_DBG_OFF
#define UDP_DEBUG LWIP_DBG_OFF
/* This define is custom for the LPC EMAC driver. Enabled it to
get debug messages for the driver. */
-#define EMAC_DEBUG LWIP_DBG_OFF
+#define EMAC_DEBUG LWIP_DBG_TRACE
+#define UDP_LPC_EMAC LWIP_DBG_OFF
//--------------------------------------------------------------------+
// FreeRTOS
//--------------------------------------------------------------------+
#define DEFAULT_THREAD_PRIO (tskIDLE_PRIORITY + 1)
-#define DEFAULT_THREAD_STACKSIZE (512)
+#define DEFAULT_THREAD_STACKSIZE (256)
#define DEFAULT_ACCEPTMBOX_SIZE 6
#define DEFAULT_ACCEPTMBOX_SIZE 6
#define DEFAULT_TCP_RECVMBOX_SIZE 6
#define DEFAULT_UDP_RECVMBOX_SIZE 6
/* TCPIP thread must run at higher priority than MAC threads! */
-#define TCPIP_THREAD_PRIO (DEFAULT_THREAD_PRIO + configMAX_PRIORITIES - 1)
+#define TCPIP_THREAD_PRIO (configMAX_PRIORITIES - 1)
#define TCPIP_THREAD_STACKSIZE (512)
-#define TCPIP_MBOX_SIZE 6
+#define TCPIP_MBOX_SIZE 3
#endif /* __LWIPOPTS_H_ */
diff --git a/demos/host/host_os_none/.cproject b/demos/host/host_os_none/.cproject
index a77f84a2..bf2da444 100644
--- a/demos/host/host_os_none/.cproject
+++ b/demos/host/host_os_none/.cproject
@@ -82,7 +82,7 @@
-
+
@@ -1193,7 +1193,7 @@
-
+
@@ -2301,7 +2301,7 @@
-
+
@@ -3409,7 +3409,7 @@
-
+
@@ -4514,7 +4514,7 @@
-
+
diff --git a/demos/host/src/main.c b/demos/host/src/main.c
index ebbacfc4..ca26e633 100644
--- a/demos/host/src/main.c
+++ b/demos/host/src/main.c
@@ -64,6 +64,22 @@
__CRP const unsigned int CRP_WORD = CRP_NO_CRP ;
#endif
+#if 0
+#include "lwip/opt.h"
+#include "lwip/sys.h"
+#include "lwip/memp.h"
+#include "lwip/tcpip.h"
+#include "lwip/ip_addr.h"
+#include "lwip/netif.h"
+#include "lwip/timers.h"
+#include "netif/etharp.h"
+#if LWIP_DHCP
+#include "lwip/dhcp.h"
+#endif
+#include "../contrib/apps/httpserver/httpserver-netconn.h"
+#include "arch/lpc18xx_43xx_emac.h"
+#endif
+
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF
//--------------------------------------------------------------------+
@@ -75,7 +91,7 @@ OSAL_TASK_FUNCTION( led_blinking_task ) (void* p_task_para);
OSAL_TASK_DEF(led_blinking_task, 128, LED_BLINKING_APP_TASK_PRIO);
void print_greeting(void);
-static inline void wait_blocking_ms(uint32_t ms);
+//static inline void wait_blocking_ms(uint32_t ms);
//--------------------------------------------------------------------+
// IMPLEMENTATION
@@ -96,16 +112,11 @@ void os_none_start_scheduler(void)
}
#endif
-//TODO try to run with optimization Os
+
int main(void)
{
board_init();
-
- // TODO blocking wait --> systick handler --> ...... freeRTOS hardfault
- //wait_blocking_ms(1000); // wait a bit for power stable
-
- // print_greeting(); TODO uart output before freeRTOS scheduler start will lead to hardfault
- // find a way to fix this as tusb_init can output to uart when an error occurred
+ print_greeting();
tusb_init();
@@ -142,9 +153,7 @@ int main(void)
#error need to start RTOS schduler
#endif
- //------------- this part of code should not be reached -------------//
- hal_debugger_breakpoint();
- while(1) { }
+ while(1) { } // should not be reached here
return 0;
}
@@ -154,17 +163,14 @@ int main(void)
//--------------------------------------------------------------------+
OSAL_TASK_FUNCTION( led_blinking_task ) (void* p_task_para)
{
- {// task init, only executed exactly one time, real RTOS does not need this but none OS does
- static bool is_init = false;
- if (!is_init)
- {
- is_init = true;
- print_greeting();
- }
- }
-
static uint32_t led_on_mask = 0;
+ #if 0
+ // FIXME OSAL NONE problem, invoke only 1
+ network_init();
+ http_server_netconn_init();
+ #endif
+
OSAL_TASK_LOOP_BEGIN
osal_task_delay(1000);
@@ -189,14 +195,68 @@ void print_greeting(void)
);
}
-static inline void wait_blocking_us(volatile uint32_t us)
+//static inline void wait_blocking_us(volatile uint32_t us)
+//{
+// us *= (SystemCoreClock / 1000000) / 3;
+// while(us--);
+//}
+//
+//static inline void wait_blocking_ms(uint32_t ms)
+//{
+// wait_blocking_us(ms * 1000);
+//}
+
+#if 0
+static struct netif lpc_netif;
+
+/* Callback for TCPIP thread to indicate TCPIP init is done */
+static void tcpip_init_done_signal(void *arg)
{
- us *= (SystemCoreClock / 1000000) / 3;
- while(us--);
+ /* Tell main thread TCP/IP init is done */
+ *(uint32_t *) arg = 1;
}
-static inline void wait_blocking_ms(uint32_t ms)
+void network_init(void)
{
- wait_blocking_us(ms * 1000);
-}
+ ip_addr_t ipaddr, netmask, gw;
+ volatile uint32_t tcpip_init_done = 0;
+#if NO_SYS
+ lwip_init();
+#else
+ /* Wait until the TCP/IP thread is finished before
+ continuing or weird things may happen */
+ LWIP_DEBUGF(LWIP_DBG_ON, ("Waiting for TCPIP thread to initialize...\n"));
+ tcpip_init(tcpip_init_done_signal, (void*)&tcpip_init_done);
+ while (!tcpip_init_done);
+// tcpip_init(NULL, NULL);
+#endif
+
+ /* Static IP assignment */
+#if LWIP_DHCP
+ IP4_ADDR(&gw, 0, 0, 0, 0);
+ IP4_ADDR(&ipaddr, 0, 0, 0, 0);
+ IP4_ADDR(&netmask, 0, 0, 0, 0);
+#else
+ IP4_ADDR(&gw, 192, 168, 1, 1);
+ IP4_ADDR(&ipaddr, 192, 168, 1, 57);
+ IP4_ADDR(&netmask, 255, 255, 255, 0);
+#endif
+
+ /* Add netif interface for lpc18xx_43xx */
+ if (!netif_add(&lpc_netif, &ipaddr, &netmask, &gw, NULL, lpc_enetif_init,
+ tcpip_input))
+ LWIP_ASSERT("Net interface failed to initialize\r\n", 0);
+
+ netif_set_default(&lpc_netif);
+ netif_set_up(&lpc_netif);
+
+ /* Enable MAC interrupts only after LWIP is ready */
+ NVIC_SetPriority(ETHERNET_IRQn, ((0x01<<3)|0x01));
+ NVIC_EnableIRQ(ETHERNET_IRQn);
+
+#if LWIP_DHCP
+ dhcp_start(&lpc_netif);
+#endif
+}
+#endif
diff --git a/vendor/freertos/lpc43xx_m4_FreeRTOSConfig.h b/vendor/freertos/lpc43xx_m4_FreeRTOSConfig.h
index 6ab560ff..3669230b 100644
--- a/vendor/freertos/lpc43xx_m4_FreeRTOSConfig.h
+++ b/vendor/freertos/lpc43xx_m4_FreeRTOSConfig.h
@@ -58,6 +58,7 @@
#include "LPC43xx.h"
#include "core_cm4.h"
#include "lpc43xx_cgu.h"
+#include "hal/hal.h"
/*-----------------------------------------------------------
* Application specific definitions.