From b8d1385b869106b9b45ce0faf6f2c66e35481e04 Mon Sep 17 00:00:00 2001 From: Raul Munoz Date: Mon, 20 Feb 2017 16:36:28 -0300 Subject: spi: example: add SPI example Add interrupt and polling examples based on the stander colibri SPI (ECSPI3). SODIMM_88 - SPI CLK SODIMM_92 - SPI TXD SODIMM_90 - SPI RXD SODIMM_86 - SPI CS To test this example, connect SODIMM_92 to SODIMM_90 in order to create a loop back. Signed-off-by: Raul Munoz Signed-off-by: Stefan Agner --- .../ecspi_interrupt/master/armgcc/CMakeLists.txt | 134 ++++++++++ .../ecspi_interrupt/master/armgcc/build_all.bat | 5 + .../ecspi_interrupt/master/armgcc/build_all.sh | 5 + .../ecspi_interrupt/master/armgcc/build_debug.bat | 3 + .../ecspi_interrupt/master/armgcc/build_debug.sh | 3 + .../master/armgcc/build_release.bat | 3 + .../ecspi_interrupt/master/armgcc/build_release.sh | 3 + .../ecspi/ecspi_interrupt/master/armgcc/clean.bat | 3 + .../ecspi/ecspi_interrupt/master/armgcc/clean.sh | 3 + .../ecspi/ecspi_interrupt/master/hardware_init.c | 56 ++++ .../ecspi/ecspi_interrupt/master/main.c | 288 +++++++++++++++++++++ .../ecspi_polling/master/armgcc/CMakeLists.txt | 134 ++++++++++ .../ecspi_polling/master/armgcc/build_all.bat | 5 + .../ecspi/ecspi_polling/master/armgcc/build_all.sh | 5 + .../ecspi_polling/master/armgcc/build_debug.bat | 3 + .../ecspi_polling/master/armgcc/build_debug.sh | 3 + .../ecspi_polling/master/armgcc/build_release.bat | 3 + .../ecspi_polling/master/armgcc/build_release.sh | 3 + .../ecspi/ecspi_polling/master/armgcc/clean.bat | 3 + .../ecspi/ecspi_polling/master/armgcc/clean.sh | 3 + .../ecspi/ecspi_polling/master/hardware_init.c | 56 ++++ .../ecspi/ecspi_polling/master/main.c | 135 ++++++++++ 22 files changed, 859 insertions(+) create mode 100644 examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/armgcc/CMakeLists.txt create mode 100644 examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/armgcc/build_all.bat create mode 100755 examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/armgcc/build_all.sh create mode 100644 examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/armgcc/build_debug.bat create mode 100755 examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/armgcc/build_debug.sh create mode 100644 examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/armgcc/build_release.bat create mode 100755 examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/armgcc/build_release.sh create mode 100644 examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/armgcc/clean.bat create mode 100755 examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/armgcc/clean.sh create mode 100644 examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/hardware_init.c create mode 100644 examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/main.c create mode 100644 examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/armgcc/CMakeLists.txt create mode 100644 examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/armgcc/build_all.bat create mode 100755 examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/armgcc/build_all.sh create mode 100644 examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/armgcc/build_debug.bat create mode 100755 examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/armgcc/build_debug.sh create mode 100644 examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/armgcc/build_release.bat create mode 100755 examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/armgcc/build_release.sh create mode 100644 examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/armgcc/clean.bat create mode 100755 examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/armgcc/clean.sh create mode 100644 examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/hardware_init.c create mode 100644 examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/main.c diff --git a/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/armgcc/CMakeLists.txt b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/armgcc/CMakeLists.txt new file mode 100644 index 0000000..d556b13 --- /dev/null +++ b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/armgcc/CMakeLists.txt @@ -0,0 +1,134 @@ +INCLUDE(CMakeForceCompiler) + +# CROSS COMPILER SETTING +SET(CMAKE_SYSTEM_NAME Generic) +CMAKE_MINIMUM_REQUIRED (VERSION 2.6) + +# THE VERSION NUMBER +SET (Tutorial_VERSION_MAJOR 1) +SET (Tutorial_VERSION_MINOR 0) + +# ENABLE ASM +ENABLE_LANGUAGE(ASM) + +SET(CMAKE_STATIC_LIBRARY_PREFIX) +SET(CMAKE_STATIC_LIBRARY_SUFFIX) + +SET(CMAKE_EXECUTABLE_LIBRARY_PREFIX) +SET(CMAKE_EXECUTABLE_LIBRARY_SUFFIX) + + +# CURRENT DIRECTORY +SET(ProjDirPath ${CMAKE_CURRENT_SOURCE_DIR}) + +# DEBUG LINK FILE +set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -T${ProjDirPath}/../../../../../../../platform/devices/MCIMX7D/linker/gcc/MCIMX7D_M4_tcm.ld -static") + +# RELEASE LINK FILE +set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -T${ProjDirPath}/../../../../../../../platform/devices/MCIMX7D/linker/gcc/MCIMX7D_M4_tcm.ld -static") + +# DEBUG ASM FLAGS +SET(CMAKE_ASM_FLAGS_DEBUG "${CMAKE_ASM_FLAGS_DEBUG} -g -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mthumb -Wall -fno-common -ffunction-sections -fdata-sections -ffreestanding -fno-builtin -mapcs -std=gnu99") + +# DEBUG C FLAGS +SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -O0 -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mthumb -MMD -MP -Wall -fno-common -ffunction-sections -fdata-sections -ffreestanding -fno-builtin -mapcs -std=gnu99") + +# DEBUG LD FLAGS +SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -g -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 --specs=nano.specs -lm -Wall -fno-common -ffunction-sections -fdata-sections -ffreestanding -fno-builtin -Os -mthumb -mapcs -Xlinker --gc-sections -Xlinker -static -Xlinker -z -Xlinker muldefs") + +# RELEASE ASM FLAGS +SET(CMAKE_ASM_FLAGS_RELEASE "${CMAKE_ASM_FLAGS_RELEASE} -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mthumb -Wall -fno-common -ffunction-sections -fdata-sections -ffreestanding -fno-builtin -mapcs -std=gnu99") + +# RELEASE C FLAGS +SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Os -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mthumb -MMD -MP -Wall -fno-common -ffunction-sections -fdata-sections -ffreestanding -fno-builtin -mapcs -std=gnu99") + +# RELEASE LD FLAGS +SET(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 --specs=nano.specs -lm -Wall -fno-common -ffunction-sections -fdata-sections -ffreestanding -fno-builtin -Os -mthumb -mapcs -Xlinker --gc-sections -Xlinker -static -Xlinker -z -Xlinker muldefs") + +# ASM MACRO +SET(CMAKE_ASM_FLAGS_DEBUG "${CMAKE_ASM_FLAGS_DEBUG} -D__DEBUG") + +# C MACRO +SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D__DEBUG") +SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DCPU_MCIMX7D_M4") +SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -D__NDEBUG") +SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DCPU_MCIMX7D_M4") + +# CXX MACRO + +# INCLUDE_DIRECTORIES +IF(CMAKE_BUILD_TYPE MATCHES Debug) + INCLUDE_DIRECTORIES(${ProjDirPath}/../../../../..) + INCLUDE_DIRECTORIES(${ProjDirPath}/../../../../../../../platform/CMSIS/Include) + INCLUDE_DIRECTORIES(${ProjDirPath}/../../../../../../../platform/devices) + INCLUDE_DIRECTORIES(${ProjDirPath}/../../../../../../../platform/devices/MCIMX7D/include) + INCLUDE_DIRECTORIES(${ProjDirPath}/../../../../../../../platform/devices/MCIMX7D/startup) + INCLUDE_DIRECTORIES(${ProjDirPath}/../../../../../../../platform/drivers/inc) + INCLUDE_DIRECTORIES(${ProjDirPath}/../../../../../../../platform/utilities/inc) + INCLUDE_DIRECTORIES(${ProjDirPath}/../../../../..) +ELSEIF(CMAKE_BUILD_TYPE MATCHES Release) + INCLUDE_DIRECTORIES(${ProjDirPath}/../../../../..) + INCLUDE_DIRECTORIES(${ProjDirPath}/../../../../../../../platform/CMSIS/Include) + INCLUDE_DIRECTORIES(${ProjDirPath}/../../../../../../../platform/devices) + INCLUDE_DIRECTORIES(${ProjDirPath}/../../../../../../../platform/devices/MCIMX7D/include) + INCLUDE_DIRECTORIES(${ProjDirPath}/../../../../../../../platform/devices/MCIMX7D/startup) + INCLUDE_DIRECTORIES(${ProjDirPath}/../../../../../../../platform/drivers/inc) + INCLUDE_DIRECTORIES(${ProjDirPath}/../../../../../../../platform/utilities/inc) + INCLUDE_DIRECTORIES(${ProjDirPath}/../../../../..) +ENDIF() + +# ADD_EXECUTABLE +ADD_EXECUTABLE(ecspi_interrupt_master_example + "${ProjDirPath}/../../../../../../../platform/devices/MCIMX7D/startup/gcc/startup_MCIMX7D_M4.S" + "${ProjDirPath}/../../../../../../../platform/utilities/src/debug_console_imx.c" + "${ProjDirPath}/../../../../../../../platform/utilities/inc/debug_console_imx.h" + "${ProjDirPath}/../../../../../../../platform/utilities/src/print_scan.c" + "${ProjDirPath}/../../../../../../../platform/utilities/src/print_scan.h" + "${ProjDirPath}/../../../../../../../platform/drivers/inc/ccm_analog_imx7d.h" + "${ProjDirPath}/../../../../../../../platform/drivers/inc/ccm_imx7d.h" + "${ProjDirPath}/../../../../../../../platform/drivers/inc/lmem.h" + "${ProjDirPath}/../../../../../../../platform/drivers/inc/rdc.h" + "${ProjDirPath}/../../../../../../../platform/drivers/inc/rdc_defs_imx7d.h" + "${ProjDirPath}/../../../../../../../platform/drivers/inc/wdog_imx.h" + "${ProjDirPath}/../../../../../../../platform/drivers/src/ccm_analog_imx7d.c" + "${ProjDirPath}/../../../../../../../platform/drivers/src/ccm_imx7d.c" + "${ProjDirPath}/../../../../../../../platform/drivers/src/lmem.c" + "${ProjDirPath}/../../../../../../../platform/drivers/src/rdc.c" + "${ProjDirPath}/../../../../../../../platform/drivers/src/wdog_imx.c" + "${ProjDirPath}/../../../../../../../platform/devices/MCIMX7D/startup/system_MCIMX7D_M4.c" + "${ProjDirPath}/../../../../../../../platform/devices/MCIMX7D/startup/system_MCIMX7D_M4.h" + "${ProjDirPath}/../../../../../pin_mux.c" + "${ProjDirPath}/../../../../../pin_mux.h" + "${ProjDirPath}/../../../../../board.c" + "${ProjDirPath}/../../../../../board.h" + "${ProjDirPath}/../../../../../clock_freq.c" + "${ProjDirPath}/../../../../../clock_freq.h" + "${ProjDirPath}/../hardware_init.c" + "${ProjDirPath}/../main.c" + "${ProjDirPath}/../../../../../../../platform/drivers/src/ecspi.c" + "${ProjDirPath}/../../../../../../../platform/drivers/inc/ecspi.h" + "${ProjDirPath}/../../../../../../../platform/drivers/src/uart_imx.c" + "${ProjDirPath}/../../../../../../../platform/drivers/inc/uart_imx.h" +) +SET_TARGET_PROPERTIES(ecspi_interrupt_master_example PROPERTIES OUTPUT_NAME "ecspi_interrupt_master_example.elf") + +TARGET_LINK_LIBRARIES(ecspi_interrupt_master_example -Wl,--start-group) +# LIBRARIES +IF(CMAKE_BUILD_TYPE MATCHES Debug) +ELSEIF(CMAKE_BUILD_TYPE MATCHES Release) +ENDIF() + +# SYSTEM LIBRARIES +TARGET_LINK_LIBRARIES(ecspi_interrupt_master_example m) +TARGET_LINK_LIBRARIES(ecspi_interrupt_master_example c) +TARGET_LINK_LIBRARIES(ecspi_interrupt_master_example gcc) +TARGET_LINK_LIBRARIES(ecspi_interrupt_master_example nosys) +TARGET_LINK_LIBRARIES(ecspi_interrupt_master_example -Wl,--end-group) + +# MAP FILE +SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -Xlinker -Map=debug/ecspi_interrupt_master_example.map") +SET(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -Xlinker -Map=release/ecspi_interrupt_master_example.map") + +# BIN AND HEX +ADD_CUSTOM_COMMAND(TARGET ecspi_interrupt_master_example POST_BUILD COMMAND ${CMAKE_OBJCOPY} -Oihex ${EXECUTABLE_OUTPUT_PATH}/ecspi_interrupt_master_example.elf ${EXECUTABLE_OUTPUT_PATH}/ecspi_interrupt_master_example.hex) +ADD_CUSTOM_COMMAND(TARGET ecspi_interrupt_master_example POST_BUILD COMMAND ${CMAKE_OBJCOPY} -Obinary ${EXECUTABLE_OUTPUT_PATH}/ecspi_interrupt_master_example.elf ${EXECUTABLE_OUTPUT_PATH}/ecspi_interrupt_master_example.bin) diff --git a/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/armgcc/build_all.bat b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/armgcc/build_all.bat new file mode 100644 index 0000000..1939438 --- /dev/null +++ b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/armgcc/build_all.bat @@ -0,0 +1,5 @@ +cmake -DCMAKE_TOOLCHAIN_FILE="../../../../../../../tools/cmake_toolchain_files/armgcc.cmake" -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Debug . +mingw32-make -j4 +cmake -DCMAKE_TOOLCHAIN_FILE="../../../../../../../tools/cmake_toolchain_files/armgcc.cmake" -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release . +mingw32-make -j4 +pause diff --git a/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/armgcc/build_all.sh b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/armgcc/build_all.sh new file mode 100755 index 0000000..fc1cfb1 --- /dev/null +++ b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/armgcc/build_all.sh @@ -0,0 +1,5 @@ +#!/bin/sh +cmake -DCMAKE_TOOLCHAIN_FILE="../../../../../../../tools/cmake_toolchain_files/armgcc.cmake" -G "Eclipse CDT4 - Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug . +make -j4 +cmake -DCMAKE_TOOLCHAIN_FILE="../../../../../../../tools/cmake_toolchain_files/armgcc.cmake" -G "Eclipse CDT4 - Unix Makefiles" -DCMAKE_BUILD_TYPE=Release . +make -j4 diff --git a/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/armgcc/build_debug.bat b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/armgcc/build_debug.bat new file mode 100644 index 0000000..4950fc9 --- /dev/null +++ b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/armgcc/build_debug.bat @@ -0,0 +1,3 @@ +cmake -DCMAKE_TOOLCHAIN_FILE="../../../../../../../tools/cmake_toolchain_files/armgcc.cmake" -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Debug . +mingw32-make -j4 +pause diff --git a/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/armgcc/build_debug.sh b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/armgcc/build_debug.sh new file mode 100755 index 0000000..869b369 --- /dev/null +++ b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/armgcc/build_debug.sh @@ -0,0 +1,3 @@ +#!/bin/sh +cmake -DCMAKE_TOOLCHAIN_FILE="../../../../../../../tools/cmake_toolchain_files/armgcc.cmake" -G "Eclipse CDT4 - Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug . +make -j4 diff --git a/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/armgcc/build_release.bat b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/armgcc/build_release.bat new file mode 100644 index 0000000..9ec4b80 --- /dev/null +++ b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/armgcc/build_release.bat @@ -0,0 +1,3 @@ +cmake -DCMAKE_TOOLCHAIN_FILE="../../../../../../../tools/cmake_toolchain_files/armgcc.cmake" -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release . +mingw32-make -j4 +pause diff --git a/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/armgcc/build_release.sh b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/armgcc/build_release.sh new file mode 100755 index 0000000..25773b2 --- /dev/null +++ b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/armgcc/build_release.sh @@ -0,0 +1,3 @@ +#!/bin/sh +cmake -DCMAKE_TOOLCHAIN_FILE="../../../../../../../tools/cmake_toolchain_files/armgcc.cmake" -G "Eclipse CDT4 - Unix Makefiles" -DCMAKE_BUILD_TYPE=Release . +make -j4 diff --git a/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/armgcc/clean.bat b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/armgcc/clean.bat new file mode 100644 index 0000000..ffea088 --- /dev/null +++ b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/armgcc/clean.bat @@ -0,0 +1,3 @@ +RD /s /Q Debug Release CMakeFiles +DEL /s /Q /F Makefile cmake_install.cmake CMakeCache.txt +pause diff --git a/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/armgcc/clean.sh b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/armgcc/clean.sh new file mode 100755 index 0000000..795ad87 --- /dev/null +++ b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/armgcc/clean.sh @@ -0,0 +1,3 @@ +#!/bin/sh +rm -rf debug release CMakeFiles +rm -rf Makefile cmake_install.cmake CMakeCache.txt diff --git a/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/hardware_init.c b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/hardware_init.c new file mode 100644 index 0000000..7ba46bc --- /dev/null +++ b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/hardware_init.c @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2015, Freescale Semiconductor, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * o Redistributions of source code must retain the above copyright notice, this list + * of conditions and the following disclaimer. + * + * o 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. + * + * o Neither the name of Freescale Semiconductor, Inc. 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. + */ + +#include "board.h" +#include "pin_mux.h" + +void hardware_init(void) +{ + /* Board specific RDC settings */ + BOARD_RdcInit(); + /* Board specific clock settings */ + BOARD_ClockInit(); + /* initialize debug uart */ + dbg_uart_init(); + + /* RDC ECSPI */ + RDC_SetPdapAccess(RDC, BOARD_ECSPI_RDC_PDAP, 3 << (BOARD_DOMAIN_ID * 2), false, false); + /* Select board ecspi clock derived from OSC clock(24M) */ + CCM_UpdateRoot(CCM, BOARD_ECSPI_CCM_ROOT, ccmRootmuxEcspiOsc24m, 0, 0); + /* Enable ecspi clock gate */ + CCM_EnableRoot(CCM, BOARD_ECSPI_CCM_ROOT); + CCM_ControlGate(CCM, BOARD_ECSPI_CCM_CCGR, ccmClockNeededAll); + /* Configure ecspi pin IOMUX */ + configure_ecspi_pins(BOARD_ECSPI_BASEADDR); +} + +/******************************************************************************* + * EOF + ******************************************************************************/ diff --git a/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/main.c b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/main.c new file mode 100644 index 0000000..5e3391d --- /dev/null +++ b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_interrupt/master/main.c @@ -0,0 +1,288 @@ +/* + * Copyright (c) 2015, Freescale Semiconductor, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * o Redistributions of source code must retain the above copyright notice, this list + * of conditions and the following disclaimer. + * + * o 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. + * + * o Neither the name of Freescale Semiconductor, Inc. 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. + */ + +#include +#include "board.h" +#include "uart_imx.h" +#include "debug_console_imx.h" +#include "ecspi.h" +#include "clock_freq.h" + +/* define ECSPI master mode parameters configuration. */ +#define ECSPI_MASTER_BURSTLENGTH (7) +#define ECSPI_MASTER_STARTMODE (0) + +typedef struct EcspiState +{ + uint8_t* txBuffPtr; /* Pointer to ECSPI Transmit Buffer */ + uint8_t txSize; /* The remaining number of bytes to be transmitted */ + uint8_t* rxBuffPtr; /* Pointer to ECSPI Receive Buffer */ + uint8_t rxSize; /* The remaining number of bytes to be received */ + volatile bool isBusy; /* True if there is a active transfer */ +} ecspi_state_t; + +/* ECSPI runtime state structure */ +static ecspi_state_t ecspiState; + +/* ECSPI master configure */ +static void ECSPI_MasterConfig(ecspi_init_config_t* initConfig); +/* ECSPI data transfer */ +static bool ECSPI_MasterTransfer(uint8_t* txBuffer, uint8_t* rxBuffer, uint32_t transferSize); +static bool ECSPI_MasterReceiveBurst(void); +static bool ECSPI_MasterTransmitBurst(void); +/* ECSPI transfer status */ +static bool ECSPI_MasterGetTransferStatus(void); + +/* Transferred data */ +static uint8_t txData[1] = {0}; +static uint8_t rxData[1] = {0}; + +int main(void) +{ + uint8_t control_char; + uint8_t i; + + ecspi_init_config_t ecspiMasterInitConfig = { + .baudRate = 500000, + .mode = ecspiMasterMode, + .burstLength = ECSPI_MASTER_BURSTLENGTH, + .channelSelect = BOARD_ECSPI_CHANNEL, + .clockPhase = ecspiClockPhaseSecondEdge, + .clockPolarity = ecspiClockPolarityActiveHigh, + .ecspiAutoStart = ECSPI_MASTER_STARTMODE + }; + + /* Hardware initialize, include RDC, CLOCK, IOMUX, ENABLE MODULE */ + hardware_init(); + + /* Update clock frequency of this module */ + ecspiMasterInitConfig.clockRate = get_ecspi_clock_freq(BOARD_ECSPI_BASEADDR); + + PRINTF("\n-------------- ECSPI master driver example --------------\n\n\r"); + PRINTF("This example application demonstrates usage of SPI driver in master mode.\n\r"); + PRINTF("It transfers data to/from remote MCU in SPI slave mode.\n\r"); + + /* Ecspi module initialize, include configure parameters */ + ECSPI_MasterConfig(&ecspiMasterInitConfig); + + /* Wait slave ready, then press 's' to start communication. */ + while(true) + { + PRINTF("Press \"s\" when spi slave is ready.\n\r"); + control_char = GETCHAR(); + if((control_char == 's') || (control_char == 'S')) + break; + } + + /* Send 1~20 to slave and receive data from slave */ + for(i = 0; i < 20; i++) + { + txData[0]++; + ECSPI_MasterTransfer((uint8_t*)txData, (uint8_t*)rxData, 1); + while(ECSPI_MasterGetTransferStatus()); + PRINTF("MASTER: Transmited data: %d \n\r", txData[0]); + PRINTF(" : Received data: %d \n\n\r", rxData[0]); + } + while(1); +} + +/****************************************************************************** +* +* Function Name: ECSPI_MasterTransmitBurst +* Comments: Fill the TXFIFO. +* +******************************************************************************/ +static bool ECSPI_MasterTransmitBurst(void) +{ + uint8_t bytes; + uint32_t data; + uint8_t i; + + /* Fill the TXFIFO */ + while((ecspiState.txSize > 0) && (ECSPI_GetStatusFlag(BOARD_ECSPI_BASEADDR, ecspiFlagTxfifoFull) == 0)) + { + bytes = ecspiState.txSize & 0x3; /* first get unaligned part transmitted */ + bytes = bytes ? bytes : 4; /* if aligned, then must be 4 */ + + if(!(ecspiState.txBuffPtr)) + { + data = 0xFFFFFFFF; /* half-duplex receive data */ + } + else + { + data = 0; + for(i = 0; i < bytes; i++) + data = (data << 8) | *(ecspiState.txBuffPtr)++; + } + + ECSPI_SendData(BOARD_ECSPI_BASEADDR, data); + ecspiState.txSize -= bytes; + ecspiState.rxSize += bytes; + } + /* start transmission */ + ECSPI_StartBurst(BOARD_ECSPI_BASEADDR); + /* set transfer flag */ + ecspiState.isBusy = true; + return true; +} + +/****************************************************************************** +* +* Function Name: ECSPI_MasterReceiveBurst +* Comments: Receive data from RXFIFO +* +******************************************************************************/ +static bool ECSPI_MasterReceiveBurst(void) +{ + uint32_t data; + uint32_t bytes; + uint32_t i; + + while ((ecspiState.rxSize > 0) && (ECSPI_GetStatusFlag(BOARD_ECSPI_BASEADDR, ecspiFlagRxfifoReady) != 0)) + { + data = ECSPI_ReceiveData(BOARD_ECSPI_BASEADDR); /* read data from register */ + bytes = ecspiState.rxSize & 0x3; /* first get unaligned part received */ + bytes = bytes ? bytes : 4; /* if aligned, then must be 4 */ + + if(ecspiState.rxBuffPtr) /* not half-duplex transmit */ + { + for(i = bytes; i > 0; i--) + { + *(ecspiState.rxBuffPtr + i - 1) = data & 0xFF; + data >>= 8; + } + ecspiState.rxBuffPtr += bytes; + } + ecspiState.rxSize -= bytes; + } + return true; +} + +/****************************************************************************** +* +* Function Name: ECSPI_MasterTransfer +* Comments: Transmit and Receive an amount of data in no-blocking mode with +* interrupt. +* +******************************************************************************/ +static bool ECSPI_MasterTransfer(uint8_t* txBuffer, uint8_t* rxBuffer, uint32_t transferSize) +{ + uint32_t len; + + if((ecspiState.isBusy) || (transferSize == 0)) + { + return false; + } + + /* Update the burst length to real size */ + len = (uint32_t)(transferSize * 8 - 1); + ECSPI_SetBurstLength(BOARD_ECSPI_BASEADDR, len); + + /* Configure the transfer */ + ecspiState.txBuffPtr = txBuffer; + ecspiState.rxBuffPtr = rxBuffer; + ecspiState.txSize = transferSize; + ecspiState.rxSize = 0; + + /* Fill the TXFIFO */ + ECSPI_MasterTransmitBurst(); + /* Enable interrupts */ + ECSPI_SetIntCmd(BOARD_ECSPI_BASEADDR, ecspiFlagTxfifoEmpty, true); + return true; +} + +/****************************************************************************** +* +* Function Name: ECSPI_MasterGetTransferStatus +* Comments: Get transfer status. +* +******************************************************************************/ +static bool ECSPI_MasterGetTransferStatus(void) +{ + return ecspiState.isBusy; +} + +/****************************************************************************** +* +* Function Name: ECSPI_MasterConfig +* Comments: ECSPI module initialize +* +******************************************************************************/ +static void ECSPI_MasterConfig(ecspi_init_config_t* initConfig) +{ + /* Initialize ECSPI transfer state. */ + ecspiState.isBusy = false; + + /* Initialize ECSPI, parameter configure */ + ECSPI_Init(BOARD_ECSPI_BASEADDR, initConfig); + + /* Call core API to enable the IRQ. */ + NVIC_EnableIRQ(BOARD_ECSPI_IRQ_NUM); +} + +/****************************************************************************** +* +* Function Name: BOARD_ECSPI_MASTER_HANDLER +* Comments: The interrupt service routine triggered by ECSPI interrupt +* +******************************************************************************/ +void BOARD_ECSPI_HANDLER(void) +{ + /* Receive data from RXFIFO */ + ECSPI_MasterReceiveBurst(); + + /* Push data left */ + if(ecspiState.txSize) + { + ECSPI_MasterTransmitBurst(); + return; + } + + /* No data left to push, but still waiting for rx data, enable receive data available interrupt. */ + if(ecspiState.rxSize) + { + ECSPI_SetIntCmd(BOARD_ECSPI_BASEADDR, ecspiFlagRxfifoReady, true); + return; + } + + /* Disable interrupt */ + ECSPI_SetIntCmd(BOARD_ECSPI_BASEADDR, ecspiFlagTxfifoEmpty, false); + ECSPI_SetIntCmd(BOARD_ECSPI_BASEADDR, ecspiFlagRxfifoReady, false); + + /* Clear the status */ + ECSPI_ClearStatusFlag(BOARD_ECSPI_BASEADDR, ecspiFlagTxfifoTc); + ECSPI_ClearStatusFlag(BOARD_ECSPI_BASEADDR, ecspiFlagRxfifoOverflow); + + ecspiState.isBusy = false; +} + +/******************************************************************************* + * EOF + ******************************************************************************/ diff --git a/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/armgcc/CMakeLists.txt b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/armgcc/CMakeLists.txt new file mode 100644 index 0000000..aed18a3 --- /dev/null +++ b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/armgcc/CMakeLists.txt @@ -0,0 +1,134 @@ +INCLUDE(CMakeForceCompiler) + +# CROSS COMPILER SETTING +SET(CMAKE_SYSTEM_NAME Generic) +CMAKE_MINIMUM_REQUIRED (VERSION 2.6) + +# THE VERSION NUMBER +SET (Tutorial_VERSION_MAJOR 1) +SET (Tutorial_VERSION_MINOR 0) + +# ENABLE ASM +ENABLE_LANGUAGE(ASM) + +SET(CMAKE_STATIC_LIBRARY_PREFIX) +SET(CMAKE_STATIC_LIBRARY_SUFFIX) + +SET(CMAKE_EXECUTABLE_LIBRARY_PREFIX) +SET(CMAKE_EXECUTABLE_LIBRARY_SUFFIX) + + +# CURRENT DIRECTORY +SET(ProjDirPath ${CMAKE_CURRENT_SOURCE_DIR}) + +# DEBUG LINK FILE +set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -T${ProjDirPath}/../../../../../../../platform/devices/MCIMX7D/linker/gcc/MCIMX7D_M4_tcm.ld -static") + +# RELEASE LINK FILE +set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -T${ProjDirPath}/../../../../../../../platform/devices/MCIMX7D/linker/gcc/MCIMX7D_M4_tcm.ld -static") + +# DEBUG ASM FLAGS +SET(CMAKE_ASM_FLAGS_DEBUG "${CMAKE_ASM_FLAGS_DEBUG} -g -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mthumb -Wall -fno-common -ffunction-sections -fdata-sections -ffreestanding -fno-builtin -mapcs -std=gnu99") + +# DEBUG C FLAGS +SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -O0 -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mthumb -MMD -MP -Wall -fno-common -ffunction-sections -fdata-sections -ffreestanding -fno-builtin -mapcs -std=gnu99") + +# DEBUG LD FLAGS +SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -g -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 --specs=nano.specs -lm -Wall -fno-common -ffunction-sections -fdata-sections -ffreestanding -fno-builtin -Os -mthumb -mapcs -Xlinker --gc-sections -Xlinker -static -Xlinker -z -Xlinker muldefs") + +# RELEASE ASM FLAGS +SET(CMAKE_ASM_FLAGS_RELEASE "${CMAKE_ASM_FLAGS_RELEASE} -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mthumb -Wall -fno-common -ffunction-sections -fdata-sections -ffreestanding -fno-builtin -mapcs -std=gnu99") + +# RELEASE C FLAGS +SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Os -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mthumb -MMD -MP -Wall -fno-common -ffunction-sections -fdata-sections -ffreestanding -fno-builtin -mapcs -std=gnu99") + +# RELEASE LD FLAGS +SET(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 --specs=nano.specs -lm -Wall -fno-common -ffunction-sections -fdata-sections -ffreestanding -fno-builtin -Os -mthumb -mapcs -Xlinker --gc-sections -Xlinker -static -Xlinker -z -Xlinker muldefs") + +# ASM MACRO +SET(CMAKE_ASM_FLAGS_DEBUG "${CMAKE_ASM_FLAGS_DEBUG} -D__DEBUG") + +# C MACRO +SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D__DEBUG") +SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DCPU_MCIMX7D_M4") +SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -D__NDEBUG") +SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DCPU_MCIMX7D_M4") + +# CXX MACRO + +# INCLUDE_DIRECTORIES +IF(CMAKE_BUILD_TYPE MATCHES Debug) + INCLUDE_DIRECTORIES(${ProjDirPath}/../../../../..) + INCLUDE_DIRECTORIES(${ProjDirPath}/../../../../../../../platform/CMSIS/Include) + INCLUDE_DIRECTORIES(${ProjDirPath}/../../../../../../../platform/devices) + INCLUDE_DIRECTORIES(${ProjDirPath}/../../../../../../../platform/devices/MCIMX7D/include) + INCLUDE_DIRECTORIES(${ProjDirPath}/../../../../../../../platform/devices/MCIMX7D/startup) + INCLUDE_DIRECTORIES(${ProjDirPath}/../../../../../../../platform/drivers/inc) + INCLUDE_DIRECTORIES(${ProjDirPath}/../../../../../../../platform/utilities/inc) + INCLUDE_DIRECTORIES(${ProjDirPath}/../../../../..) +ELSEIF(CMAKE_BUILD_TYPE MATCHES Release) + INCLUDE_DIRECTORIES(${ProjDirPath}/../../../../..) + INCLUDE_DIRECTORIES(${ProjDirPath}/../../../../../../../platform/CMSIS/Include) + INCLUDE_DIRECTORIES(${ProjDirPath}/../../../../../../../platform/devices) + INCLUDE_DIRECTORIES(${ProjDirPath}/../../../../../../../platform/devices/MCIMX7D/include) + INCLUDE_DIRECTORIES(${ProjDirPath}/../../../../../../../platform/devices/MCIMX7D/startup) + INCLUDE_DIRECTORIES(${ProjDirPath}/../../../../../../../platform/drivers/inc) + INCLUDE_DIRECTORIES(${ProjDirPath}/../../../../../../../platform/utilities/inc) + INCLUDE_DIRECTORIES(${ProjDirPath}/../../../../..) +ENDIF() + +# ADD_EXECUTABLE +ADD_EXECUTABLE(ecspi_polling_master_example + "${ProjDirPath}/../../../../../../../platform/devices/MCIMX7D/startup/gcc/startup_MCIMX7D_M4.S" + "${ProjDirPath}/../../../../../../../platform/utilities/src/debug_console_imx.c" + "${ProjDirPath}/../../../../../../../platform/utilities/inc/debug_console_imx.h" + "${ProjDirPath}/../../../../../../../platform/utilities/src/print_scan.c" + "${ProjDirPath}/../../../../../../../platform/utilities/src/print_scan.h" + "${ProjDirPath}/../../../../../../../platform/drivers/inc/ccm_analog_imx7d.h" + "${ProjDirPath}/../../../../../../../platform/drivers/inc/ccm_imx7d.h" + "${ProjDirPath}/../../../../../../../platform/drivers/inc/lmem.h" + "${ProjDirPath}/../../../../../../../platform/drivers/inc/rdc.h" + "${ProjDirPath}/../../../../../../../platform/drivers/inc/rdc_defs_imx7d.h" + "${ProjDirPath}/../../../../../../../platform/drivers/inc/wdog_imx.h" + "${ProjDirPath}/../../../../../../../platform/drivers/src/ccm_analog_imx7d.c" + "${ProjDirPath}/../../../../../../../platform/drivers/src/ccm_imx7d.c" + "${ProjDirPath}/../../../../../../../platform/drivers/src/lmem.c" + "${ProjDirPath}/../../../../../../../platform/drivers/src/rdc.c" + "${ProjDirPath}/../../../../../../../platform/drivers/src/wdog_imx.c" + "${ProjDirPath}/../../../../../../../platform/devices/MCIMX7D/startup/system_MCIMX7D_M4.c" + "${ProjDirPath}/../../../../../../../platform/devices/MCIMX7D/startup/system_MCIMX7D_M4.h" + "${ProjDirPath}/../../../../../pin_mux.c" + "${ProjDirPath}/../../../../../pin_mux.h" + "${ProjDirPath}/../../../../../board.c" + "${ProjDirPath}/../../../../../board.h" + "${ProjDirPath}/../../../../../clock_freq.c" + "${ProjDirPath}/../../../../../clock_freq.h" + "${ProjDirPath}/../hardware_init.c" + "${ProjDirPath}/../main.c" + "${ProjDirPath}/../../../../../../../platform/drivers/src/ecspi.c" + "${ProjDirPath}/../../../../../../../platform/drivers/inc/ecspi.h" + "${ProjDirPath}/../../../../../../../platform/drivers/src/uart_imx.c" + "${ProjDirPath}/../../../../../../../platform/drivers/inc/uart_imx.h" +) +SET_TARGET_PROPERTIES(ecspi_polling_master_example PROPERTIES OUTPUT_NAME "ecspi_polling_master_example.elf") + +TARGET_LINK_LIBRARIES(ecspi_polling_master_example -Wl,--start-group) +# LIBRARIES +IF(CMAKE_BUILD_TYPE MATCHES Debug) +ELSEIF(CMAKE_BUILD_TYPE MATCHES Release) +ENDIF() + +# SYSTEM LIBRARIES +TARGET_LINK_LIBRARIES(ecspi_polling_master_example m) +TARGET_LINK_LIBRARIES(ecspi_polling_master_example c) +TARGET_LINK_LIBRARIES(ecspi_polling_master_example gcc) +TARGET_LINK_LIBRARIES(ecspi_polling_master_example nosys) +TARGET_LINK_LIBRARIES(ecspi_polling_master_example -Wl,--end-group) + +# MAP FILE +SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -Xlinker -Map=debug/ecspi_polling_master_example.map") +SET(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -Xlinker -Map=release/ecspi_polling_master_example.map") + +# BIN AND HEX +ADD_CUSTOM_COMMAND(TARGET ecspi_polling_master_example POST_BUILD COMMAND ${CMAKE_OBJCOPY} -Oihex ${EXECUTABLE_OUTPUT_PATH}/ecspi_polling_master_example.elf ${EXECUTABLE_OUTPUT_PATH}/ecspi_polling_master_example.hex) +ADD_CUSTOM_COMMAND(TARGET ecspi_polling_master_example POST_BUILD COMMAND ${CMAKE_OBJCOPY} -Obinary ${EXECUTABLE_OUTPUT_PATH}/ecspi_polling_master_example.elf ${EXECUTABLE_OUTPUT_PATH}/ecspi_polling_master_example.bin) diff --git a/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/armgcc/build_all.bat b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/armgcc/build_all.bat new file mode 100644 index 0000000..1939438 --- /dev/null +++ b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/armgcc/build_all.bat @@ -0,0 +1,5 @@ +cmake -DCMAKE_TOOLCHAIN_FILE="../../../../../../../tools/cmake_toolchain_files/armgcc.cmake" -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Debug . +mingw32-make -j4 +cmake -DCMAKE_TOOLCHAIN_FILE="../../../../../../../tools/cmake_toolchain_files/armgcc.cmake" -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release . +mingw32-make -j4 +pause diff --git a/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/armgcc/build_all.sh b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/armgcc/build_all.sh new file mode 100755 index 0000000..fc1cfb1 --- /dev/null +++ b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/armgcc/build_all.sh @@ -0,0 +1,5 @@ +#!/bin/sh +cmake -DCMAKE_TOOLCHAIN_FILE="../../../../../../../tools/cmake_toolchain_files/armgcc.cmake" -G "Eclipse CDT4 - Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug . +make -j4 +cmake -DCMAKE_TOOLCHAIN_FILE="../../../../../../../tools/cmake_toolchain_files/armgcc.cmake" -G "Eclipse CDT4 - Unix Makefiles" -DCMAKE_BUILD_TYPE=Release . +make -j4 diff --git a/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/armgcc/build_debug.bat b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/armgcc/build_debug.bat new file mode 100644 index 0000000..4950fc9 --- /dev/null +++ b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/armgcc/build_debug.bat @@ -0,0 +1,3 @@ +cmake -DCMAKE_TOOLCHAIN_FILE="../../../../../../../tools/cmake_toolchain_files/armgcc.cmake" -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Debug . +mingw32-make -j4 +pause diff --git a/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/armgcc/build_debug.sh b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/armgcc/build_debug.sh new file mode 100755 index 0000000..869b369 --- /dev/null +++ b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/armgcc/build_debug.sh @@ -0,0 +1,3 @@ +#!/bin/sh +cmake -DCMAKE_TOOLCHAIN_FILE="../../../../../../../tools/cmake_toolchain_files/armgcc.cmake" -G "Eclipse CDT4 - Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug . +make -j4 diff --git a/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/armgcc/build_release.bat b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/armgcc/build_release.bat new file mode 100644 index 0000000..9ec4b80 --- /dev/null +++ b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/armgcc/build_release.bat @@ -0,0 +1,3 @@ +cmake -DCMAKE_TOOLCHAIN_FILE="../../../../../../../tools/cmake_toolchain_files/armgcc.cmake" -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release . +mingw32-make -j4 +pause diff --git a/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/armgcc/build_release.sh b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/armgcc/build_release.sh new file mode 100755 index 0000000..25773b2 --- /dev/null +++ b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/armgcc/build_release.sh @@ -0,0 +1,3 @@ +#!/bin/sh +cmake -DCMAKE_TOOLCHAIN_FILE="../../../../../../../tools/cmake_toolchain_files/armgcc.cmake" -G "Eclipse CDT4 - Unix Makefiles" -DCMAKE_BUILD_TYPE=Release . +make -j4 diff --git a/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/armgcc/clean.bat b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/armgcc/clean.bat new file mode 100644 index 0000000..ffea088 --- /dev/null +++ b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/armgcc/clean.bat @@ -0,0 +1,3 @@ +RD /s /Q Debug Release CMakeFiles +DEL /s /Q /F Makefile cmake_install.cmake CMakeCache.txt +pause diff --git a/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/armgcc/clean.sh b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/armgcc/clean.sh new file mode 100755 index 0000000..795ad87 --- /dev/null +++ b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/armgcc/clean.sh @@ -0,0 +1,3 @@ +#!/bin/sh +rm -rf debug release CMakeFiles +rm -rf Makefile cmake_install.cmake CMakeCache.txt diff --git a/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/hardware_init.c b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/hardware_init.c new file mode 100644 index 0000000..7ba46bc --- /dev/null +++ b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/hardware_init.c @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2015, Freescale Semiconductor, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * o Redistributions of source code must retain the above copyright notice, this list + * of conditions and the following disclaimer. + * + * o 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. + * + * o Neither the name of Freescale Semiconductor, Inc. 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. + */ + +#include "board.h" +#include "pin_mux.h" + +void hardware_init(void) +{ + /* Board specific RDC settings */ + BOARD_RdcInit(); + /* Board specific clock settings */ + BOARD_ClockInit(); + /* initialize debug uart */ + dbg_uart_init(); + + /* RDC ECSPI */ + RDC_SetPdapAccess(RDC, BOARD_ECSPI_RDC_PDAP, 3 << (BOARD_DOMAIN_ID * 2), false, false); + /* Select board ecspi clock derived from OSC clock(24M) */ + CCM_UpdateRoot(CCM, BOARD_ECSPI_CCM_ROOT, ccmRootmuxEcspiOsc24m, 0, 0); + /* Enable ecspi clock gate */ + CCM_EnableRoot(CCM, BOARD_ECSPI_CCM_ROOT); + CCM_ControlGate(CCM, BOARD_ECSPI_CCM_CCGR, ccmClockNeededAll); + /* Configure ecspi pin IOMUX */ + configure_ecspi_pins(BOARD_ECSPI_BASEADDR); +} + +/******************************************************************************* + * EOF + ******************************************************************************/ diff --git a/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/main.c b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/main.c new file mode 100644 index 0000000..95f080d --- /dev/null +++ b/examples/imx7_colibri_m4/driver_examples/ecspi/ecspi_polling/master/main.c @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2015, Freescale Semiconductor, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * o Redistributions of source code must retain the above copyright notice, this list + * of conditions and the following disclaimer. + * + * o 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. + * + * o Neither the name of Freescale Semiconductor, Inc. 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. + */ + +#include +#include "board.h" +#include "debug_console_imx.h" +#include "ecspi.h" +#include "clock_freq.h" + +/* define ECSPI master mode parameters configuration. */ +#define ECSPI_MASTER_BURSTLENGTH (7) +#define ECSPI_MASTER_STARTMODE (0) +#define BURST_LENGTH_IN_BYTES(x) ((8 * x) - 1) + +/* ECSPI data transfer */ +static bool ECSPI_MasterTransfer(uint8_t* txBuffer, uint8_t* rxBuffer, uint32_t transferSize); + +int main(void) +{ + uint8_t txData = 0; + uint8_t rxData = 0; + uint8_t control_char; + + ecspi_init_config_t initConfig = { + .baudRate = 500000, + .mode = ecspiMasterMode, + .burstLength = ECSPI_MASTER_BURSTLENGTH, + .channelSelect = BOARD_ECSPI_CHANNEL, + .clockPhase = ecspiClockPhaseSecondEdge, + .clockPolarity = ecspiClockPolarityActiveHigh, + .ecspiAutoStart = ECSPI_MASTER_STARTMODE + }; + + /* Hardware initialize, include RDC, CLOCK, IOMUX, ENABLE MODULE */ + hardware_init(); + + /* Update clock frequency of this module */ + initConfig.clockRate = get_ecspi_clock_freq(BOARD_ECSPI_BASEADDR); + + PRINTF("\n-------------- ECSPI master driver example --------------\n\n\r"); + PRINTF("This example application demonstrates usage of SPI driver in master mode.\n\r"); + PRINTF("It transfers data to/from remote MCU in SPI slave mode.\n\r"); + + /* Ecspi module initialize, include configure parameters */ + ECSPI_Init(BOARD_ECSPI_BASEADDR, &initConfig); + + /* Wait slave ready, then press 's' to start communication. */ + while (true) + { + PRINTF("Press \"s\" when SPI slave is ready.\n\r"); + control_char = GETCHAR(); + if ((control_char == 's') || (control_char == 'S')) + break; + } + + /* Send 1~20 to slave and receive data from slave */ + for (uint8_t i = 0; i < 20; i++) + { + txData++; + ECSPI_MasterTransfer(&txData, &rxData, 1); + PRINTF("MASTER: Transmited data: %d \n\r", txData); + PRINTF(" : Received data: %d \n\r", rxData); + } + + PRINTF("Example finish!!!\n\r"); + while (1) + __WFI(); +} + +/****************************************************************************** +* +* Function Name: ECSPI_MasterTransfer +* Comments: Transmit and Receive an amount of data in no-blocking mode with +* interrupt. +* +******************************************************************************/ +static bool ECSPI_MasterTransfer(uint8_t* txBuffer, uint8_t* rxBuffer, uint32_t transferSize) +{ + if (0 == transferSize) + return false; + + /* Set the burst length to one byte(8 bits) */ + ECSPI_SetBurstLength(BOARD_ECSPI_BASEADDR, BURST_LENGTH_IN_BYTES(1)); + + while (transferSize) + { + /* Fill the TXFIFO */ + ECSPI_SendData(BOARD_ECSPI_BASEADDR, *txBuffer++); + + /* start transmission */ + ECSPI_StartBurst(BOARD_ECSPI_BASEADDR); + + /* Wait transmission finish */ + while (!ECSPI_GetStatusFlag(BOARD_ECSPI_BASEADDR, ecspiFlagTxfifoTc)); + ECSPI_ClearStatusFlag(BOARD_ECSPI_BASEADDR, ecspiFlagTxfifoTc); + + /* Fill the RXFIFO */ + *rxBuffer = ECSPI_ReceiveData(BOARD_ECSPI_BASEADDR); + + transferSize--; + } + + return true; +} + +/******************************************************************************* + * EOF + ******************************************************************************/ -- cgit v1.2.3