From 2b930943e6e784b914aa3bad40c6c84e80fe970d Mon Sep 17 00:00:00 2001 From: Juan Manuel Cruz Date: Tue, 13 Jun 2017 22:05:31 -0300 Subject: [PATCH] USE_DEBUG for LPC43337_m4 MCU (1) --- etc/ld/lpc4337_m4_semihost_lib.ld | 15 ++++ etc/target/lpc4337_m4.mk | 14 +++- examples/blinky_debug/Makefile | 48 ++++++++++++ examples/blinky_debug/inc/main.h | 75 ++++++++++++++++++ examples/blinky_debug/src/main.c | 109 +++++++++++++++++++++++++++ modules/lpc4337_m4/board/inc/board.h | 4 +- modules/lpc4337_m4/board/src/board.c | 8 +- project.mk.template | 6 +- 8 files changed, 272 insertions(+), 7 deletions(-) create mode 100644 etc/ld/lpc4337_m4_semihost_lib.ld create mode 100644 examples/blinky_debug/Makefile create mode 100644 examples/blinky_debug/inc/main.h create mode 100644 examples/blinky_debug/src/main.c diff --git a/etc/ld/lpc4337_m4_semihost_lib.ld b/etc/ld/lpc4337_m4_semihost_lib.ld new file mode 100644 index 0000000..3f48e36 --- /dev/null +++ b/etc/ld/lpc4337_m4_semihost_lib.ld @@ -0,0 +1,15 @@ +/* + * GENERATED FILE - DO NOT EDIT + * (c) Code Red Technologies Ltd, 2008-13 + * (c) NXP Semiconductors 2013-2015 + * Generated linker script file for LPC4337 + * Created from LibIncTemplate.ld (LPCXpresso v7.6 (2 [Build 326] [2015-02-02] )) + * By LPCXpresso v7.6.2 [Build 326] [2015-02-02] on Wed Aug 26 15:59:13 ART 2015 + */ + + + GROUP( + libcr_nohost.a + libcr_c.a + libcr_eabihelpers.a + ) diff --git a/etc/target/lpc4337_m4.mk b/etc/target/lpc4337_m4.mk index 5d8f9a0..0dd2b13 100644 --- a/etc/target/lpc4337_m4.mk +++ b/etc/target/lpc4337_m4.mk @@ -57,12 +57,22 @@ LFLAGS := -nostdlib -fno-builtin -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 \ -Wl,--gc-sections # Linker scripts -ifndef LINK_RAM -LD_FILE := -Tetc/ld/lpc4337_m4_lib.ld -Tetc/ld/lpc4337_m4_mem.ld \ +ifdef USE_DEBUG +LD_FILE := -Tetc/ld/lpc4337_m4_semihost_lib.ld -Tetc/ld/lpc4337_m4_mem.ld \ -Tetc/ld/lpc4337_m4.ld else +ifdef USE_SEMIHOSTING +LD_FILE := -Tetc/ld/lpc4337_m4_semihost_lib.ld -Tetc/ld/lpc4337_m4_mem.ld \ + -Tetc/ld/lpc4337_m4.ld +else +ifdef LINK_RAM LD_FILE := -Tetc/ld/lpc4337_m4_lib.ld -Tetc/ld/lpc4337_m4_mem.ld \ -Tetc/ld/lpc4337_m4_RAM.ld +else +LD_FILE := -Tetc/ld/lpc4337_m4_lib.ld -Tetc/ld/lpc4337_m4_mem.ld \ + -Tetc/ld/lpc4337_m4.ld +endif +endif endif # OpenOCD configuration file diff --git a/examples/blinky_debug/Makefile b/examples/blinky_debug/Makefile new file mode 100644 index 0000000..9e20b67 --- /dev/null +++ b/examples/blinky_debug/Makefile @@ -0,0 +1,48 @@ +# Copyright 2016, Pablo Ridolfi +# All rights reserved. +# +# This file is part of Workspace. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +# application name +PROJECT_NAME := $(notdir $(PROJECT)) + +# Modules needed by the application +PROJECT_MODULES := modules/$(TARGET)/base \ + modules/$(TARGET)/board \ + modules/$(TARGET)/chip + +# source files folder +PROJECT_SRC_FOLDERS := $(PROJECT)/src + +# header files folder +PROJECT_INC_FOLDERS := $(PROJECT)/inc + +# source files +PROJECT_C_FILES := $(wildcard $(PROJECT)/src/*.c) +PROJECT_ASM_FILES := $(wildcard $(PROJECT)/src/*.S) diff --git a/examples/blinky_debug/inc/main.h b/examples/blinky_debug/inc/main.h new file mode 100644 index 0000000..d70e037 --- /dev/null +++ b/examples/blinky_debug/inc/main.h @@ -0,0 +1,75 @@ +/* Copyright 2016, Pablo Ridolfi + * All rights reserved. + * + * This file is part of Workspace. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef _MAIN_H_ +#define _MAIN_H_ + +/** \addtogroup blink Bare-metal blink example + ** @{ */ + +/*==================[inclusions]=============================================*/ + +/*==================[cplusplus]==============================================*/ + +#ifdef __cplusplus +extern "C" { +#endif + +/*==================[macros]=================================================*/ + +/** delay in milliseconds */ +#define DELAY_MS 500 + +/** led number to toggle */ +#define LED 0 + +/*==================[typedef]================================================*/ + +/*==================[external data declaration]==============================*/ + +/*==================[external functions declaration]=========================*/ + +/** @brief main function + * @return main function should never return + */ +int main(void); + +/*==================[cplusplus]==============================================*/ + +#ifdef __cplusplus +} +#endif + +/** @} doxygen end group definition */ +/*==================[end of file]============================================*/ +#endif /* #ifndef _MAIN_H_ */ diff --git a/examples/blinky_debug/src/main.c b/examples/blinky_debug/src/main.c new file mode 100644 index 0000000..099cabb --- /dev/null +++ b/examples/blinky_debug/src/main.c @@ -0,0 +1,109 @@ +/* Copyright 2016, Pablo Ridolfi + * All rights reserved. + * + * This file is part of Workspace. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +/** @brief This is a simple blink example. + */ + +/** \addtogroup blink Bare-metal blink example + ** @{ */ + +/*==================[inclusions]=============================================*/ + +#include "main.h" +#include "board.h" + +/*==================[macros and definitions]=================================*/ + +/*==================[internal data declaration]==============================*/ + +/*==================[internal functions declaration]=========================*/ + +/** @brief hardware initialization function + * @return none + */ +static void initHardware(void); + +/** @brief delay function + * @param t desired milliseconds to wait + */ +static void pausems(uint32_t t); + +/*==================[internal data definition]===============================*/ + +/** @brief used for delay counter */ +static uint32_t pausems_count; + +static char WelcomeMenu[] = "\r\nHello - DEBUG DEMO \r\n"; +/*==================[external data definition]===============================*/ + +/*==================[internal functions definition]==========================*/ + +static void initHardware(void) +{ + Board_Init(); + SystemCoreClockUpdate(); + SysTick_Config(SystemCoreClock / 1000); +} + +static void pausems(uint32_t t) +{ + pausems_count = t; + while (pausems_count != 0) { + __WFI(); + } +} + +/*==================[external functions definition]==========================*/ + +void SysTick_Handler(void) +{ + if(pausems_count > 0) pausems_count--; +} + +int main(void) +{ + initHardware(); + + DEBUGOUT(WelcomeMenu); + while (1) + { + Board_LED_Toggle(LED); + pausems(DELAY_MS); + + DEBUGOUT("\r\nDEBUG DEMO running!"); + } +} + +/** @} doxygen end group definition */ + +/*==================[end of file]============================================*/ diff --git a/modules/lpc4337_m4/board/inc/board.h b/modules/lpc4337_m4/board/inc/board.h index fda535f..fbae0e0 100644 --- a/modules/lpc4337_m4/board/inc/board.h +++ b/modules/lpc4337_m4/board/inc/board.h @@ -56,7 +56,7 @@ extern "C" { DEBUGIN macros. If not defined, DEBUG* functions will be optimized out of the code at build time. */ -//#define DEBUG_ENABLE +#define DEBUG_ENABLE /** Define DEBUG_SEMIHOSTING along with DEBUG_ENABLE to enable IO support via semihosting. You may need to use a C library that supports @@ -67,7 +67,7 @@ extern "C" { /** Board UART used for debug output and input using the DEBUG* macros. This is also the port used for Board_UARTPutChar, Board_UARTGetChar, and Board_UARTPutSTR functions. */ -#define DEBUG_UART LPC_USART0 +#define DEBUG_UART LPC_USART2 /** * @} diff --git a/modules/lpc4337_m4/board/src/board.c b/modules/lpc4337_m4/board/src/board.c index 3743330..748e829 100644 --- a/modules/lpc4337_m4/board/src/board.c +++ b/modules/lpc4337_m4/board/src/board.c @@ -47,20 +47,24 @@ typedef struct { } io_port_t; static const io_port_t gpioLEDBits[] = {{5,0},{5,1},{5,2},{0,14},{1,11},{1,12}}; -static uint32_t lcd_cfg_val; static const io_port_t gpioBtnBits[] = {{0,4},{0,8},{0,9},{1,9}}; static const uint8_t gpioBtnIDs[] = {TEC1_PRESSED, TEC2_PRESSED, TEC3_PRESSED, TEC4_PRESSED}; void Board_UART_Init(LPC_USART_T *pUART) { if (pUART == LPC_USART0) { - Chip_SCU_PinMuxSet(0x6, 4, (SCU_MODE_PULLDOWN | SCU_MODE_FUNC2)); /* P6.5 : UART0_TXD */ + Chip_SCU_PinMuxSet(0x6, 4, (SCU_MODE_PULLDOWN | SCU_MODE_FUNC2)); /* P6.5 : UART0_TXD */ Chip_SCU_PinMuxSet(0x6, 5, (SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC2));/* P6.4 : UART0_RXD */ } else if (pUART == LPC_UART1) { Chip_SCU_PinMuxSet(0x1, 13, (SCU_MODE_PULLDOWN | SCU_MODE_FUNC2)); /* P1.13 : UART1_TXD */ Chip_SCU_PinMuxSet(0x1, 14, (SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC2)); /* P1.14 : UART1_RX */ } + else if (pUART == LPC_USART2) { + Chip_SCU_PinMuxSet(0x7, 1, (SCU_MODE_INACT | SCU_MODE_FUNC6)); /* P7.1 : UART2_TXD */ + Chip_SCU_PinMuxSet(0x7, 2, (SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC6));/* P7.2 : UART2_RXD */ + } + } /* Initialize debug output via UART for board */ diff --git a/project.mk.template b/project.mk.template index 5d80624..211f0ec 100644 --- a/project.mk.template +++ b/project.mk.template @@ -35,6 +35,7 @@ # current project PROJECT = examples/blinky +#PROJECT = examples/blinky_debug #PROJECT = examples/blinky_rit #PROJECT = examples/adc_fir_dac #PROJECT = examples/freertos_blinky @@ -57,5 +58,8 @@ BOARD = edu_ciaa_nxp # you need to add an lpc54102_m0 program). For example: #SLAVE_OBJ_FILE = out/lpc54102_m0/blinky_m0.axf.o +# If you want to use debug libraries (LPCXpresso) then define +#USE_DEBUG = 1 + # If you want to use semihosting libraries (LPCXpresso) then define -# USE_SEMIHOSTING = 1 +#USE_SEMIHOSTING = 1