root: init project

Adding basic board repos, main
This commit is contained in:
Vasily Davydov
2022-09-14 11:05:10 +03:00
parent 930c9a508b
commit 25545eb2ea
125 changed files with 27444 additions and 0 deletions

View File

@@ -0,0 +1,198 @@
/*
* @brief LPCXPresso LPC1549 board file
*
* @note
* Copyright(C) NXP Semiconductors, 2014
* 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"
#include "retarget.h"
/*****************************************************************************
* Private types/enumerations/variables
****************************************************************************/
/*****************************************************************************
* Public types/enumerations/variables
****************************************************************************/
/* System oscillator rate and RTC oscillator rate */
const uint32_t OscRateIn = 12000000;
const uint32_t RTCOscRateIn = 32768;
/*****************************************************************************
* Private functions
****************************************************************************/
/*****************************************************************************
* Public functions
****************************************************************************/
/* Sends a character on the UART */
void Board_UARTPutChar(char ch)
{
#if defined(DEBUG_UART)
Chip_UART_SendBlocking(DEBUG_UART, &ch, 1);
#endif
}
/* Gets a character from the UART, returns EOF if no character is ready */
int Board_UARTGetChar(void)
{
#if defined(DEBUG_UART)
uint8_t data;
if (Chip_UART_Read(DEBUG_UART, &data, 1) == 1) {
return (int) data;
}
#endif
return EOF;
}
/* Outputs a string on the debug UART */
void Board_UARTPutSTR(const char *str)
{
#if defined(DEBUG_UART)
while (*str != '\0') {
Board_UARTPutChar(*str++);
}
#endif
}
/* Initialize debug output via UART for board */
void Board_Debug_Init(void)
{
#if defined(DEBUG_UART)
/* Disables pullups/pulldowns and enable digitial mode */
Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 13, (IOCON_MODE_INACT | IOCON_DIGMODE_EN));
Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 18, (IOCON_MODE_INACT | IOCON_DIGMODE_EN));
/* UART signal muxing via SWM */
Chip_SWM_MovablePortPinAssign(SWM_UART0_RXD_I, 0, 13);
Chip_SWM_MovablePortPinAssign(SWM_UART0_TXD_O, 0, 18);
/* Use main clock rate as base for UART baud rate divider */
Chip_Clock_SetUARTBaseClockRate(Chip_Clock_GetMainClockRate(), false);
/* Setup UART */
Chip_UART_Init(DEBUG_UART);
Chip_UART_ConfigData(DEBUG_UART, UART_CFG_DATALEN_8 | UART_CFG_PARITY_NONE | UART_CFG_STOPLEN_1);
Chip_UART_SetBaud(DEBUG_UART, 115200);
Chip_UART_Enable(DEBUG_UART);
Chip_UART_TXEnable(DEBUG_UART);
#endif
}
#define MAXLEDS 3
static const uint8_t ledpins[MAXLEDS] = {25, 3, 1};
static const uint8_t ledports[MAXLEDS] = {0, 0, 1};
/* Initializes board LED(s) */
static void Board_LED_Init(void)
{
int idx;
for (idx = 0; idx < MAXLEDS; idx++) {
/* Set the GPIO as output with initial state off (high) */
Chip_GPIO_SetPinDIROutput(LPC_GPIO, ledports[idx], ledpins[idx]);
Chip_GPIO_SetPinState(LPC_GPIO, ledports[idx], ledpins[idx], true);
}
}
/* Sets the state of a board LED to on or off */
void Board_LED_Set(uint8_t LEDNumber, bool On)
{
if (LEDNumber < MAXLEDS) {
/* Toggle state, low is on, high is off */
Chip_GPIO_SetPinState(LPC_GPIO, ledports[LEDNumber], ledpins[LEDNumber], !On);
}
}
/* Returns the current state of a board LED */
bool Board_LED_Test(uint8_t LEDNumber)
{
bool state = false;
if (LEDNumber < MAXLEDS) {
state = !Chip_GPIO_GetPinState(LPC_GPIO, ledports[LEDNumber], ledpins[LEDNumber]);
}
return state;
}
/* Toggles the current state of a board LED */
void Board_LED_Toggle(uint8_t LEDNumber)
{
Chip_GPIO_SetPinToggle(LPC_GPIO, ledports[LEDNumber], ledpins[LEDNumber]);
}
/* Set up and initialize all required blocks and functions related to the
board hardware */
void Board_Init(void)
{
/* Sets up DEBUG UART */
DEBUGINIT();
/* Initialize GPIO */
Chip_GPIO_Init(LPC_GPIO);
/* Initialize LEDs */
Board_LED_Init();
}
/* Ordered up, down, left, right, press */
#define NUM_BUTTONS 5
static const uint8_t portButton[NUM_BUTTONS] = {1, 1, 1, 1, 1};
static const uint8_t pinButton[NUM_BUTTONS] = {4, 6, 8, 7, 5};
static const uint8_t stateButton[NUM_BUTTONS] = {JOY_UP, JOY_DOWN, JOY_LEFT,
JOY_RIGHT, JOY_PRESS};
/* Initialize Joystick */
void Board_Joystick_Init(void)
{
int i;
/* IOCON states already selected in SystemInit(), GPIO setup only. Pullups
are external, so IOCON with no states */
for (i = 0; i < NUM_BUTTONS; i++) {
Chip_GPIO_SetPinDIRInput(LPC_GPIO, portButton[i], pinButton[i]);
}
}
/* Get Joystick status */
uint8_t Joystick_GetStatus(void)
{
uint8_t i, ret = 0;
for (i = 0; i < NUM_BUTTONS; i++) {
if ((Chip_GPIO_GetPinState(LPC_GPIO, portButton[i], pinButton[i])) == 0x00) {
ret |= stateButton[i];
}
}
return ret;
}

View File

@@ -0,0 +1,183 @@
/*
* @brief LPCXPresso LPC1549 Sysinit file
*
* @note
* Copyright(C) NXP Semiconductors, 2014
* 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"
#include "string.h"
/* The System initialization code is called prior to the application and
initializes the board for run-time operation. Board initialization
includes clock setup and default pin muxing configuration. */
/*****************************************************************************
* Private types/enumerations/variables
****************************************************************************/
/* IOCON setup table, only items that need changing from their default pin
state are in this table. */
STATIC const PINMUX_GRP_T ioconSetup[] = {
/* LEDs */
{0, 25, (IOCON_MODE_INACT | IOCON_DIGMODE_EN)}, /* PIO0_25-BREAK_CTRL-RED (low enable) */
{0, 3, (IOCON_MODE_INACT | IOCON_DIGMODE_EN)}, /* PIO0_3-SCT1_OUT4-GRN */
{1, 1, (IOCON_MODE_INACT | IOCON_DIGMODE_EN)}, /* PIO1_1-BREAK_STS1-BLUE */
/* QEI, motor controler, I2C, CAN */
{0, 2, (IOCON_MODE_INACT | IOCON_DIGMODE_EN)}, /* PIO0_2-QEI-SCT0_IN */
{0, 30, (IOCON_MODE_INACT | IOCON_DIGMODE_EN)}, /* PIO0_30-QEI-SCT0_IN */
{0, 17, (IOCON_MODE_INACT | IOCON_DIGMODE_EN)}, /* PIO0_17-QEI-SCT0_IN */
{0, 25, (IOCON_MODE_INACT | IOCON_DIGMODE_EN)}, /* PIO0_25-BREAK_CTRL-RED */
{1, 1, (IOCON_MODE_INACT | IOCON_DIGMODE_EN)}, /* PIO1_1-BREAK_STS1-BLUE */
{0, 23, (IOCON_MODE_INACT | IOCON_DIGMODE_EN)}, /* PIO0_23-I2C_SDA */
{0, 22, (IOCON_MODE_INACT | IOCON_DIGMODE_EN)}, /* PIO0_22-I2C_SCL */
{0, 11, (IOCON_MODE_INACT | IOCON_DIGMODE_EN)}, /* PIO0_11-CAN_RD */
{0, 31, (IOCON_MODE_INACT | IOCON_DIGMODE_EN)}, /* PIO0_31-CAN_TD */
/* ADC */
{1, 3, (IOCON_MODE_INACT)}, /* PIO1_3-ADC1_5 */
{0, 4, (IOCON_MODE_INACT)}, /* PIO0_4-ADC0_4 */
{0, 5, (IOCON_MODE_INACT)}, /* PIO0_5-ADC0_3 */
{0, 7, (IOCON_MODE_INACT)}, /* PIO0_7-ADC0_1 */
{0, 8, (IOCON_MODE_INACT)}, /* PIO0_8-ADC0_0 */
{0, 9, (IOCON_MODE_INACT)}, /* PIO0_9-ADC1_1 */
{0, 10, (IOCON_MODE_INACT)}, /* PIO0_10-ADC1_2 */
/* Joystick */
{1, 4, (IOCON_MODE_INACT | IOCON_DIGMODE_EN)}, /* PIO1_4-JOY_U */
{1, 5, (IOCON_MODE_INACT | IOCON_DIGMODE_EN)}, /* PIO1_5-JOY_C */
{1, 6, (IOCON_MODE_INACT | IOCON_DIGMODE_EN)}, /* PIO1_6-JOY_D */
{1, 7, (IOCON_MODE_INACT | IOCON_DIGMODE_EN)}, /* PIO1_7-JOY_R */
{1, 8, (IOCON_MODE_INACT | IOCON_DIGMODE_EN)}, /* PIO1_8-JOY_L */
/* UART */
{0, 13, (IOCON_MODE_INACT | IOCON_DIGMODE_EN)}, /* PIO0_13-ISP_RX */
{0, 18, (IOCON_MODE_INACT | IOCON_DIGMODE_EN)}, /* PIO0_18-ISP_TX */
{0, 11, (IOCON_MODE_INACT | IOCON_DIGMODE_EN)},
{0, 31, (IOCON_MODE_INACT | IOCON_DIGMODE_EN)},
/* USB related */
{1, 11, (IOCON_MODE_PULLDOWN | IOCON_DIGMODE_EN)}, /* PIO1_11-ISP_1 (VBUS) */
};
/* SWIM pin assignment definitions for pin assignment/muxing */
typedef struct {
uint16_t assignedpin : 9; /* Function and mode */
uint16_t port : 2; /* Pin port */
uint16_t pin : 5; /* Pin number */
} SWM_GRP_T;
/* Pin muxing table, only items that need changing from their default pin
state are in this table. */
STATIC const SWM_GRP_T swmSetup[] = {
/* USB related */
{(uint16_t) SWM_USB_VBUS_I, 1, 11}, /* PIO1_11-ISP_1-AIN_CTRL */
/* UART */
{(uint16_t) SWM_UART0_RXD_I, 0, 13}, /* PIO0_13-ISP_RX */
{(uint16_t) SWM_UART0_TXD_O, 0, 18}, /* PIO0_18-ISP_TX */
};
/* Setup fixed pin functions (GPIOs are fixed) */
/* No fixed pins except GPIOs */
#define PINENABLE0_VAL 0xFFFFFFFF
/* No fixed pins except GPIOs */
#define PINENABLE1_VAL 0x00FFFFFF
/*****************************************************************************
* Public types/enumerations/variables
****************************************************************************/
/*****************************************************************************
* Private functions
****************************************************************************/
/*****************************************************************************
* Public functions
****************************************************************************/
/* Sets up system pin muxing */
void Board_SetupMuxing(void)
{
int i;
/* Enable SWM and IOCON clocks */
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_IOCON);
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM);
Chip_SYSCTL_PeriphReset(RESET_IOCON);
/* IOCON setup */
Chip_IOCON_SetPinMuxing(LPC_IOCON, ioconSetup, sizeof(ioconSetup) / sizeof(PINMUX_GRP_T));
/* SWM assignable pin setup */
for (i = 0; i < (sizeof(swmSetup) / sizeof(SWM_GRP_T)); i++) {
Chip_SWM_MovablePortPinAssign((CHIP_SWM_PIN_MOVABLE_T) swmSetup[i].assignedpin,
swmSetup[i].port, swmSetup[i].pin);
}
/* SWM fixed pin setup */
// LPC_SWM->PINENABLE[0] = PINENABLE0_VAL;
// LPC_SWM->PINENABLE[1] = PINENABLE1_VAL;
/* Note SWM and IOCON clocks are left on */
}
/* Set up and initialize clocking prior to call to main */
void Board_SetupClocking(void)
{
Chip_SetupXtalClocking();
/* Set USB PLL input to main oscillator */
Chip_Clock_SetUSBPLLSource(SYSCTL_PLLCLKSRC_MAINOSC);
/* Setup USB PLL (FCLKIN = 12MHz) * 4 = 48MHz
MSEL = 3 (this is pre-decremented), PSEL = 1 (for P = 2)
FCLKOUT = FCLKIN * (MSEL + 1) = 12MHz * 4 = 48MHz
FCCO = FCLKOUT * 2 * P = 48MHz * 2 * 2 = 192MHz (within FCCO range) */
Chip_Clock_SetupUSBPLL(3, 1);
/* Powerup USB PLL */
Chip_SYSCTL_PowerUp(SYSCTL_POWERDOWN_USBPLL_PD);
/* Wait for PLL to lock */
while (!Chip_Clock_IsUSBPLLLocked()) {}
/* Set default system tick divder to 1 */
Chip_Clock_SetSysTickClockDiv(1);
}
/* Set up and initialize hardware prior to call to main */
void Board_SystemInit(void)
{
/* Setup system clocking and muxing */
Board_SetupMuxing();
Board_SetupClocking();
/* Set SYSTICKDIV to 1 so CMSIS Systick functions work */
LPC_SYSCTL->SYSTICKCLKDIV = 1;
}

View File

@@ -0,0 +1,275 @@
/*
* @brief IO redirection support
*
* This file adds re-direction support to the library for various
* projects. It can be configured in one of 3 ways - no redirection,
* redirection via a UART, or redirection via semihosting. If DEBUG
* is not defined, all printf statements will do nothing with the
* output being throw away. If DEBUG is defined, then the choice of
* output is selected by the DEBUG_SEMIHOSTING define. If the
* DEBUG_SEMIHOSTING is not defined, then output is redirected via
* the UART. If DEBUG_SEMIHOSTING is defined, then output will be
* attempted to be redirected via semihosting. If the UART method
* is used, then the Board_UARTPutChar and Board_UARTGetChar
* functions must be defined to be used by this driver and the UART
* must already be initialized to the correct settings.
*
* @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.
*/
#include "board.h"
/* Keil (Realview) support */
#if defined(__CC_ARM)
#include <stdio.h>
#include <rt_misc.h>
#if defined(DEBUG_ENABLE)
#if defined(DEBUG_SEMIHOSTING)
#define ITM_Port8(n) (*((volatile unsigned char *) (0xE0000000 + 4 * n)))
#define ITM_Port16(n) (*((volatile unsigned short *) (0xE0000000 + 4 * n)))
#define ITM_Port32(n) (*((volatile unsigned long *) (0xE0000000 + 4 * n)))
#define DEMCR (*((volatile unsigned long *) (0xE000EDFC)))
#define TRCENA 0x01000000
/* Write to SWO */
void _ttywrch(int ch)
{
if (DEMCR & TRCENA) {
while (ITM_Port32(0) == 0) {}
ITM_Port8(0) = ch;
}
}
#else
static INLINE void BoardOutChar(char ch)
{
Board_UARTPutChar(ch);
}
#endif /* defined(DEBUG_SEMIHOSTING) */
#endif /* defined(DEBUG_ENABLE) */
struct __FILE {
int handle;
};
FILE __stdout;
FILE __stdin;
FILE __stderr;
void *_sys_open(const char *name, int openmode)
{
return 0;
}
int fputc(int c, FILE *f)
{
#if defined(DEBUG_ENABLE)
#if defined(DEBUG_SEMIHOSTING)
_ttywrch(c);
#else
BoardOutChar((char) c);
#endif
#endif
return 0;
}
int fgetc(FILE *f)
{
#if defined(DEBUG_ENABLE) && !defined(DEBUG_SEMIHOSTING)
return Board_UARTGetChar();
#else
return 0;
#endif
}
int ferror(FILE *f)
{
return EOF;
}
void _sys_exit(int return_code)
{
label:
__WFI();
goto label; /* endless loop */
}
#endif /* defined (__CC_ARM) */
/* IAR support */
#if defined(__ICCARM__)
/*******************
*
* Copyright 1998-2003 IAR Systems. All rights reserved.
*
* $Revision: 30870 $
*
* This is a template implementation of the "__write" function used by
* the standard library. Replace it with a system-specific
* implementation.
*
* The "__write" function should output "size" number of bytes from
* "buffer" in some application-specific way. It should return the
* number of characters written, or _LLIO_ERROR on failure.
*
* If "buffer" is zero then __write should perform flushing of
* internal buffers, if any. In this case "handle" can be -1 to
* indicate that all handles should be flushed.
*
* The template implementation below assumes that the application
* provides the function "MyLowLevelPutchar". It should return the
* character written, or -1 on failure.
*
********************/
#include <yfuns.h>
#if defined(DEBUG_ENABLE) && !defined(DEBUG_SEMIHOSTING)
_STD_BEGIN
#pragma module_name = "?__write"
/*
If the __write implementation uses internal buffering, uncomment
the following line to ensure that we are called with "buffer" as 0
(i.e. flush) when the application terminates. */
size_t __write(int handle, const unsigned char *buffer, size_t size)
{
#if defined(DEBUG_ENABLE)
size_t nChars = 0;
if (buffer == 0) {
/*
This means that we should flush internal buffers. Since we
don't we just return. (Remember, "handle" == -1 means that all
handles should be flushed.)
*/
return 0;
}
/* This template only writes to "standard out" and "standard err",
for all other file handles it returns failure. */
if (( handle != _LLIO_STDOUT) && ( handle != _LLIO_STDERR) ) {
return _LLIO_ERROR;
}
for ( /* Empty */; size != 0; --size) {
Board_UARTPutChar(*buffer++);
++nChars;
}
return nChars;
#else
return size;
#endif /* defined(DEBUG_ENABLE) */
}
_STD_END
#endif
#endif /* defined (__ICCARM__) */
#if defined( __GNUC__ )
/* Include stdio.h to pull in __REDLIB_INTERFACE_VERSION__ */
#include <stdio.h>
#if defined(__NEWLIB__)
#define WRITEFUNC _write
#define READFUNC _read
#else
#if (__REDLIB_INTERFACE_VERSION__ >= 20000)
/* We are using new Redlib_v2 semihosting interface */
#define WRITEFUNC __sys_write
#define READFUNC __sys_readc
#else
/* We are using original Redlib semihosting interface */
#define WRITEFUNC __write
#define READFUNC __readc
#endif
#endif /* __NEWLIB__ */
#if defined(DEBUG_ENABLE)
#if defined(DEBUG_SEMIHOSTING)
/* Do nothing, semihosting is enabled by default in LPCXpresso */
#endif /* defined(DEBUG_SEMIHOSTING) */
#endif /* defined(DEBUG_ENABLE) */
#if !defined(DEBUG_SEMIHOSTING)
int WRITEFUNC(int iFileHandle, char *pcBuffer, int iLength)
{
#if defined(DEBUG_ENABLE)
unsigned int i;
for (i = 0; i < iLength; i++) {
Board_UARTPutChar(pcBuffer[i]);
}
#endif
return iLength;
}
#if !defined(__NEWLIB__)
/* Called by bottom level of scanf routine within RedLib C library to read
a character. With the default semihosting stub, this would read the character
from the debugger console window (which acts as stdin). But this version reads
the character from the LPC1768/RDB1768 UART. */
int READFUNC(void)
{
#if defined(DEBUG_ENABLE)
int c = Board_UARTGetChar();
return c;
#else
return (int) -1;
#endif
}
#else
/*
* **WARNING**: THIS FUNCTION IS NON-BLOCKING
* Not just STDIN all inputs handled via UART
* Read function for newlib is added as a non-blocking function
* the application should check for the size to identify the number
* of bytes received */
int READFUNC(int iFileHandle, char *pcBuffer, int iLength)
{
int idx;
for (idx = 0; idx < iLength; idx++) {
int c = Board_UARTGetChar();
if (c == EOF) break;
pcBuffer[idx] = c;
}
return idx;
}
#endif
#endif /* !defined(DEBUG_SEMIHOSTING) */
#endif /* defined ( __GNUC__ ) */