Commit b39e30fb authored by Deomid Ryabkov's avatar Deomid Ryabkov Committed by Cesanta Bot

Example LPCXpresso project for NXP LPC4088

PUBLISHED_FROM=ec4c4ec1ca7fee10c67fbba5a603d59fe44a046d
parent 92b15395
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
# `wildcard ./*/` works in both linux and linux/wine, while `wildcard */` enumerates nothing under wine # `wildcard ./*/` works in both linux and linux/wine, while `wildcard */` enumerates nothing under wine
SUBDIRS = $(sort $(dir $(wildcard ./*/))) SUBDIRS = $(sort $(dir $(wildcard ./*/)))
SUBDIRS:=$(filter-out ./ ./CC3200/ ./ESP8266_RTOS/ ./MSP432/ ./NXP_K64/ ./PIC32/ ./STM32F4_CC3100/ ./mbed/ ./nRF51/ ./nRF52/, $(SUBDIRS)) SUBDIRS:=$(filter-out ./ ./CC3200/ ./ESP8266_RTOS/ ./MSP432/ ./NXP_LPC4088/ ./NXP_K64/ ./PIC32/ ./STM32F4_CC3100/ ./mbed/ ./nRF51/ ./nRF52/, $(SUBDIRS))
ifeq ($(OS), Windows_NT) ifeq ($(OS), Windows_NT)
SUBDIRS:=$(filter-out ./netcat/ ./raspberry_pi_mjpeg_led/ ./captive_dns_server/, $(SUBDIRS)) SUBDIRS:=$(filter-out ./netcat/ ./raspberry_pi_mjpeg_led/ ./captive_dns_server/, $(SUBDIRS))
......
Please download the [LPCOpen QSB SDK](https://www.embeddedartists.com/sites/default/files/support/qsb/lpc4088/lpcopen_2_10_lpcxpresso_arm_university_4088qsb.zip) and unpack it into this directory.
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Mongoose_LPC4088_QSB_BM</name>
<comment></comment>
<projects>
<project>lpc_chip_40xx</project>
<project>lpc_board_ea_devkit_4088</project>
<project>webserver</project>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
<linkedResources>
<link>
<name>lwip</name>
<type>2</type>
<locationURI>LWIP_PATH</locationURI>
</link>
<link>
<name>example/src/mongoose.c</name>
<type>1</type>
<location>$%7BPARENT-4-PROJECT_LOC%7D/mongoose.c</location>
</link>
</linkedResources>
<variableList>
<variable>
<name>LWIP_PATH</name>
<value>$%7BSDK_PATH%7D/webserver/lwip</value>
</variable>
<variable>
<name>SDK_PATH</name>
<value>$%7BPARENT-2-PROJECT_LOC%7D/LPCOpen_QSB</value>
</variable>
</variableList>
</projectDescription>
/* clang-format off */
/*
* @brief LPC17xx/LPC40xx EMAC and PHY driver configuration file for LWIP
*
* @note
* Copyright(C) NXP Semiconductors, 2012
* All rights reserved.
*
* @par
* Software that is described herein is for illustrative purposes only
* which provides customers with programming information regarding the
* LPC products. This software is supplied "AS IS" without any warranties of
* any kind, and NXP Semiconductors and its licensor disclaim any and
* all warranties, express or implied, including all implied warranties of
* merchantability, fitness for a particular purpose and non-infringement of
* intellectual property rights. NXP Semiconductors assumes no responsibility
* or liability for the use of the software, conveys no license or rights under any
* patent, copyright, mask work right, or any other intellectual property rights in
* or to any products. NXP Semiconductors reserves the right to make changes
* in the software without notification. NXP Semiconductors also makes no
* representation or warranty that such application will be suitable for the
* specified use without further testing or modification.
*
* @par
* Permission to use, copy, modify, and distribute this software and its
* documentation is hereby granted, under NXP Semiconductors' and its
* licensor's relevant copyrights in the software, without fee, provided that it
* is used in conjunction with NXP Semiconductors microcontrollers. This
* copyright, permission, and disclaimer notice must appear in all copies of
* this code.
*/
#ifndef __LPC_17XX40XX_EMAC_CONFIG_H_
#define __LPC_17XX40XX_EMAC_CONFIG_H_
#include "lwip/opt.h"
#ifdef __cplusplus
extern "C"
{
#endif
/* The PHY address connected the to MII/RMII */
#define LPC_PHYDEF_PHYADDR 1
/* Autonegotiation mode enable flag */
#define PHY_USE_AUTONEG 1
/* PHY interface full duplex operation or half duplex enable flag.
Only applies if PHY_USE_AUTONEG = 0 */
#define PHY_USE_FULL_DUPLEX 1
/* PHY interface 100MBS or 10MBS enable flag.
Only applies if PHY_USE_AUTONEG = 0 */
#define PHY_USE_100MBS 1
/* Defines the number of descriptors used for RX */
#define LPC_NUM_BUFF_RXDESCS 4
/* Defines the number of descriptors used for TX */
#define LPC_NUM_BUFF_TXDESCS 4
/* Disable slow speed memory buffering */
#define LPC_CHECK_SLOWMEM 0
/* Array of slow memory address ranges for LPC_CHECK_SLOWMEM */
#define LPC_SLOWMEM_ARRAY
#ifdef __cplusplus
}
#endif
#endif /* __LPC_17XX40XX_EMAC_CONFIG_H_ */
/* clang-format off */
/*
* @brief LWIP build option override file
*
* @note
* Copyright(C) NXP Semiconductors, 2012
* All rights reserved.
*
* @par
* Software that is described herein is for illustrative purposes only
* which provides customers with programming information regarding the
* LPC products. This software is supplied "AS IS" without any warranties of
* any kind, and NXP Semiconductors and its licensor disclaim any and
* all warranties, express or implied, including all implied warranties of
* merchantability, fitness for a particular purpose and non-infringement of
* intellectual property rights. NXP Semiconductors assumes no responsibility
* or liability for the use of the software, conveys no license or rights under any
* patent, copyright, mask work right, or any other intellectual property rights in
* or to any products. NXP Semiconductors reserves the right to make changes
* in the software without notification. NXP Semiconductors also makes no
* representation or warranty that such application will be suitable for the
* specified use without further testing or modification.
*
* @par
* Permission to use, copy, modify, and distribute this software and its
* documentation is hereby granted, under NXP Semiconductors' and its
* licensor's relevant copyrights in the software, without fee, provided that it
* is used in conjunction with NXP Semiconductors microcontrollers. This
* copyright, permission, and disclaimer notice must appear in all copies of
* this code.
*/
#ifndef __LWIPOPTS_H_
#define __LWIPOPTS_H_
/* Standalone build */
#define NO_SYS 1
//#define LWIP_DEBUG 1
#define LPC_TX_PBUF_BOUNCE_EN 1
//#define HTTPD_DEBUG LWIP_DBG_ON
/* Use LWIP timers */
#define NO_SYS_NO_TIMERS 0
#define LWIP_HTTPD_DYNAMIC_HEADERS 1
/* Need for memory protection */
#define SYS_LIGHTWEIGHT_PROT 0
/* 32-bit alignment */
#define MEM_ALIGNMENT 4
/* pbuf buffers in 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
/* No padding needed */
#define ETH_PAD_SIZE 0
#define IP_SOF_BROADCAST 1
#define IP_SOF_BROADCAST_RECV 1
/* The ethernet FCS is performed in hardware. The IP, TCP, and UDP
CRCs still need to be done in hardware. */
#define CHECKSUM_GEN_IP 1
#define CHECKSUM_GEN_UDP 1
#define CHECKSUM_GEN_TCP 1
#define CHECKSUM_CHECK_IP 1
#define CHECKSUM_CHECK_UDP 1
#define CHECKSUM_CHECK_TCP 1
#define LWIP_CHECKSUM_ON_COPY 1
/* Use LWIP version of htonx() to allow generic functionality across
all platforms. If you are using the Cortex Mx devices, you might
be able to use the Cortex __rev instruction instead. */
#define LWIP_PLATFORM_BYTESWAP 0
/* Non-static memory, used with DMA pool */
#define MEM_SIZE (12 * 1024)
/* Raw interface not needed */
#define LWIP_RAW 1
/* DHCP is ok, UDP is required with DHCP */
#define LWIP_DHCP 1
#define LWIP_UDP 1
/* Hostname can be used */
#define LWIP_NETIF_HOSTNAME 1
#define LWIP_BROADCAST_PING 1
/* MSS should match the hardware packet size */
#define TCP_MSS 1460
#define TCP_SND_BUF (2 * TCP_MSS)
#define LWIP_SOCKET 0
#define LWIP_NETCONN 0
#define MEMP_NUM_SYS_TIMEOUT 300
#define LWIP_STATS 0
#define LINK_STATS 0
#define LWIP_STATS_DISPLAY 0
/* 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 ETHARP_DEBUG LWIP_DBG_OFF
#define PBUF_DEBUG LWIP_DBG_OFF
#define IP_DEBUG LWIP_DBG_OFF
#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 MEM_LIBC_MALLOC 1
#define MEMP_MEM_MALLOC 1
/* Needed for malloc/free */
#include <stdlib.h>
#endif /* __LWIPOPTS_H_ */
Mongoose Web Server example without an RTOS
===========================================
This project sets up a simple Web server using the Mongoose Web Server and
Networking library.
This project depends on lpc_chip_40xx and lpc_board_ea_devkit_4088 (for
drivers) and the webserver example project (for LWIP).
/*
* Copyright (c) 2014-2016 Cesanta Software Limited
* All rights reserved
*/
#include "mongoose.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "lwip/dhcp.h"
#include "lwip/init.h"
#include "lwip/netif.h"
#include "lwip/raw.h"
#include "lwip/timers.h"
#include "netif/etharp.h"
#include "board.h"
#include "lpc_phy.h"
#include "arch/lpc17xx_40xx_emac.h"
#include "arch/lpc_arch.h"
/* IP address configuration. */
#define USE_DHCP 1 /* For static IP, set to 0 and configure options below */
#if !USE_DHCP
#define STATIC_IP "192.168.0.111"
#define STATIC_NM "255.255.255.0"
#define STATIC_GW "192.168.0.1"
#endif
void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
if (ev == MG_EV_POLL) return;
/* printf("ev %d\r\n", ev); */
switch (ev) {
case MG_EV_ACCEPT: {
char addr[32];
mg_sock_addr_to_str(&nc->sa, addr, sizeof(addr),
MG_SOCK_STRINGIFY_IP | MG_SOCK_STRINGIFY_PORT);
printf("%p: Connection from %s\r\n", nc, addr);
break;
}
case MG_EV_HTTP_REQUEST: {
struct http_message *hm = (struct http_message *) ev_data;
char addr[32];
mg_sock_addr_to_str(&nc->sa, addr, sizeof(addr),
MG_SOCK_STRINGIFY_IP | MG_SOCK_STRINGIFY_PORT);
printf("%p: %.*s %.*s\r\n", nc, (int) hm->method.len, hm->method.p,
(int) hm->uri.len, hm->uri.p);
mg_send_response_line(nc, 200,
"Content-Type: text/html\r\n"
"Connection: close");
mg_printf(nc,
"\r\n<h1>Hello, %s!</h1>\r\n"
"You asked for %.*s\r\n",
addr, (int) hm->uri.len, hm->uri.p);
nc->flags |= MG_F_SEND_AND_CLOSE;
Board_LED_Toggle(2);
break;
}
case MG_EV_CLOSE: {
printf("%p: Connection closed\r\n", nc);
break;
}
}
}
void handle_eth(struct netif *eth_if) {
/* PHY link status. */
uint32_t status = lpcPHYStsPoll();
if (status & PHY_LINK_CHANGED) {
if (status & PHY_LINK_CONNECTED) {
Board_LED_Set(0, true);
if (status & PHY_LINK_SPEED100) {
Chip_ENET_Set100Mbps(LPC_ETHERNET);
} else {
Chip_ENET_Set10Mbps(LPC_ETHERNET);
}
if (status & PHY_LINK_FULLDUPLX) {
Chip_ENET_SetFullDuplex(LPC_ETHERNET);
} else {
Chip_ENET_SetHalfDuplex(LPC_ETHERNET);
}
netif_set_link_up(eth_if);
printf("Link up\r\n");
} else {
Board_LED_Set(0, false);
Board_LED_Set(1, false);
netif_set_link_down(eth_if);
printf("Link down\r\n");
}
}
/* Handle packets as part of this loop, not in the IRQ handler */
lpc_enetif_input(eth_if);
/* Free TX buffers that are done sending */
lpc_tx_reclaim(eth_if);
}
int gettimeofday(struct timeval *tv, void *tzvp) {
tv->tv_sec = time(NULL);
tv->tv_usec = 0;
return 0;
}
/*
* This is a callback invoked by Mongoose to signal that a poll is needed soon.
* Since we're in a tight polling loop anyway (see below), we don't need to do
* anything.
*/
void mg_lwip_mgr_schedule_poll(struct mg_mgr *mgr) {
}
int main(void) {
struct netif eth0;
SystemCoreClockUpdate();
Board_Init();
SysTick_Enable(1);
lwip_init();
Board_LED_Set(0, false); /* Link state */
Board_LED_Set(1, false); /* DHCP state */
Board_LED_Set(2, false); /* HTTP request activity indicator */
Board_LED_Set(3, false); /* Error indicator */
#if USE_DHCP
netif_add(&eth0, NULL, NULL, NULL, NULL, lpc_enetif_init, ethernet_input);
printf("Waiting for DHCP...\r\n");
dhcp_start(&eth0);
u8_t os = 0xff, ds;
do {
ds = eth0.dhcp->state;
if (ds != os) {
printf(" DHCP state: %d\r\n", ds);
os = ds;
}
handle_eth(&eth0);
sys_check_timeouts();
} while (ds != DHCP_BOUND);
printf("DHCP bound.\r\n");
#else
ip_addr_t ip, nm, gw;
if (!ipaddr_aton(STATIC_IP, &ip) || !ipaddr_aton(STATIC_NM, &nm) ||
!ipaddr_aton(STATIC_GW, &gw)) {
printf("Invalid static IP configuration.\r\n");
Board_LED_Set(3, true);
return 1;
} else {
netif_add(&eth0, &ip, &nm, &gw, NULL, lpc_enetif_init, ethernet_input);
netif_set_up(&eth0);
}
#endif
netif_set_default(&eth0);
printf("Setting up HTTP server...\r\n");
struct mg_mgr mgr;
mg_mgr_init(&mgr, NULL);
const char *err;
struct mg_bind_opts opts = {};
opts.error_string = &err;
struct mg_connection *nc = mg_bind_opt(&mgr, "80", ev_handler, opts);
if (nc == NULL) {
printf("Failed to create listener: %s\r\n", err);
Board_LED_Set(3, true);
return 1;
}
mg_set_protocol_http_websocket(nc);
printf("Server address: http://%s/\r\n", ipaddr_ntoa(&eth0.ip_addr));
while (1) {
/* Ethernet link status, low level input. */
handle_eth(&eth0);
/* LWIP timers - ARP, DHCP, TCP, etc. */
sys_check_timeouts();
/* Mongoose poll */
mg_mgr_poll(&mgr, 0);
}
return 0;
}
/* clang-format off */
/*
* @brief Common SystemInit function for LPC17xx/40xx chips
*
* @note
* Copyright(C) NXP Semiconductors, 2013
* All rights reserved.
*
* @par
* Software that is described herein is for illustrative purposes only
* which provides customers with programming information regarding the
* LPC products. This software is supplied "AS IS" without any warranties of
* any kind, and NXP Semiconductors and its licensor disclaim any and
* all warranties, express or implied, including all implied warranties of
* merchantability, fitness for a particular purpose and non-infringement of
* intellectual property rights. NXP Semiconductors assumes no responsibility
* or liability for the use of the software, conveys no license or rights under any
* patent, copyright, mask work right, or any other intellectual property rights in
* or to any products. NXP Semiconductors reserves the right to make changes
* in the software without notification. NXP Semiconductors also makes no
* representation or warranty that such application will be suitable for the
* specified use without further testing or modification.
*
* @par
* Permission to use, copy, modify, and distribute this software and its
* documentation is hereby granted, under NXP Semiconductors' and its
* licensor's relevant copyrights in the software, without fee, provided that it
* is used in conjunction with NXP Semiconductors microcontrollers. This
* copyright, permission, and disclaimer notice must appear in all copies of
* this code.
*/
#include "board.h"
/*****************************************************************************
* Private types/enumerations/variables
****************************************************************************/
/*****************************************************************************
* Public types/enumerations/variables
****************************************************************************/
/*****************************************************************************
* Private functions
****************************************************************************/
/*****************************************************************************
* Public functions
****************************************************************************/
/* Set up and initialize hardware prior to call to main */
void SystemInit(void)
{
unsigned int *pSCB_VTOR = (unsigned int *) 0xE000ED08;
#if defined(__IAR_SYSTEMS_ICC__)
extern void *__vector_table;
*pSCB_VTOR = (unsigned int) &__vector_table;
#elif defined(__CODE_RED)
extern void *g_pfnVectors;
*pSCB_VTOR = (unsigned int) &g_pfnVectors;
#elif defined(__ARMCC_VERSION)
extern void *__Vectors;
*pSCB_VTOR = (unsigned int) &__Vectors;
#endif
#if defined(__FPU_PRESENT) && __FPU_PRESENT == 1
fpuInit();
#endif
#if defined(NO_BOARD_LIB)
/* Chip specific SystemInit */
Chip_SystemInit();
#else
/* Setup system clocking and muxing */
Board_SystemInit();
#endif
}
Mongoose Web Server example without an RTOS
===========================================
This project sets up a simple Web server using the Mongoose Web Server and
Networking library.
This project is based on the [LPC4088 QuickStart Board](https://www.embeddedartists.com/products/boards/lpc4088_qsb.php) from Embedded Artists.
Please download the [modified LPCOpen SDK](https://www.embeddedartists.com/sites/default/files/support/qsb/lpc4088/lpcopen_2_10_lpcxpresso_arm_university_4088qsb.zip)
and unpack it into the `LPCOpen_QSB` directory.
This project depends on `lpc_chip_40xx` and `lpc_board_ea_devkit_4088` (for drivers)
and the `webserver` example project (for LWIP). Please import them along with this project.
By default, the project uses DHCP to obtain an IP address.
If you want to configure a static IP address, please edit the settings at the top of `example/src/main.c`.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment