commit 3a906364067dafadd4d83c96e173b190d0ad40f5 Author: Yilin Sun Date: Thu May 25 17:56:19 2023 +0800 Initial commit Signed-off-by: Yilin Sun diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..146512b --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "SDK"] + path = SDK + url = https://git.minori.work/Embedded_SDK/MCUXpresso_LPC804.git diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..57526d9 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,146 @@ +cmake_minimum_required(VERSION 3.10) + +project(mpyate_template) + +enable_language(CXX) +enable_language(ASM) + +# Different linker scripts +set(TARGET_LDSCRIPT_FLASH "${CMAKE_SOURCE_DIR}/SDK/devices/LPC804/gcc/LPC804_flash.ld") +set(TARGET_LDSCRIPT_RAM "${CMAKE_SOURCE_DIR}/SDK/devices/LPC804/gcc/LPC804_ram.ld") + +set(TARGET_SOURCES + "SDK/components/uart/fsl_adapter_miniusart.c" + "SDK/devices/LPC804/drivers/fsl_acomp.c" + "SDK/devices/LPC804/drivers/fsl_adc.c" + "SDK/devices/LPC804/drivers/fsl_capt.c" + "SDK/devices/LPC804/drivers/fsl_clock.c" + "SDK/devices/LPC804/drivers/fsl_common.c" + "SDK/devices/LPC804/drivers/fsl_common_arm.c" + "SDK/devices/LPC804/drivers/fsl_crc.c" + "SDK/devices/LPC804/drivers/fsl_ctimer.c" + "SDK/devices/LPC804/drivers/fsl_dac.c" + "SDK/devices/LPC804/drivers/fsl_gpio.c" + "SDK/devices/LPC804/drivers/fsl_i2c.c" + "SDK/devices/LPC804/drivers/fsl_iap.c" + "SDK/devices/LPC804/drivers/fsl_mrt.c" + "SDK/devices/LPC804/drivers/fsl_pint.c" + "SDK/devices/LPC804/drivers/fsl_plu.c" + "SDK/devices/LPC804/drivers/fsl_power.c" + "SDK/devices/LPC804/drivers/fsl_reset.c" + "SDK/devices/LPC804/drivers/fsl_spi.c" + "SDK/devices/LPC804/drivers/fsl_swm.c" + "SDK/devices/LPC804/drivers/fsl_syscon.c" + "SDK/devices/LPC804/drivers/fsl_usart.c" + "SDK/devices/LPC804/drivers/fsl_wkt.c" + "SDK/devices/LPC804/drivers/fsl_wwdt.c" + "SDK/devices/LPC804/gcc/startup_LPC804.S" + "SDK/devices/LPC804/system_LPC804.c" + "SDK/devices/LPC804/utilities/debug_console_lite/fsl_debug_console.c" + "SDK/devices/LPC804/utilities/fsl_sbrk.c" + "SDK/devices/LPC804/utilities/str/fsl_str.c" + "board/board.c" + "board/clock_config.c" + "board/peripherals.c" + "board/pin_mux.c" + "src/main.c" +) + +set(TARGET_C_DEFINES + "CPU_LPC804M101JHI33" + "MCUXPRESSO_SDK" + "__STARTUP_CLEAR_BSS" +) + +set(TARGET_C_INCLUDES + "SDK/CMSIS/Core/Include" + "SDK/components/uart" + "SDK/devices/LPC804" + "SDK/devices/LPC804/drivers" + "SDK/devices/LPC804/utilities/debug_console_lite" + "SDK/devices/LPC804/utilities/str" + "board" + "include" +) + +# Shared libraries linked with application +set(TARGET_LIBS + "c" + "m" + "nosys" +) + +# Shared library and linker script search paths +set(TARGET_LIB_DIRECTORIES +) + +# Conditional flags +# DEBUG +set(CMAKE_C_FLAGS_DEBUG "-DDEBUG -O0 -g") +set(CMAKE_CXX_FLAGS_DEBUG "-DDEBUG -O0 -g") +set(CMAKE_ASM_FLAGS_DEBUG "-DDEBUG -O0 -g") + +# RELEASE +set(CMAKE_C_FLAGS_RELEASE "-DNDEBUG -O2 -flto") +set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG -O2 -flto") +set(CMAKE_ASM_FLAGS_RELEASE "-DNDEBUG -O2 -flto") +set(CMAKE_EXE_LINKER_FLAGS_RELEASE "-flto") + +# Final compiler flags +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -fno-common -fno-builtin -ffreestanding -fdata-sections -ffunction-sections") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-common -fno-builtin -ffreestanding -fdata-sections -ffunction-sections") +set(CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS} -x assembler-with-cpp") +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") + +# Shared sources, includes and definitions +add_compile_definitions(${TARGET_C_DEFINES}) +include_directories(${TARGET_C_INCLUDES}) +link_directories(${TARGET_LIB_DIRECTORIES}) +link_libraries(${TARGET_LIBS}) + +# Main targets are added here + +# Create ELF +add_executable("${CMAKE_PROJECT_NAME}_FLASH.elf" ${TARGET_SOURCES}) +target_compile_definitions("${CMAKE_PROJECT_NAME}_FLASH.elf" + PRIVATE ${TARGET_C_DEFINES_XIP} + ) +target_link_options("${CMAKE_PROJECT_NAME}_FLASH.elf" + PRIVATE "-T${TARGET_LDSCRIPT_FLASH}" + PRIVATE "-Wl,--Map=${CMAKE_PROJECT_NAME}_FLASH.map" + ) +set_property(TARGET "${CMAKE_PROJECT_NAME}_FLASH.elf" APPEND + PROPERTY ADDITIONAL_CLEAN_FILES "${CMAKE_PROJECT_NAME}_FLASH.map" + ) +add_custom_command(OUTPUT "${CMAKE_PROJECT_NAME}_FLASH.hex" + COMMAND ${CMAKE_OBJCOPY} "-O" "ihex" "${CMAKE_PROJECT_NAME}_FLASH.elf" "${CMAKE_PROJECT_NAME}_FLASH.hex" + DEPENDS "${CMAKE_PROJECT_NAME}_FLASH.elf" + ) +add_custom_target("${CMAKE_PROJECT_NAME}_FLASH_HEX" DEPENDS "${CMAKE_PROJECT_NAME}_FLASH.hex") +if(DEFINED TARGET_TOOLCHAIN_SIZE) + add_custom_command(TARGET "${CMAKE_PROJECT_NAME}_FLASH.elf" POST_BUILD + COMMAND ${TARGET_TOOLCHAIN_SIZE} "${CMAKE_PROJECT_NAME}_FLASH.elf" + ) +endif() + + +# Create ELF +add_executable("${CMAKE_PROJECT_NAME}_RAM.elf" ${TARGET_SOURCES}) +target_link_options("${CMAKE_PROJECT_NAME}_RAM.elf" + PRIVATE "-T${TARGET_LDSCRIPT_RAM}" + PRIVATE "-Wl,--Map=${CMAKE_PROJECT_NAME}_RAM.map" + ) +set_property(TARGET "${CMAKE_PROJECT_NAME}_RAM.elf" APPEND + PROPERTY ADDITIONAL_CLEAN_FILES "${CMAKE_PROJECT_NAME}_RAM.map" + ) +add_custom_command(OUTPUT "${CMAKE_PROJECT_NAME}_RAM.hex" + COMMAND ${CMAKE_OBJCOPY} "-O" "ihex" "${CMAKE_PROJECT_NAME}_RAM.elf" "${CMAKE_PROJECT_NAME}_RAM.hex" + DEPENDS "${CMAKE_PROJECT_NAME}_RAM.elf" + ) +add_custom_target("${CMAKE_PROJECT_NAME}_RAM_HEX" DEPENDS "${CMAKE_PROJECT_NAME}_RAM.hex") +if(DEFINED TARGET_TOOLCHAIN_SIZE) + add_custom_command(TARGET "${CMAKE_PROJECT_NAME}_RAM.elf" POST_BUILD + COMMAND ${TARGET_TOOLCHAIN_SIZE} "${CMAKE_PROJECT_NAME}_RAM.elf" + ) +endif() + diff --git a/LPC804.mex b/LPC804.mex new file mode 100644 index 0000000..548bae8 --- /dev/null +++ b/LPC804.mex @@ -0,0 +1,207 @@ + + + + LPC804 + LPC804M101JHI33 + ksdk2_0 + + + + + + + true + false + false + true + false + + + + + + + + + 13.0.1 + + + + + + + + + Configures pin routing and optionally pin electrical features. + + false + core0 + true + + + + + true + + + + + true + + + + + true + + + + + + + + + + Configures pin routing and optionally pin electrical features. + + true + core0 + true + + + + + true + + + + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 13.0.1 + + + + + + + + + true + + + + + true + + + + + true + + + + + + + + + + + + + true + + + + + + + N/A + + + + + + + + + + 13.0.1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + N/A + + + + \ No newline at end of file diff --git a/SDK b/SDK new file mode 160000 index 0000000..e468131 --- /dev/null +++ b/SDK @@ -0,0 +1 @@ +Subproject commit e46813114663364b03f7507d3926852fe55b2b58 diff --git a/arm-none-eabi.cmake b/arm-none-eabi.cmake new file mode 100644 index 0000000..2b68248 --- /dev/null +++ b/arm-none-eabi.cmake @@ -0,0 +1,17 @@ +# Poor old Windows... +if(WIN32) + set(CMAKE_SYSTEM_NAME "Generic") +endif() + +set(CMAKE_C_COMPILER arm-none-eabi-gcc) +set(CMAKE_CXX_COMPILER arm-none-eabi-g++) + +# Optionally set size binary name, for elf section size reporting. +set(TARGET_TOOLCHAIN_SIZE arm-none-eabi-size) + +set(CMAKE_C_FLAGS_INIT "-mcpu=cortex-m0plus -mthumb -mfloat-abi=soft") +set(CMAKE_CXX_FLAGS_INIT "-mcpu=cortex-m0plus -mthumb -mfloat-abi=soft") +set(CMAKE_EXE_LINKER_FLAGS_INIT "-specs=nano.specs -specs=nosys.specs -Wl,--print-memory-usage -Wl,--no-warn-rwx-segments") + +# Make CMake happy about those compilers +set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY") diff --git a/board/board.c b/board/board.c new file mode 100644 index 0000000..2e5e789 --- /dev/null +++ b/board/board.c @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2016, Freescale Semiconductor, Inc. + * Copyright 2016-2018 NXP + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include "fsl_common.h" +#include "clock_config.h" +#include "board.h" +#include "fsl_debug_console.h" + +/******************************************************************************* + * Variables + ******************************************************************************/ + +/* Clock rate on the CLKIN pin */ +const uint32_t ExtClockIn = BOARD_EXTCLKINRATE; + +/******************************************************************************* + * Code + ******************************************************************************/ +/* Initialize debug console. */ +status_t BOARD_InitDebugConsole(void) +{ +#if ((SDK_DEBUGCONSOLE == DEBUGCONSOLE_REDIRECT_TO_SDK) || defined(SDK_DEBUGCONSOLE_UART)) + status_t result; + /* Attach 12 MHz clock to USART0 (debug console) */ + CLOCK_Select(BOARD_DEBUG_USART_CLK_ATTACH); + RESET_PeripheralReset(BOARD_DEBUG_USART_RST); + result = DbgConsole_Init(BOARD_DEBUG_USART_INSTANCE, BOARD_DEBUG_USART_BAUDRATE, BOARD_DEBUG_USART_TYPE, + BOARD_DEBUG_USART_CLK_FREQ); + assert(kStatus_Success == result); + return result; +#else + return kStatus_Success; +#endif +} diff --git a/board/board.h b/board/board.h new file mode 100644 index 0000000..dac0fec --- /dev/null +++ b/board/board.h @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2016, Freescale Semiconductor, Inc. + * Copyright 2016-2018 NXP + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _BOARD_H_ +#define _BOARD_H_ + +#include "clock_config.h" +#include "fsl_common.h" +#include "fsl_gpio.h" + +/******************************************************************************* + * Definitions + ******************************************************************************/ +/*! @brief The board name */ +#define BOARD_NAME "MPyATE" + +#define BOARD_EXTCLKINRATE (0) + +/*! @brief The UART to use for debug messages. */ +#define BOARD_DEBUG_USART_TYPE kSerialPort_Uart +#define BOARD_DEBUG_USART_BASEADDR (uint32_t) USART0 +#define BOARD_DEBUG_USART_INSTANCE 0U +#define BOARD_DEBUG_USART_CLK_FREQ CLOCK_GetMainClkFreq() +#define BOARD_DEBUG_USART_CLK_ATTACH kUART0_Clk_From_MainClk +#define BOARD_DEBUG_USART_RST kUART0_RST_N_SHIFT_RSTn +#define BOARD_USART_IRQ USART0_IRQn +#define BOARD_USART_IRQ_HANDLER USART0_IRQHandler + +#ifndef BOARD_DEBUG_USART_BAUDRATE +#define BOARD_DEBUG_USART_BAUDRATE 9600 +#endif /* BOARD_DEBUG_USART_BAUDRATE */ + +/*! @brief Board led mapping */ +#define LOGIC_LED_ON 0U +#define LOGIC_LED_OFF 1U + +/* LED_GREEN */ +#ifndef BOARD_LED_GREEN_GPIO +#define BOARD_LED_GREEN_GPIO GPIO +#endif +#define BOARD_LED_GREEN_GPIO_PORT 0U +#ifndef BOARD_LED_GREEN_GPIO_PIN +#define BOARD_LED_GREEN_GPIO_PIN 18U +#endif + +#define LED_GREEN_INIT(output) \ + GPIO_PortInit(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PORT); \ + GPIO_PinInit(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PORT, BOARD_LED_GREEN_GPIO_PIN, \ + &(gpio_pin_config_t){kGPIO_DigitalOutput, (output)}); /*!< Enable target LED_GREEN */ +#define LED_GREEN_ON() \ + GPIO_PortClear(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PORT, \ + 1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Turn on target LED_GREEN \ \ \ \ \ \ \ + */ +#define LED_GREEN_OFF() \ + GPIO_PortSet(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PORT, \ + 1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Turn off target LED_GREEN \ \ \ \ \ \ \ + */ +#define LED_GREEN_TOGGLE() \ + GPIO_PortToggle(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PORT, \ + 1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Toggle on target LED_GREEN */ + +/* LED_BLUE */ +#ifndef BOARD_LED_BLUE_GPIO +#define BOARD_LED_BLUE_GPIO GPIO +#endif +#define BOARD_LED_BLUE_GPIO_PORT 0U +#ifndef BOARD_LED_BLUE_GPIO_PIN +#define BOARD_LED_BLUE_GPIO_PIN 16U +#endif + +#ifndef BOARD_S1_GPIO +#define BOARD_S1_GPIO GPIO +#endif +#define BOARD_S1_GPIO_PORT 0U +#ifndef BOARD_S1_GPIO_PIN +#define BOARD_S1_GPIO_PIN 13U +#endif +#define BOARD_S1_NAME "S1" +#define BOARD_S1_IRQ PIN_INT0_IRQn +#define BOARD_S1_IRQ_HANDLER PIN_INT0_IRQHandler + +#define LED_BLUE_INIT(output) \ + GPIO_PortInit(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PORT); \ + GPIO_PinInit(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PORT, BOARD_LED_BLUE_GPIO_PIN, \ + &(gpio_pin_config_t){kGPIO_DigitalOutput, (output)}); /*!< Enable target LED_GREEN */ +#define LED_BLUE_ON() \ + GPIO_PortClear(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PORT, \ + 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Turn on target LED_BLUE \ \ \ \ \ \ \ + */ +#define LED_BLUE_OFF() \ + GPIO_PortSet(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PORT, \ + 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Turn off target LED_BLUE \ \ \ \ \ \ \ + */ +#define LED_BLUE_TOGGLE() \ + GPIO_PortToggle(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PORT, \ + 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Toggle on target LED_BLUE */ + +/* LED_RED */ +#ifndef BOARD_LED_RED_GPIO +#define BOARD_LED_RED_GPIO GPIO +#endif +#define BOARD_LED_RED_GPIO_PORT 0U +#ifndef BOARD_LED_RED_GPIO_PIN +#define BOARD_LED_RED_GPIO_PIN 18U +#endif + +#define LED_RED_INIT(output) \ + GPIO_PortInit(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PORT); \ + GPIO_PinInit(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PORT, BOARD_LED_RED_GPIO_PIN, \ + &(gpio_pin_config_t){kGPIO_DigitalOutput, (output)}); /*!< Enable target LED_RED */ +#define LED_RED_ON() \ + GPIO_PortClear(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PORT, \ + 1U << BOARD_LED_RED_GPIO_PIN) /*!< Turn on target LED_RED \ \ \ \ \ \ \ + */ +#define LED_RED_OFF() \ + GPIO_PortSet(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PORT, \ + 1U << BOARD_LED_RED_GPIO_PIN) /*!< Turn off target LED_RED \ \ \ \ \ \ \ + */ +#define LED_RED_TOGGLE() \ + GPIO_PortToggle(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PORT, \ + 1U << BOARD_LED_RED_GPIO_PIN) /*!< Toggle on target LED_RED */ + +#if defined(__cplusplus) +extern "C" { +#endif /* __cplusplus */ + +/******************************************************************************* + * API + ******************************************************************************/ + +status_t BOARD_InitDebugConsole(void); + +#if defined(__cplusplus) +} +#endif /* __cplusplus */ + +#endif /* _BOARD_H_ */ diff --git a/board/clock_config.c b/board/clock_config.c new file mode 100644 index 0000000..8573a7a --- /dev/null +++ b/board/clock_config.c @@ -0,0 +1,78 @@ +/* + * How to set up clock using clock driver functions: + * + * 1. Setup clock sources. + * + * 2. Set up all dividers. + * + * 3. Set up all selectors to provide selected clocks. + */ + +/* TEXT BELOW IS USED AS SETTING FOR TOOLS ************************************* +!!GlobalInfo +product: Clocks v11.0 +processor: LPC804 +package_id: LPC804M101JHI33 +mcu_data: ksdk2_0 +processor_version: 13.0.1 + * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/ + +#include "fsl_power.h" +#include "fsl_clock.h" +#include "clock_config.h" + +/******************************************************************************* + * Definitions + ******************************************************************************/ + +/******************************************************************************* + * Variables + ******************************************************************************/ + +/******************************************************************************* + ************************ BOARD_InitBootClocks function ************************ + ******************************************************************************/ +void BOARD_InitBootClocks(void) +{ + BOARD_BootClockRUN(); +} + +/******************************************************************************* + ********************** Configuration BOARD_BootClockRUN *********************** + ******************************************************************************/ +/* TEXT BELOW IS USED AS SETTING FOR TOOLS ************************************* +!!Configuration +name: BOARD_BootClockRUN +called_from_default_init: true +outputs: +- {id: FROHF_clock.outFreq, value: 30 MHz} +- {id: LowPower_clock.outFreq, value: 1 MHz} +- {id: System_clock.outFreq, value: 15 MHz} +- {id: WWDT_clock.outFreq, value: 1 MHz} +- {id: divto750k_clock.outFreq, value: 750 kHz} + * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/ + +/******************************************************************************* + * Variables for BOARD_BootClockRUN configuration + ******************************************************************************/ +/******************************************************************************* + * Code for BOARD_BootClockRUN configuration + ******************************************************************************/ +void BOARD_BootClockRUN(void) +{ + /*!< Set up the clock sources */ + /*!< Set up FRO */ + POWER_DisablePD(kPDRUNCFG_PD_FRO_OUT); /*!< Ensure FRO OUT is on */ + POWER_DisablePD(kPDRUNCFG_PD_FRO); /*!< Ensure FRO is on */ + CLOCK_SetFroOscFreq(kCLOCK_FroOscOut30M); /*!< Set up FRO freq */ + POWER_DisablePD(kPDRUNCFG_PD_LPOSC); /*!< Ensure LPOSC is on */ + CLOCK_SetMainClkSrc(kCLOCK_MainClkSrcFro); /*!< select fro for main clock */ + CLOCK_Select(kFRG0_Clk_From_Fro); /*!< select fro for frg0 */ + CLOCK_SetFRG0ClkFreq(15000000U); /*!< select frg0 freq */ + CLOCK_Select(kCLKOUT_From_Fro); /*!< select FRO for CLKOUT */ + CLOCK_Select(kADC_Clk_From_Fro); /*!< select FRO for ADC */ + CLOCK_SetCoreSysClkDiv(1U); + /*!< Set SystemCoreClock variable. */ + SystemCoreClock = BOARD_BOOTCLOCKRUN_CORE_CLOCK; +} + diff --git a/board/clock_config.h b/board/clock_config.h new file mode 100644 index 0000000..214827f --- /dev/null +++ b/board/clock_config.h @@ -0,0 +1,78 @@ +/*********************************************************************************************************************** + * This file was generated by the MCUXpresso Config Tools. Any manual edits made to this file + * will be overwritten if the respective MCUXpresso Config Tools is used to update this file. + **********************************************************************************************************************/ + +#ifndef _CLOCK_CONFIG_H_ +#define _CLOCK_CONFIG_H_ + +#include "fsl_common.h" + +/******************************************************************************* + * Definitions + ******************************************************************************/ +#define BOARD_XTAL0_CLK_HZ 12000000U /*!< Board xtal0 frequency in Hz */ +#define BOARD_XTAL32K_CLK_HZ 32768U /*!< Board xtal32K frequency in Hz */ + +/******************************************************************************* + ************************ BOARD_InitBootClocks function ************************ + ******************************************************************************/ + +#if defined(__cplusplus) +extern "C" { +#endif /* __cplusplus*/ + +/*! + * @brief This function executes default configuration of clocks. + * + */ +void BOARD_InitBootClocks(void); + +#if defined(__cplusplus) +} +#endif /* __cplusplus*/ + +/******************************************************************************* + ********************** Configuration BOARD_BootClockRUN *********************** + ******************************************************************************/ +/******************************************************************************* + * Definitions for BOARD_BootClockRUN configuration + ******************************************************************************/ +#define BOARD_BOOTCLOCKRUN_CORE_CLOCK 15000000U /*!< Core clock frequency: 15000000Hz */ + + +/* Clock outputs (values are in Hz): */ +#define BOARD_BOOTCLOCKRUN_ADC_CLOCK 0UL +#define BOARD_BOOTCLOCKRUN_CAPT_CLOCK 0UL +#define BOARD_BOOTCLOCKRUN_CLKOUT_CLOCK 0UL +#define BOARD_BOOTCLOCKRUN_FROHF_CLOCK 30000000UL +#define BOARD_BOOTCLOCKRUN_I2C0_CLOCK 0UL +#define BOARD_BOOTCLOCKRUN_I2C1_CLOCK 0UL +#define BOARD_BOOTCLOCKRUN_LOWPOWER_CLOCK 1000000UL +#define BOARD_BOOTCLOCKRUN_PLUCLKIN_CLOCK 0UL +#define BOARD_BOOTCLOCKRUN_SPI0_CLOCK 0UL +#define BOARD_BOOTCLOCKRUN_SYSTEM_CLOCK 15000000UL +#define BOARD_BOOTCLOCKRUN_UART0_CLOCK 0UL +#define BOARD_BOOTCLOCKRUN_UART1_CLOCK 0UL +#define BOARD_BOOTCLOCKRUN_WWDT_CLOCK 1000000UL +#define BOARD_BOOTCLOCKRUN_DIVTO750K_CLOCK 750000UL + +/******************************************************************************* + * API for BOARD_BootClockRUN configuration + ******************************************************************************/ +#if defined(__cplusplus) +extern "C" { +#endif /* __cplusplus*/ + +/*! + * @brief This function executes configuration of clocks. + * + */ +void BOARD_BootClockRUN(void); + +#if defined(__cplusplus) +} +#endif /* __cplusplus*/ + +#endif /* _CLOCK_CONFIG_H_ */ + diff --git a/board/peripherals.c b/board/peripherals.c new file mode 100644 index 0000000..c4ed6dc --- /dev/null +++ b/board/peripherals.c @@ -0,0 +1,65 @@ +/*********************************************************************************************************************** + * This file was generated by the MCUXpresso Config Tools. Any manual edits made to this file + * will be overwritten if the respective MCUXpresso Config Tools is used to update this file. + **********************************************************************************************************************/ + +/* clang-format off */ +/* TEXT BELOW IS USED AS SETTING FOR TOOLS ************************************* +!!GlobalInfo +product: Peripherals v12.0 +processor: LPC804 +package_id: LPC804M101JHI33 +mcu_data: ksdk2_0 +processor_version: 13.0.1 +functionalGroups: +- name: BOARD_InitPeripherals + UUID: 333bc532-5b96-45be-999a-50c34b7bab60 + called_from_default_init: true + selectedCore: core0 + * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/ + +/* TEXT BELOW IS USED AS SETTING FOR TOOLS ************************************* +component: +- type: 'system' +- type_id: 'system_54b53072540eeeb8f8e9343e71f28176' +- global_system_definitions: + - user_definitions: '' + - user_includes: '' + * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/ + +/* TEXT BELOW IS USED AS SETTING FOR TOOLS ************************************* +component: +- type: 'gpio_adapter_common' +- type_id: 'gpio_adapter_common_57579b9ac814fe26bf95df0a384c36b6' +- global_gpio_adapter_common: + - quick_selection: 'default' + * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/ + +/* TEXT BELOW IS USED AS SETTING FOR TOOLS ************************************* +component: +- type: 'uart_cmsis_common' +- type_id: 'uart_cmsis_common_9cb8e302497aa696fdbb5a4fd622c2a8' +- global_USART_CMSIS_common: + - quick_selection: 'default' + * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/ +/* clang-format on */ + +/*********************************************************************************************************************** + * Included files + **********************************************************************************************************************/ +#include "peripherals.h" + +/*********************************************************************************************************************** + * Initialization functions + **********************************************************************************************************************/ +void BOARD_InitPeripherals(void) +{ +} + +/*********************************************************************************************************************** + * BOARD_InitBootPeripherals function + **********************************************************************************************************************/ +void BOARD_InitBootPeripherals(void) +{ + BOARD_InitPeripherals(); +} diff --git a/board/peripherals.h b/board/peripherals.h new file mode 100644 index 0000000..fe99cdc --- /dev/null +++ b/board/peripherals.h @@ -0,0 +1,28 @@ +/*********************************************************************************************************************** + * This file was generated by the MCUXpresso Config Tools. Any manual edits made to this file + * will be overwritten if the respective MCUXpresso Config Tools is used to update this file. + **********************************************************************************************************************/ + +#ifndef _PERIPHERALS_H_ +#define _PERIPHERALS_H_ + +#if defined(__cplusplus) +extern "C" { +#endif /* __cplusplus */ + +/*********************************************************************************************************************** + * Initialization functions + **********************************************************************************************************************/ + +void BOARD_InitPeripherals(void); + +/*********************************************************************************************************************** + * BOARD_InitBootPeripherals function + **********************************************************************************************************************/ +void BOARD_InitBootPeripherals(void); + +#if defined(__cplusplus) +} +#endif + +#endif /* _PERIPHERALS_H_ */ diff --git a/board/pin_mux.c b/board/pin_mux.c new file mode 100644 index 0000000..34f22d1 --- /dev/null +++ b/board/pin_mux.c @@ -0,0 +1,147 @@ +/*********************************************************************************************************************** + * This file was generated by the MCUXpresso Config Tools. Any manual edits made to this file + * will be overwritten if the respective MCUXpresso Config Tools is used to update this file. + **********************************************************************************************************************/ + +/* clang-format off */ +/* + * TEXT BELOW IS USED AS SETTING FOR TOOLS ************************************* +!!GlobalInfo +product: Pins v13.1 +processor: LPC804 +package_id: LPC804M101JHI33 +mcu_data: ksdk2_0 +processor_version: 13.0.1 +pin_labels: +- {pin_num: '30', pin_signal: PIO0_22, label: LED_R, identifier: LED_R} +- {pin_num: '31', pin_signal: PIO0_18, label: LED_G, identifier: LED_G} +- {pin_num: '32', pin_signal: PIO0_16/ACMP_I4/ADC_3, label: LED_B, identifier: LED_B} + * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS *********** + */ +/* clang-format on */ + +#include "fsl_common.h" +#include "fsl_gpio.h" +#include "fsl_swm.h" +#include "pin_mux.h" + +/* FUNCTION ************************************************************************************************************ + * + * Function Name : BOARD_InitBootPins + * Description : Calls initialization functions. + * + * END ****************************************************************************************************************/ +void BOARD_InitBootPins(void) +{ + BOARD_InitLEDPins(); +} + +/* clang-format off */ +/* + * TEXT BELOW IS USED AS SETTING FOR TOOLS ************************************* +BOARD_InitDbgUARTPins: +- options: {callFromInitBoot: 'false', coreID: core0, enableClock: 'true'} +- pin_list: + - {pin_num: '28', peripheral: USART0, signal: TXD, pin_signal: PIO0_24} + - {pin_num: '27', peripheral: USART0, signal: RXD, pin_signal: PIO0_25} + * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS *********** + */ +/* clang-format on */ + +/* FUNCTION ************************************************************************************************************ + * + * Function Name : BOARD_InitDbgUARTPins + * Description : Configures pin routing and optionally pin electrical features. + * + * END ****************************************************************************************************************/ +/* Function assigned for the Cortex-M0P */ +void BOARD_InitDbgUARTPins(void) +{ + /* Enables clock for switch matrix.: enable */ + CLOCK_EnableClock(kCLOCK_Swm); + + /* USART0_TXD connect to P0_24 */ + SWM_SetMovablePinSelect(SWM0, kSWM_USART0_TXD, kSWM_PortPin_P0_24); + + /* USART0_RXD connect to P0_25 */ + SWM_SetMovablePinSelect(SWM0, kSWM_USART0_RXD, kSWM_PortPin_P0_25); + + /* Disable clock for switch matrix. */ + CLOCK_DisableClock(kCLOCK_Swm); +} + +/* clang-format off */ +/* + * TEXT BELOW IS USED AS SETTING FOR TOOLS ************************************* +BOARD_InitLEDPins: +- options: {callFromInitBoot: 'true', coreID: core0, enableClock: 'true'} +- pin_list: + - {pin_num: '30', peripheral: GPIO, signal: 'PIO0, 22', pin_signal: PIO0_22, direction: OUTPUT, gpio_init_state: 'true', opendrain: enabled} + - {pin_num: '31', peripheral: GPIO, signal: 'PIO0, 18', pin_signal: PIO0_18, direction: OUTPUT, gpio_init_state: 'true', opendrain: enabled} + - {pin_num: '32', peripheral: GPIO, signal: 'PIO0, 16', pin_signal: PIO0_16/ACMP_I4/ADC_3, direction: OUTPUT, gpio_init_state: 'true', opendrain: enabled} + * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS *********** + */ +/* clang-format on */ + +/* FUNCTION ************************************************************************************************************ + * + * Function Name : BOARD_InitLEDPins + * Description : Configures pin routing and optionally pin electrical features. + * + * END ****************************************************************************************************************/ +/* Function assigned for the Cortex-M0P */ +void BOARD_InitLEDPins(void) +{ + /* Enables clock for IOCON.: enable */ + CLOCK_EnableClock(kCLOCK_Iocon); + /* Enables the clock for the GPIO0 module */ + CLOCK_EnableClock(kCLOCK_Gpio0); + + gpio_pin_config_t LED_B_config = { + .pinDirection = kGPIO_DigitalOutput, + .outputLogic = 1U, + }; + /* Initialize GPIO functionality on pin PIO0_16 (pin 32) */ + GPIO_PinInit(BOARD_INITLEDPINS_LED_B_GPIO, BOARD_INITLEDPINS_LED_B_PORT, BOARD_INITLEDPINS_LED_B_PIN, &LED_B_config); + + gpio_pin_config_t LED_G_config = { + .pinDirection = kGPIO_DigitalOutput, + .outputLogic = 1U, + }; + /* Initialize GPIO functionality on pin PIO0_18 (pin 31) */ + GPIO_PinInit(BOARD_INITLEDPINS_LED_G_GPIO, BOARD_INITLEDPINS_LED_G_PORT, BOARD_INITLEDPINS_LED_G_PIN, &LED_G_config); + + gpio_pin_config_t LED_R_config = { + .pinDirection = kGPIO_DigitalOutput, + .outputLogic = 1U, + }; + /* Initialize GPIO functionality on pin PIO0_22 (pin 30) */ + GPIO_PinInit(BOARD_INITLEDPINS_LED_R_GPIO, BOARD_INITLEDPINS_LED_R_PORT, BOARD_INITLEDPINS_LED_R_PIN, &LED_R_config); + + IOCON->PIO[9] = ((IOCON->PIO[9] & + /* Mask bits to zero which are setting */ + (~(IOCON_PIO_OD_MASK))) + + /* Open-drain mode.: Open-drain mode enabled. Remark: This is not a true open-drain mode. */ + | IOCON_PIO_OD(PIO0_16_OD_ENABLED)); + + IOCON->PIO[29] = ((IOCON->PIO[29] & + /* Mask bits to zero which are setting */ + (~(IOCON_PIO_OD_MASK))) + + /* Open-drain mode.: Open-drain mode enabled. Remark: This is not a true open-drain mode. */ + | IOCON_PIO_OD(PIO0_18_OD_ENABLED)); + + IOCON->PIO[28] = ((IOCON->PIO[28] & + /* Mask bits to zero which are setting */ + (~(IOCON_PIO_OD_MASK))) + + /* Open-drain mode.: Open-drain mode enabled. Remark: This is not a true open-drain mode. */ + | IOCON_PIO_OD(PIO0_22_OD_ENABLED)); + + /* Disable clock for switch matrix. */ + CLOCK_DisableClock(kCLOCK_Swm); +} +/*********************************************************************************************************************** + * EOF + **********************************************************************************************************************/ diff --git a/board/pin_mux.h b/board/pin_mux.h new file mode 100644 index 0000000..84d5b1e --- /dev/null +++ b/board/pin_mux.h @@ -0,0 +1,94 @@ +/*********************************************************************************************************************** + * This file was generated by the MCUXpresso Config Tools. Any manual edits made to this file + * will be overwritten if the respective MCUXpresso Config Tools is used to update this file. + **********************************************************************************************************************/ + +#ifndef _PIN_MUX_H_ +#define _PIN_MUX_H_ + +/*! + * @addtogroup pin_mux + * @{ + */ + +/*********************************************************************************************************************** + * API + **********************************************************************************************************************/ + +#if defined(__cplusplus) +extern "C" { +#endif + +/*! + * @brief Calls initialization functions. + * + */ +void BOARD_InitBootPins(void); + +/*! + * @brief Configures pin routing and optionally pin electrical features. + * + */ +void BOARD_InitDbgUARTPins(void); /* Function assigned for the Cortex-M0P */ + +/*! + * @brief Open-drain mode.: Open-drain mode enabled. Remark: This is not a true open-drain mode. */ +#define PIO0_16_OD_ENABLED 0x01u +/*! + * @brief Open-drain mode.: Open-drain mode enabled. Remark: This is not a true open-drain mode. */ +#define PIO0_18_OD_ENABLED 0x01u +/*! + * @brief Open-drain mode.: Open-drain mode enabled. Remark: This is not a true open-drain mode. */ +#define PIO0_22_OD_ENABLED 0x01u + +/*! @name PIO0_22 (number 30), LED_R + @{ */ + +/* Symbols to be used with GPIO driver */ +#define BOARD_INITLEDPINS_LED_R_GPIO GPIO /*!<@brief GPIO peripheral base pointer */ +#define BOARD_INITLEDPINS_LED_R_GPIO_PIN_MASK (1U << 22U) /*!<@brief GPIO pin mask */ +#define BOARD_INITLEDPINS_LED_R_PORT 0U /*!<@brief PORT device index: 0 */ +#define BOARD_INITLEDPINS_LED_R_PIN 22U /*!<@brief PORT pin number */ +#define BOARD_INITLEDPINS_LED_R_PIN_MASK (1U << 22U) /*!<@brief PORT pin mask */ + /* @} */ + +/*! @name PIO0_18 (number 31), LED_G + @{ */ + +/* Symbols to be used with GPIO driver */ +#define BOARD_INITLEDPINS_LED_G_GPIO GPIO /*!<@brief GPIO peripheral base pointer */ +#define BOARD_INITLEDPINS_LED_G_GPIO_PIN_MASK (1U << 18U) /*!<@brief GPIO pin mask */ +#define BOARD_INITLEDPINS_LED_G_PORT 0U /*!<@brief PORT device index: 0 */ +#define BOARD_INITLEDPINS_LED_G_PIN 18U /*!<@brief PORT pin number */ +#define BOARD_INITLEDPINS_LED_G_PIN_MASK (1U << 18U) /*!<@brief PORT pin mask */ + /* @} */ + +/*! @name PIO0_16 (number 32), LED_B + @{ */ + +/* Symbols to be used with GPIO driver */ +#define BOARD_INITLEDPINS_LED_B_GPIO GPIO /*!<@brief GPIO peripheral base pointer */ +#define BOARD_INITLEDPINS_LED_B_GPIO_PIN_MASK (1U << 16U) /*!<@brief GPIO pin mask */ +#define BOARD_INITLEDPINS_LED_B_PORT 0U /*!<@brief PORT device index: 0 */ +#define BOARD_INITLEDPINS_LED_B_PIN 16U /*!<@brief PORT pin number */ +#define BOARD_INITLEDPINS_LED_B_PIN_MASK (1U << 16U) /*!<@brief PORT pin mask */ + /* @} */ + +/*! + * @brief Configures pin routing and optionally pin electrical features. + * + */ +void BOARD_InitLEDPins(void); /* Function assigned for the Cortex-M0P */ + +#if defined(__cplusplus) +} +#endif + +/*! + * @} + */ +#endif /* _PIN_MUX_H_ */ + +/*********************************************************************************************************************** + * EOF + **********************************************************************************************************************/ diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..d9646b9 --- /dev/null +++ b/src/main.c @@ -0,0 +1,16 @@ +#include "board.h" +#include "clock_config.h" +#include "fsl_debug_console.h" +#include "pin_mux.h" + +int main(void) { + BOARD_InitBootPins(); + BOARD_InitBootClocks(); + BOARD_InitDebugConsole(); + + for (;;) { + GPIO_PortToggle(BOARD_INITLEDPINS_LED_R_GPIO, BOARD_INITLEDPINS_LED_R_PORT, + BOARD_INITLEDPINS_LED_R_GPIO_PIN_MASK); + SDK_DelayAtLeastUs(500 * 1000, CLOCK_GetCoreSysClkFreq()); + } +}