diff --git a/.clang-format b/.clang-format index 7ba2003..214adf0 100644 --- a/.clang-format +++ b/.clang-format @@ -1,8 +1,9 @@ BasedOnStyle: Google IndentWidth: 4 -AlignConsecutiveMacros: AcrossEmptyLines -AlignConsecutiveDeclarations: AcrossEmptyLines -AlignConsecutiveAssignments: AcrossEmptyLinesAndComments +AlignConsecutiveMacros: Consecutive +AlignConsecutiveDeclarations: Consecutive +AlignConsecutiveAssignments: Consecutive +AllowShortFunctionsOnASingleLine: None BreakBeforeBraces: Custom BraceWrapping: AfterEnum: false diff --git a/.gitmodules b/.gitmodules index e537b8d..f912afc 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "SDK"] path = SDK - url = git@git.minori.work:Embedded_SDK/MCUXpresso_MIMXRT1052xxxxB.git + url = https://git.minori.work/Embedded_SDK/MCUXpresso_MIMXRT1052xxxxB.git +[submodule "lib/threadx"] + path = lib/threadx + url = https://github.com/azure-rtos/threadx.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 5698557..9cb484c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.10) -project(fire_rt1052_pro_template) +project(fire_rt1052_pro_azrtos_hello) enable_language(CXX) enable_language(ASM) @@ -95,6 +95,8 @@ set(TARGET_SOURCES "board/dcd.c" "board/peripherals.c" "board/pin_mux.c" + "src/app_entry.c" + "src/app_thr_hello.c" "src/main.c" "xip/fire_rt1052_pro_flexspi_nor_config.c" ) @@ -131,6 +133,7 @@ set(TARGET_C_INCLUDES # Shared libraries linked with application set(TARGET_LIBS + "threadx" "c" "m" "nosys" @@ -159,6 +162,11 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-common -fno-builtin -f set(CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS} -x assembler-with-cpp") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") +set(THREADX_ARCH "cortex_m7" CACHE STRING "") +set(THREADX_TOOLCHAIN "gnu" CACHE STRING "") +set(TX_USER_FILE "${CMAKE_CURRENT_SOURCE_DIR}/include/tx_user.h" CACHE STRING "") +add_subdirectory(lib/threadx) + # Shared sources, includes and definitions add_compile_definitions(${TARGET_C_DEFINES}) include_directories(${TARGET_C_INCLUDES}) diff --git a/MIMXRT1052xxxxB.mex b/MIMXRT1052xxxxB.mex index 6d55fc0..79f0423 100644 --- a/MIMXRT1052xxxxB.mex +++ b/MIMXRT1052xxxxB.mex @@ -1,5 +1,5 @@ - + MIMXRT1052xxxxB MIMXRT1052DVL6B @@ -17,13 +17,13 @@ false - + - 13.0.1 + 13.0.2 @@ -34,6 +34,9 @@ + + + @@ -109,8 +112,8 @@ - + @@ -712,6 +715,53 @@ + + Configures pin routing and optionally pin electrical features. + + true + core0 + true + + + + + true + + + + + true + + + + + true + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -720,7 +770,7 @@ - 13.0.1 + 13.0.2 @@ -984,7 +1034,7 @@ - 13.0.1 + 13.0.2 c_array @@ -1001,7 +1051,7 @@ - 13.0.1 + 13.0.2 diff --git a/SDK b/SDK new file mode 160000 index 0000000..c2668b7 --- /dev/null +++ b/SDK @@ -0,0 +1 @@ +Subproject commit c2668b7ca02d42d9e8638a8d92fdbf8656a54099 diff --git a/board/clock_config.c b/board/clock_config.c index 2b11cda..f6bf0e3 100644 --- a/board/clock_config.c +++ b/board/clock_config.c @@ -19,7 +19,7 @@ product: Clocks v11.0 processor: MIMXRT1052xxxxB package_id: MIMXRT1052DVL6B mcu_data: ksdk2_0 -processor_version: 13.0.1 +processor_version: 13.0.2 * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/ #include "clock_config.h" diff --git a/board/dcd.c b/board/dcd.c index b4902c3..5b24225 100644 --- a/board/dcd.c +++ b/board/dcd.c @@ -24,7 +24,7 @@ product: DCDx v3.0 processor: MIMXRT1052xxxxB package_id: MIMXRT1052DVL6B mcu_data: ksdk2_0 -processor_version: 13.0.1 +processor_version: 13.0.2 output_format: c_array * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/ /* COMMENTS BELOW ARE USED AS SETTINGS FOR DCD DATA */ diff --git a/board/peripherals.c b/board/peripherals.c index f35aa88..b62d9fa 100644 --- a/board/peripherals.c +++ b/board/peripherals.c @@ -10,7 +10,7 @@ product: Peripherals v12.0 processor: MIMXRT1052xxxxB package_id: MIMXRT1052DVL6B mcu_data: ksdk2_0 -processor_version: 13.0.1 +processor_version: 13.0.2 functionalGroups: - name: BOARD_InitPeripherals UUID: 19596643-a9d0-4000-b44d-6a0a05ec6830 diff --git a/board/pin_mux.c b/board/pin_mux.c index 2aed03a..956eeec 100644 --- a/board/pin_mux.c +++ b/board/pin_mux.c @@ -6,11 +6,11 @@ /* * TEXT BELOW IS USED AS SETTING FOR TOOLS ************************************* !!GlobalInfo -product: Pins v13.0 +product: Pins v13.1 processor: MIMXRT1052xxxxB package_id: MIMXRT1052DVL6B mcu_data: ksdk2_0 -processor_version: 13.0.1 +processor_version: 13.0.2 pin_labels: - {pin_num: C7, pin_signal: GPIO_EMC_41, label: LED_B, identifier: LED_R;LED_B} - {pin_num: B12, pin_signal: GPIO_B1_07, label: LED_G, identifier: LED_G} @@ -21,6 +21,9 @@ pin_labels: - {pin_num: H10, pin_signal: GPIO_AD_B0_01, label: CSI_RST, identifier: CSI_RST} - {pin_num: G11, pin_signal: GPIO_AD_B0_03, label: BUZZER, identifier: BUZZER} - {pin_num: L6, pin_signal: WAKEUP, label: WAKEUP, identifier: WAKEUP} +- {pin_num: G13, pin_signal: GPIO_AD_B0_10, label: LED_B, identifier: LED_B} +- {pin_num: H13, pin_signal: GPIO_AD_B1_08, label: LED_R, identifier: LED_R} +- {pin_num: M13, pin_signal: GPIO_AD_B1_09, label: LED_G, identifier: LED_G} power_domains: {DCDC_IN: '3.3', DCDC_IN_Q: '3.3', DCDC_LP: '1.25', DCDC_PSWITCH: '3.3', DCDC_SENSE: '1.25', NVCC_EMC: '3.3', NVCC_GPIO: '3.3', NVCC_SD0: '3.3', NVCC_SD1: '3.3', VDDA_ADC_3P3: '3.3', VDD_HIGH_CAP: '1.1', VDD_HIGH_IN: '3.3', VDD_SNVS_CAP: '1.1', VDD_SNVS_IN: '3.3', VDD_SOC_IN: '1.25', VDD_USB_CAP: '2.5'} * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS *********** @@ -41,6 +44,7 @@ void BOARD_InitBootPins(void) { BOARD_InitUARTDbgPins(); BOARD_InitSWDPins(); BOARD_InitFlexSPIPins(); + BOARD_InitCLEDPins(); } /* @@ -80,8 +84,8 @@ void BOARD_InitUARTDbgPins(void) { BOARD_InitSWDPins: - options: {callFromInitBoot: 'true', coreID: core0, enableClock: 'true'} - pin_list: - - {pin_num: E14, peripheral: JTAG, signal: TMS, pin_signal: GPIO_AD_B0_06} - {pin_num: F12, peripheral: JTAG, signal: TCK, pin_signal: GPIO_AD_B0_07} + - {pin_num: E14, peripheral: JTAG, signal: TMS, pin_signal: GPIO_AD_B0_06} * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS *********** */ @@ -808,6 +812,60 @@ void BOARD_InitSPDIFPins(void) { IOMUXC_SetPinMux(IOMUXC_GPIO_AD_B1_03_SPDIF_IN, 0U); } + +/* + * TEXT BELOW IS USED AS SETTING FOR TOOLS ************************************* +BOARD_InitCLEDPins: +- options: {callFromInitBoot: 'true', coreID: core0, enableClock: 'true'} +- pin_list: + - {pin_num: G13, peripheral: GPIO1, signal: 'gpio_io, 10', pin_signal: GPIO_AD_B0_10, direction: OUTPUT, gpio_init_state: 'true', open_drain: Enable, slew_rate: Slow} + - {pin_num: H13, peripheral: GPIO1, signal: 'gpio_io, 24', pin_signal: GPIO_AD_B1_08, direction: OUTPUT, gpio_init_state: 'true'} + - {pin_num: M13, peripheral: GPIO1, signal: 'gpio_io, 25', pin_signal: GPIO_AD_B1_09, direction: OUTPUT, gpio_init_state: 'true'} + * BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS *********** + */ + +/* FUNCTION ************************************************************************************************************ + * + * Function Name : BOARD_InitCLEDPins + * Description : Configures pin routing and optionally pin electrical features. + * + * END ****************************************************************************************************************/ +void BOARD_InitCLEDPins(void) { + CLOCK_EnableClock(kCLOCK_Iomuxc); + + /* GPIO configuration of LED_B on GPIO_AD_B0_10 (pin G13) */ + gpio_pin_config_t LED_B_config = { + .direction = kGPIO_DigitalOutput, + .outputLogic = 1U, + .interruptMode = kGPIO_NoIntmode + }; + /* Initialize GPIO functionality on GPIO_AD_B0_10 (pin G13) */ + GPIO_PinInit(GPIO1, 10U, &LED_B_config); + + /* GPIO configuration of LED_R on GPIO_AD_B1_08 (pin H13) */ + gpio_pin_config_t LED_R_config = { + .direction = kGPIO_DigitalOutput, + .outputLogic = 1U, + .interruptMode = kGPIO_NoIntmode + }; + /* Initialize GPIO functionality on GPIO_AD_B1_08 (pin H13) */ + GPIO_PinInit(GPIO1, 24U, &LED_R_config); + + /* GPIO configuration of LED_G on GPIO_AD_B1_09 (pin M13) */ + gpio_pin_config_t LED_G_config = { + .direction = kGPIO_DigitalOutput, + .outputLogic = 1U, + .interruptMode = kGPIO_NoIntmode + }; + /* Initialize GPIO functionality on GPIO_AD_B1_09 (pin M13) */ + GPIO_PinInit(GPIO1, 25U, &LED_G_config); + + IOMUXC_SetPinMux(IOMUXC_GPIO_AD_B0_10_GPIO1_IO10, 0U); + IOMUXC_SetPinMux(IOMUXC_GPIO_AD_B1_08_GPIO1_IO24, 0U); + IOMUXC_SetPinMux(IOMUXC_GPIO_AD_B1_09_GPIO1_IO25, 0U); + IOMUXC_SetPinConfig(IOMUXC_GPIO_AD_B0_10_GPIO1_IO10, 0x98B0U); +} + /*********************************************************************************************************************** * EOF **********************************************************************************************************************/ diff --git a/board/pin_mux.h b/board/pin_mux.h index d87c119..8fbbcde 100644 --- a/board/pin_mux.h +++ b/board/pin_mux.h @@ -114,6 +114,25 @@ void BOARD_InitSEMCPins(void); */ void BOARD_InitLCDPins(void); +/* GPIO_AD_B1_09 (coord M13), LED_G */ +/* Routed pin properties */ +#define BOARD_INITCODECPINS_LED_G_PERIPHERAL SAI1 /*!< Peripheral name */ +#define BOARD_INITCODECPINS_LED_G_SIGNAL sai_mclk /*!< Signal name */ + +/* GPIO_AD_B1_08 (coord H13), LED_R */ +/* Routed pin properties */ +#define BOARD_INITCODECPINS_LED_R_PERIPHERAL GPIO1 /*!< Peripheral name */ +#define BOARD_INITCODECPINS_LED_R_SIGNAL gpio_io /*!< Signal name */ +#define BOARD_INITCODECPINS_LED_R_CHANNEL 24U /*!< Signal channel */ + +/* Symbols to be used with GPIO driver */ +#define BOARD_INITCODECPINS_LED_R_GPIO GPIO1 /*!< GPIO peripheral base pointer */ +#define BOARD_INITCODECPINS_LED_R_GPIO_PIN 24U /*!< GPIO pin number */ +#define BOARD_INITCODECPINS_LED_R_GPIO_PIN_MASK (1U << 24U) /*!< GPIO pin mask */ +#define BOARD_INITCODECPINS_LED_R_PORT GPIO1 /*!< PORT peripheral base pointer */ +#define BOARD_INITCODECPINS_LED_R_PIN 24U /*!< PORT pin number */ +#define BOARD_INITCODECPINS_LED_R_PIN_MASK (1U << 24U) /*!< PORT pin mask */ + /*! * @brief Configures pin routing and optionally pin electrical features. @@ -121,6 +140,18 @@ void BOARD_InitLCDPins(void); */ void BOARD_InitCodecPins(void); +/* GPIO_AD_B1_09 (coord M13), LED_G */ +/* Routed pin properties */ +#define BOARD_INITCSIPINS_LED_G_PERIPHERAL CSI /*!< Peripheral name */ +#define BOARD_INITCSIPINS_LED_G_SIGNAL csi_data /*!< Signal name */ +#define BOARD_INITCSIPINS_LED_G_CHANNEL 8U /*!< Signal channel */ + +/* GPIO_AD_B1_08 (coord H13), LED_R */ +/* Routed pin properties */ +#define BOARD_INITCSIPINS_LED_R_PERIPHERAL CSI /*!< Peripheral name */ +#define BOARD_INITCSIPINS_LED_R_SIGNAL csi_data /*!< Signal name */ +#define BOARD_INITCSIPINS_LED_R_CHANNEL 9U /*!< Signal channel */ + /* GPIO_AD_B0_00 (coord M14), CSI_ */ /* Routed pin properties */ #define BOARD_INITCSIPINS_CSI_PDN_PERIPHERAL GPIO1 /*!< Peripheral name */ @@ -232,6 +263,55 @@ void BOARD_InitCAN2Pins(void); */ void BOARD_InitSPDIFPins(void); +/* GPIO_AD_B0_10 (coord G13), LED_B */ +/* Routed pin properties */ +#define BOARD_INITCLEDPINS_LED_B_PERIPHERAL GPIO1 /*!< Peripheral name */ +#define BOARD_INITCLEDPINS_LED_B_SIGNAL gpio_io /*!< Signal name */ +#define BOARD_INITCLEDPINS_LED_B_CHANNEL 10U /*!< Signal channel */ + +/* Symbols to be used with GPIO driver */ +#define BOARD_INITCLEDPINS_LED_B_GPIO GPIO1 /*!< GPIO peripheral base pointer */ +#define BOARD_INITCLEDPINS_LED_B_GPIO_PIN 10U /*!< GPIO pin number */ +#define BOARD_INITCLEDPINS_LED_B_GPIO_PIN_MASK (1U << 10U) /*!< GPIO pin mask */ +#define BOARD_INITCLEDPINS_LED_B_PORT GPIO1 /*!< PORT peripheral base pointer */ +#define BOARD_INITCLEDPINS_LED_B_PIN 10U /*!< PORT pin number */ +#define BOARD_INITCLEDPINS_LED_B_PIN_MASK (1U << 10U) /*!< PORT pin mask */ + +/* GPIO_AD_B1_08 (coord H13), LED_R */ +/* Routed pin properties */ +#define BOARD_INITCLEDPINS_LED_R_PERIPHERAL GPIO1 /*!< Peripheral name */ +#define BOARD_INITCLEDPINS_LED_R_SIGNAL gpio_io /*!< Signal name */ +#define BOARD_INITCLEDPINS_LED_R_CHANNEL 24U /*!< Signal channel */ + +/* Symbols to be used with GPIO driver */ +#define BOARD_INITCLEDPINS_LED_R_GPIO GPIO1 /*!< GPIO peripheral base pointer */ +#define BOARD_INITCLEDPINS_LED_R_GPIO_PIN 24U /*!< GPIO pin number */ +#define BOARD_INITCLEDPINS_LED_R_GPIO_PIN_MASK (1U << 24U) /*!< GPIO pin mask */ +#define BOARD_INITCLEDPINS_LED_R_PORT GPIO1 /*!< PORT peripheral base pointer */ +#define BOARD_INITCLEDPINS_LED_R_PIN 24U /*!< PORT pin number */ +#define BOARD_INITCLEDPINS_LED_R_PIN_MASK (1U << 24U) /*!< PORT pin mask */ + +/* GPIO_AD_B1_09 (coord M13), LED_G */ +/* Routed pin properties */ +#define BOARD_INITCLEDPINS_LED_G_PERIPHERAL GPIO1 /*!< Peripheral name */ +#define BOARD_INITCLEDPINS_LED_G_SIGNAL gpio_io /*!< Signal name */ +#define BOARD_INITCLEDPINS_LED_G_CHANNEL 25U /*!< Signal channel */ + +/* Symbols to be used with GPIO driver */ +#define BOARD_INITCLEDPINS_LED_G_GPIO GPIO1 /*!< GPIO peripheral base pointer */ +#define BOARD_INITCLEDPINS_LED_G_GPIO_PIN 25U /*!< GPIO pin number */ +#define BOARD_INITCLEDPINS_LED_G_GPIO_PIN_MASK (1U << 25U) /*!< GPIO pin mask */ +#define BOARD_INITCLEDPINS_LED_G_PORT GPIO1 /*!< PORT peripheral base pointer */ +#define BOARD_INITCLEDPINS_LED_G_PIN 25U /*!< PORT pin number */ +#define BOARD_INITCLEDPINS_LED_G_PIN_MASK (1U << 25U) /*!< PORT pin mask */ + + +/*! + * @brief Configures pin routing and optionally pin electrical features. + * + */ +void BOARD_InitCLEDPins(void); + #if defined(__cplusplus) } #endif diff --git a/include/app_thr.h b/include/app_thr.h new file mode 100644 index 0000000..ca3b281 --- /dev/null +++ b/include/app_thr.h @@ -0,0 +1,6 @@ +#ifndef APP_THR_H +#define APP_THR_H + +void hello_task(ULONG thread_input); + +#endif // APP_THR_H diff --git a/include/tx_user.h b/include/tx_user.h new file mode 100644 index 0000000..1fc95ad --- /dev/null +++ b/include/tx_user.h @@ -0,0 +1,6 @@ +#ifndef TX_USER_H +#define TX_USER_H + +#define TX_TIMER_TICKS_PER_SECOND 1000 + +#endif // TX_USER_H diff --git a/lib/threadx b/lib/threadx new file mode 160000 index 0000000..2aa19f3 --- /dev/null +++ b/lib/threadx @@ -0,0 +1 @@ +Subproject commit 2aa19f3de0b6cf09bb9dca78c8a53fe337b8f0f7 diff --git a/src/app_entry.c b/src/app_entry.c new file mode 100644 index 0000000..7d3e221 --- /dev/null +++ b/src/app_entry.c @@ -0,0 +1,45 @@ +/* SDK drivers */ +#include "fsl_common.h" + +/* ThreadX */ +#include "tx_api.h" + +/* App */ +#include "app_thr.h" + +extern void *__HeapLimit; +extern void *_tx_initialize_unused_memory; + +void _tx_timer_interrupt(void); + +static TX_THREAD hello_task_handle; + +void tx_application_define(void *first_unused_memory) { + tx_thread_create(&hello_task_handle, "T_HE", hello_task, 0x00, first_unused_memory, 1024, 3, 3, TX_NO_TIME_SLICE, + TX_AUTO_START); +} + +void _tx_initialize_low_level(void) { + DisableGlobalIRQ(); + + _tx_initialize_unused_memory = (VOID *)&__HeapLimit; + + /* enable CPU cycle counter */ + DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk; + + SysTick_Config(SystemCoreClock / TX_TIMER_TICKS_PER_SECOND); + + NVIC_SetPriority(MemoryManagement_IRQn, 0); + NVIC_SetPriority(BusFault_IRQn, 0); + NVIC_SetPriority(UsageFault_IRQn, 0); + + NVIC_SetPriority(SVCall_IRQn, 0x0ff); + + NVIC_SetPriority(DebugMonitor_IRQn, 0); + NVIC_SetPriority(PendSV_IRQn, 0x0ff); + NVIC_SetPriority(SysTick_IRQn, 0x40); +} + +VOID SysTick_Handler(VOID) { + _tx_timer_interrupt(); +} diff --git a/src/app_thr_hello.c b/src/app_thr_hello.c new file mode 100644 index 0000000..d578676 --- /dev/null +++ b/src/app_thr_hello.c @@ -0,0 +1,21 @@ +/* Board */ +#include "pin_mux.h" + +/* SDK drivers */ +#include "fsl_common.h" +#include "fsl_gpio.h" + +/* ThreadX */ +#include "tx_api.h" + +/* App */ +#include "app_thr.h" + +void hello_task(ULONG thread_input) { + for (;;) { + GPIO_PinWrite(BOARD_INITCLEDPINS_LED_R_GPIO, BOARD_INITCLEDPINS_LED_R_GPIO_PIN, 1); + tx_thread_sleep(750); + GPIO_PinWrite(BOARD_INITCLEDPINS_LED_R_GPIO, BOARD_INITCLEDPINS_LED_R_GPIO_PIN, 0); + tx_thread_sleep(250); + } +} \ No newline at end of file diff --git a/src/main.c b/src/main.c index 4c63a63..301425d 100644 --- a/src/main.c +++ b/src/main.c @@ -3,6 +3,9 @@ #include "peripherals.h" #include "pin_mux.h" +/* ThreadX */ +#include "tx_api.h" + /* Debug console */ #include "fsl_debug_console.h" @@ -16,7 +19,7 @@ int main(void) { CLOCK_SetMode(kCLOCK_ModeRun); - PRINTF("CPU frequency: %d\r\n", CLOCK_GetCoreSysClkFreq()); + tx_kernel_enter(); for (;;) { __WFI();