diff --git a/boards/nxp/tropic/default.px4board b/boards/nxp/tropic/default.px4board index 4262ca34cb69..49b3d65a0d59 100644 --- a/boards/nxp/tropic/default.px4board +++ b/boards/nxp/tropic/default.px4board @@ -5,16 +5,22 @@ CONFIG_BOARD_SERIAL_GPS1="/dev/ttyS1" CONFIG_BOARD_SERIAL_TEL1="/dev/ttyS2" CONFIG_BOARD_SERIAL_TEL2="/dev/ttyS3" CONFIG_DRIVERS_ADC_BOARD_ADC=y -CONFIG_DRIVERS_BAROMETER_DPS310=y +CONFIG_DRIVERS_BAROMETER_BMP388=y +CONFIG_DRIVERS_BAROMETER_INVENSENSE_ICP201XX=y +CONFIG_DRIVERS_BAROMETER_MS5611=y CONFIG_DRIVERS_CAMERA_CAPTURE=y CONFIG_DRIVERS_CAMERA_TRIGGER=y -CONFIG_DRIVERS_DISTANCE_SENSOR_LIGHTWARE_LASER_I2C=y +CONFIG_DRIVERS_CDCACM_AUTOSTART=y +CONFIG_COMMON_DIFFERENTIAL_PRESSURE=y +CONFIG_COMMON_DISTANCE_SENSOR=y CONFIG_DRIVERS_DSHOT=y CONFIG_DRIVERS_GPS=y CONFIG_DRIVERS_IMU_BOSCH_BMI088=y CONFIG_DRIVERS_IMU_INVENSENSE_ICM20948=y CONFIG_DRIVERS_IMU_INVENSENSE_ICM42688P=y +CONFIG_COMMON_INS=y CONFIG_COMMON_LIGHT=y +CONFIG_DRIVERS_LIGHTS_RGBLED_PWM=y CONFIG_COMMON_MAGNETOMETER=y CONFIG_DRIVERS_OSD_MSP_OSD=y CONFIG_DRIVERS_POWER_MONITOR_INA226=y @@ -27,12 +33,15 @@ CONFIG_COMMON_TELEMETRY=y CONFIG_DRIVERS_TONE_ALARM=y CONFIG_DRIVERS_UAVCAN=y CONFIG_BOARD_UAVCAN_INTERFACES=1 +CONFIG_COMMON_UWB=y +CONFIG_MODULES_AIRSPEED_SELECTOR=y CONFIG_MODULES_BATTERY_STATUS=y CONFIG_MODULES_CAMERA_FEEDBACK=y CONFIG_MODULES_COMMANDER=y CONFIG_MODULES_CONTROL_ALLOCATOR=y CONFIG_MODULES_DATAMAN=y CONFIG_MODULES_EKF2=y +CONFIG_MODULES_ESC_BATTERY=y CONFIG_MODULES_EVENTS=y CONFIG_MODULES_FLIGHT_MODE_MANAGER=y CONFIG_MODULES_FW_ATT_CONTROL=y @@ -61,10 +70,13 @@ CONFIG_MODULES_RC_UPDATE=y CONFIG_MODULES_ROVER_POS_CONTROL=y CONFIG_MODULES_SENSORS=y CONFIG_MODULES_TEMPERATURE_COMPENSATION=y +CONFIG_MODULES_UXRCE_DDS_CLIENT=y +CONFIG_MODULES_VTOL_ATT_CONTROL=y CONFIG_SYSTEMCMDS_ACTUATOR_TEST=y CONFIG_SYSTEMCMDS_BSONDUMP=y CONFIG_SYSTEMCMDS_DMESG=y CONFIG_SYSTEMCMDS_DUMPFILE=y +CONFIG_SYSTEMCMDS_I2C_LAUNCHER=y CONFIG_SYSTEMCMDS_I2CDETECT=y CONFIG_SYSTEMCMDS_LED_CONTROL=y CONFIG_SYSTEMCMDS_MFT=y diff --git a/boards/nxp/tropic/init/rc.board_defaults b/boards/nxp/tropic/init/rc.board_defaults index c87952922cc3..8a49eca594a9 100644 --- a/boards/nxp/tropic/init/rc.board_defaults +++ b/boards/nxp/tropic/init/rc.board_defaults @@ -16,8 +16,8 @@ param set-default SENS_EN_INA238 0 param set-default SENS_EN_INA228 0 param set-default SENS_EN_INA226 0 -param set-default BAT1_V_DIV 10.177939394 -param set-default BAT1_A_PER_V 15.391030303 +param set-default BAT1_V_DIV 18.000000000 +param set-default BAT1_A_PER_V 38.462030303 if [ -f "/fs/microsd/ipcfg-eth0" ] then @@ -25,6 +25,7 @@ else netman update -i eth0 fi +rgbled_pwm start safety_button start if param greater -s UAVCAN_ENABLE 0 diff --git a/boards/nxp/tropic/init/rc.board_sensors b/boards/nxp/tropic/init/rc.board_sensors index 80e07ab1a928..88cf1adb4119 100644 --- a/boards/nxp/tropic/init/rc.board_sensors +++ b/boards/nxp/tropic/init/rc.board_sensors @@ -1,18 +1,20 @@ #!/bin/sh # -# NXP Tropic specific board sensors init +# PX4 board sensors init #------------------------------------------------------------------------------ # -# UART mapping on NXP Tropic +# UART mapping on Tropic: # -# LPUART5 /dev/ttyS0 DEBUG -# LPUART3 /dev/ttyS2 TELEM -# LPUART2 /dev/ttyS1 GPS -# LPUART4 /dev/ttyS3 AUX -# LPUART8 /dev/ttyS4 RC +# LPUART5 /dev/ttyS0 CONSOLE +# LPUART3 /dev/ttyS1 GPS +# LPUART2 /dev/ttyS2 TELEM1 +# LPUART4 /dev/ttyS3 TELEM2 +# LPUART8 /dev/ttyS4 RC # #------------------------------------------------------------------------------ +set INA_CONFIGURED no + if param compare -s ADC_ADS1115_EN 1 then ads1115 start -X @@ -25,18 +27,27 @@ if param compare SENS_EN_INA226 1 then # Start Digital power monitors ina226 -X -b 1 -t 1 -k start + set INA_CONFIGURED yes fi if param compare SENS_EN_INA228 1 then # Start Digital power monitors ina228 -X -b 1 -t 1 -k start + set INA_CONFIGURED yes fi if param compare SENS_EN_INA238 1 then # Start Digital power monitors ina238 -X -b 1 -t 1 -k start + set INA_CONFIGURED yes +fi + +if [ $INA_CONFIGURED = no ] +then + # INA226, INA228, INA238 auto-start + i2c_launcher start -b 1 fi # Internal SPI bus ICM42688p @@ -57,5 +68,7 @@ ist8310 -X -b 1 -R 10 start # Disable startup of internal baros if param is set to false if param compare SENS_INT_BARO_EN 1 then - dps310 -I -b 4 start + bmp388 -I -b 4 start fi + +unset INA_CONFIGURED diff --git a/boards/nxp/tropic/nuttx-config/nsh/defconfig b/boards/nxp/tropic/nuttx-config/nsh/defconfig index efc59a244619..802c6c57f3ec 100644 --- a/boards/nxp/tropic/nuttx-config/nsh/defconfig +++ b/boards/nxp/tropic/nuttx-config/nsh/defconfig @@ -27,6 +27,7 @@ CONFIG_ARMV7M_ITCM=y CONFIG_ARMV7M_MEMCPY=y CONFIG_ARMV7M_USEBASEPRI=y CONFIG_ARM_MPU=y +CONFIG_ARM_MPU_RESET=y CONFIG_BOARDCTL_RESET=y CONFIG_BOARD_ASSERT_RESET_VALUE=0 CONFIG_BOARD_LOOPSPERMSEC=114325 @@ -40,7 +41,10 @@ CONFIG_CDCACM_RXBUFSIZE=600 CONFIG_CDCACM_TXBUFSIZE=12000 CONFIG_CDCACM_VENDORID=0x1FC9 CONFIG_CDCACM_VENDORSTR="NXP SEMICONDUCTORS" +CONFIG_DEBUG_ERROR=y +CONFIG_DEBUG_FEATURES=y CONFIG_DEBUG_HARDFAULT_ALERT=y +CONFIG_DEBUG_MEMFAULT=y CONFIG_DEBUG_SYMBOLS=y CONFIG_DEBUG_TCBINFO=y CONFIG_DEV_FIFO_SIZE=0 @@ -131,7 +135,6 @@ CONFIG_LPUART5_SERIAL_CONSOLE=y CONFIG_MEMSET_64BIT=y CONFIG_MEMSET_OPTSPEED=y CONFIG_MMCSD=y -CONFIG_MMCSD_MULTIBLOCK_LIMIT=1 CONFIG_MMCSD_SDIO=y CONFIG_MTD=y CONFIG_MTD_BYTE_WRITE=y @@ -163,9 +166,7 @@ CONFIG_NET_CAN_SOCK_OPTS=y CONFIG_NET_ETH_PKTSIZE=1518 CONFIG_NET_ICMP=y CONFIG_NET_ICMP_SOCKET=y -CONFIG_NET_NACTIVESOCKETS=20 CONFIG_NET_SOLINGER=y -CONFIG_NET_STATISTICS=y CONFIG_NET_TCP=y CONFIG_NET_TCPBACKLOG=y CONFIG_NET_TCP_DELAYED_ACK=y @@ -204,7 +205,7 @@ CONFIG_SCHED_INSTRUMENTATION_EXTERNAL=y CONFIG_SCHED_INSTRUMENTATION_SWITCH=y CONFIG_SCHED_LPWORK=y CONFIG_SCHED_LPWORKPRIORITY=50 -CONFIG_SCHED_LPWORKSTACKSIZE=1632 +CONFIG_SCHED_LPWORKSTACKSIZE=2032 CONFIG_SCHED_WAITPID=y CONFIG_SDIO_BLOCKSETUP=y CONFIG_SEM_PREALLOCHOLDERS=32 @@ -225,6 +226,7 @@ CONFIG_SYSTEM_CLE=y CONFIG_SYSTEM_DHCPC_RENEW=y CONFIG_SYSTEM_NSH=y CONFIG_SYSTEM_PING=y +CONFIG_SYSTEM_SYSTEM=y CONFIG_TASK_NAME_SIZE=24 CONFIG_USBDEV=y CONFIG_USBDEV_BUSPOWERED=y diff --git a/boards/nxp/tropic/nuttx-config/scripts/itcm_functions_includes.ld b/boards/nxp/tropic/nuttx-config/scripts/itcm_functions_includes.ld index d5c804a72bd6..60a76f97e1b9 100644 --- a/boards/nxp/tropic/nuttx-config/scripts/itcm_functions_includes.ld +++ b/boards/nxp/tropic/nuttx-config/scripts/itcm_functions_includes.ld @@ -1,112 +1,3 @@ -/* Static */ -*(.text.arm_ack_irq) -*(.text.arm_doirq) -*(.text.arm_svcall) -*(.text.arm_switchcontext) -*(.text.board_autoled_on) -*(.text.clock_timer) -*(.text.exception_common) -*(.text.hrt_absolute_time) -*(.text.hrt_tim_isr) -*(.text.imxrt_configwaitints) -*(.text.imxrt_dma_callback) -*(.text.imxrt_dmach_interrupt) -*(.text.imxrt_dmaterminate) -*(.text.imxrt_edma_interrupt) -*(.text.imxrt_endwait) -*(.text.imxrt_gpio3_16_31_interrupt) -*(.text.imxrt_interrupt) -*(.text.imxrt_lpi2c_isr) -*(.text.imxrt_recvdma) -*(.text.imxrt_tcd_free) -*(.text.imxrt_timerisr) -*(.text.imxrt_usbinterrupt) -*(.text.irq_dispatch) -*(.text.memcpy) -*(.text.nxsched_add_blocked) -*(.text.nxsched_add_prioritized) -*(.text.nxsched_add_readytorun) -*(.text.nxsched_get_files) -*(.text.nxsched_get_tcb) -*(.text.nxsched_merge_pending) -*(.text.nxsched_process_timer) -*(.text.nxsched_remove_blocked) -*(.text.nxsched_remove_readytorun) -*(.text.nxsched_resume_scheduler) -*(.text.nxsched_suspend_scheduler) -*(.text.nxsem_add_holder) -*(.text.nxsem_add_holder_tcb) -*(.text.nxsem_clockwait) -*(.text.nxsem_foreachholder) -*(.text.nxsem_freecount0holder) -*(.text.nxsem_freeholder) -*(.text.nxsem_post) -*(.text.nxsem_release_holder) -*(.text.nxsem_restore_baseprio) -*(.text.nxsem_tickwait) -*(.text.nxsem_timeout) -*(.text.nxsem_trywait) -*(.text.nxsem_wait) -*(.text.nxsem_wait_uninterruptible) -*(.text.nxsig_timedwait) -*(.text.sched_lock) -*(.text.sched_note_resume) -*(.text.sched_note_suspend) -*(.text.sched_unlock) -*(.text.sq_addafter) -*(.text.sq_addlast) -*(.text.sq_rem) -*(.text.sq_remafter) -*(.text.sq_remfirst) -*(.text.uart_connected) -*(.text.wd_timer) -/* Tropic tune */ -*(.text.imxrt_enet_interrupt) -*(.text.imxrt_enet_interrupt_work) -*(.text.imxrt_txdone) -*(.text.imxrt_txtimeout_work) -*(.text.imxrt_txtimeout_expiry) -*(.text.imxrt_txavail_work) -*(.text.imxrt_txavail) -*(.text.devif_poll) -*(.text.devif_poll_tcp_connections) -*(.text.tcp_poll) -*(.text.devif_poll_udp_connections) -*(.text.udp_nextconn) -*(.text.udp_poll) -*(.text.udp_ipv4_select) -*(.text.udp_callback) -*(.text.udp_datahandler) -*(.text.udp_send) -*(.text.udp_active) -*(.text.udp_ipv4_active) -*(.text.psock_udp_sendto) -*(.text.sendto_eventhandler) -*(.text.net_dataevent) -*(.text.devif_conn_event) -*(.text.devif_event_trigger) -*(.text.devif_poll_icmp) -*(.text.icmp_poll) -*(.text.devif_packet_conversion) -*(.text.imxrt_txpoll) -*(.text.imxrt_txringfull) -*(.text.arp_out) -*(.text.arp_find) -*(.text.arp_format) -*(.text.net_ipv4addr_hdrcmp) -*(.text.net_ipv4addr_copy) -*(.text.net_ipv4addr_broadcast) -*(.text.imxrt_transmit) -*(.text.wd_start) -*(.text.imxrt_dispatch) -*(.text.arp_arpin) -*(.text.ipv4_input) -*(.text.flexio_irq_handler) - - -*(.text.work_thread) -*(.text.work_queue) - /* Auto-generated */ *(.text._ZN4uORB7Manager27orb_add_internal_subscriberE6ORB_IDhPj) *(.text._ZN13MavlinkStream6updateERKy) @@ -117,11 +8,9 @@ *(.text._ZN22MulticopterRateControl3RunEv.part.0) *(.text._ZN7Mavlink9task_mainEiPPc) *(.text._ZN7sensors22VehicleAngularVelocity3RunEv) -*(.text.memset) *(.text._ZN4uORB12Subscription9subscribeEv.part.0) *(.text._ZN4uORB7Manager13orb_data_copyEPvS1_Rjb) *(.text._ZN4uORB10DeviceNode5writeEP4filePKcj) -*(.text.strcmp) *(.text._ZN4uORB10DeviceNode7publishEPK12orb_metadataPvPKv) *(.text._ZN4uORB12DeviceMaster19getDeviceNodeLockedEPK12orb_metadatah) *(.text._Z12get_orb_meta6ORB_ID) @@ -129,15 +18,12 @@ *(.text._ZN3px49WorkQueue3RunEv) *(.text._ZN9ICM42688P11ProcessGyroERKyPKN20InvenSense_ICM42688P4FIFO4DATAEh) *(.text._ZN4EKF23RunEv) -*(.text.imxrt_lpspi_exchange) -*(.text.imxrt_dmach_xfrsetup) *(.text._ZN7sensors10VehicleIMU7PublishEv) *(.text._ZN4math17WelfordMeanVectorIfLj3EE6updateERKN6matrix6VectorIfLj3EEE) *(.text._ZN7sensors10VehicleIMU10UpdateGyroEv) *(.text._ZN9ICM42688P8FIFOReadERKyh) *(.text._ZN3Ekf20controlGravityFusionERKN9estimator9imuSampleE) *(.text._ZN16PX4Accelerometer10updateFIFOER19sensor_accel_fifo_s) -*(.text.up_block_task) *(.text._ZN7sensors22VehicleAngularVelocity19CalibrateAndPublishERKyRKN6matrix7Vector3IfEES7_) *(.text._ZN4uORB12Subscription10advertisedEv) *(.text._ZNK15AttitudeControl6updateERKN6matrix10QuaternionIfEE) @@ -146,7 +32,6 @@ *(.text._ZN4uORB12Subscription6updateEPv) *(.text._ZN12PX4Gyroscope10updateFIFOER18sensor_gyro_fifo_s) *(.text._ZN7sensors10VehicleIMU3RunEv) -*(.text.up_unblock_task) *(.text.__aeabi_l2f) *(.text._ZN39ControlAllocationSequentialDesaturation23computeDesaturationGainERKN6matrix6VectorIfLj16EEES4_) *(.text.pthread_mutex_timedlock) @@ -168,16 +53,12 @@ *(.text._ZN9ICM42688P7RunImplEv) *(.text._ZN4uORB12Subscription9subscribeEv) *(.text.param_get) -*(.text._do_memcpy) *(.text._ZN7sensors22VehicleAngularVelocity21SensorSelectionUpdateERKyb) *(.text._ZN3px49WorkQueue3AddEPNS_8WorkItemE) -*(.text.wd_start) -*(.text.hrt_call_enter) *(.text._ZN4EKF220PublishLocalPositionERKy) *(.text._mav_finalize_message_chan_send) *(.text._ZN3Ekf19fixCovarianceErrorsEb) *(.text._ZN7sensors22VehicleAngularVelocity16ParametersUpdateEb) -*(.text.ioctl) *(.text._ZN6events12SendProtocol6updateERKy) *(.text._ZN6device3SPI8transferEPhS1_j) *(.text._ZN27MavlinkStreamDistanceSensor4sendEv) diff --git a/boards/nxp/tropic/nuttx-config/scripts/itcm_static_functions.ld b/boards/nxp/tropic/nuttx-config/scripts/itcm_static_functions.ld new file mode 100644 index 000000000000..8b228a22f8b7 --- /dev/null +++ b/boards/nxp/tropic/nuttx-config/scripts/itcm_static_functions.ld @@ -0,0 +1,119 @@ +/* Static */ +*(.text.arm_ack_irq) +*(.text.arm_doirq) +*(.text.arm_svcall) +*(.text.arm_switchcontext) +*(.text.board_autoled_on) +*(.text.clock_timer) +*(.text.exception_common) +*(.text.flexio_irq_handler) +*(.text.hrt_absolute_time) +*(.text.hrt_call_enter) +*(.text.hrt_tim_isr) +*(.text.imxrt_configwaitints) +*(.text.imxrt_dma_callback) +*(.text.imxrt_dmach_interrupt) +*(.text.imxrt_dmach_xfrsetup) +*(.text.imxrt_dmaterminate) +*(.text.imxrt_dispatch) +*(.text.imxrt_edma_interrupt) +*(.text.imxrt_endwait) +*(.text.imxrt_enet_interrupt) +*(.text.imxrt_enet_interrupt_work) +*(.text.imxrt_gpio3_16_31_interrupt) +*(.text.imxrt_interrupt) +*(.text.imxrt_lpi2c_isr) +*(.text.imxrt_lpspi_exchange) +*(.text.imxrt_recvdma) +*(.text.imxrt_tcd_free) +*(.text.imxrt_timerisr) +*(.text.imxrt_transmit) +*(.text.imxrt_txdone) +*(.text.imxrt_txtimeout_work) +*(.text.imxrt_txtimeout_expiry) +*(.text.imxrt_txpoll) +*(.text.imxrt_txringfull) +*(.text.imxrt_txavail_work) +*(.text.imxrt_txavail) +*(.text.imxrt_usbinterrupt) +*(.text.irq_dispatch) +*(.text.ioctl) +*(.text.memcpy) +*(.text.memset) +*(.text.nxsched_add_blocked) +*(.text.nxsched_add_prioritized) +*(.text.nxsched_add_readytorun) +*(.text.nxsched_get_files) +*(.text.nxsched_get_tcb) +*(.text.nxsched_merge_pending) +*(.text.nxsched_process_timer) +*(.text.nxsched_remove_blocked) +*(.text.nxsched_remove_readytorun) +*(.text.nxsched_resume_scheduler) +*(.text.nxsched_suspend_scheduler) +*(.text.nxsem_add_holder) +*(.text.nxsem_add_holder_tcb) +*(.text.nxsem_clockwait) +*(.text.nxsem_foreachholder) +*(.text.nxsem_freecount0holder) +*(.text.nxsem_freeholder) +*(.text.nxsem_post) +*(.text.nxsem_release_holder) +*(.text.nxsem_restore_baseprio) +*(.text.nxsem_tickwait) +*(.text.nxsem_timeout) +*(.text.nxsem_trywait) +*(.text.nxsem_wait) +*(.text.nxsem_wait_uninterruptible) +*(.text.nxsig_timedwait) +*(.text.sched_lock) +*(.text.sched_note_resume) +*(.text.sched_note_suspend) +*(.text.sched_unlock) +*(.text.strcmp) +*(.text.sq_addafter) +*(.text.sq_addlast) +*(.text.sq_rem) +*(.text.sq_remafter) +*(.text.sq_remfirst) +*(.text.uart_connected) +*(.text.up_block_task) +*(.text.up_unblock_task) +*(.text.wd_timer) +*(.text.wd_start) +*(.text.work_thread) +*(.text.work_queue) +*(.text._do_memcpy) + +/* Tropic Eth tune */ +*(.text.devif_poll) +*(.text.devif_poll_tcp_connections) +*(.text.tcp_poll) +*(.text.devif_poll_udp_connections) +*(.text.udp_nextconn) +*(.text.udp_poll) +*(.text.udp_ipv4_select) +*(.text.udp_callback) +*(.text.udp_datahandler) +*(.text.udp_send) +*(.text.udp_active) +*(.text.udp_ipv4_active) +*(.text.psock_udp_sendto) +*(.text.sendto_eventhandler) +*(.text.net_dataevent) +*(.text.devif_conn_event) +*(.text.devif_event_trigger) +*(.text.devif_poll_icmp) +*(.text.icmp_poll) +*(.text.devif_packet_conversion) +*(.text.arp_out) +*(.text.arp_find) +*(.text.arp_format) +*(.text.net_ipv4addr_hdrcmp) +*(.text.net_ipv4addr_copy) +*(.text.net_ipv4addr_broadcast) +*(.text.wd_start) +*(.text.arp_arpin) +*(.text.ipv4_input) +*(.text.work_thread) +*(.text.work_queue) diff --git a/boards/nxp/tropic/nuttx-config/scripts/script.ld b/boards/nxp/tropic/nuttx-config/scripts/script.ld index e616444a5a20..a715059912ce 100644 --- a/boards/nxp/tropic/nuttx-config/scripts/script.ld +++ b/boards/nxp/tropic/nuttx-config/scripts/script.ld @@ -67,6 +67,7 @@ SECTIONS _sitcmfuncs = ABSOLUTE(.); FILL(0xFF) . = 0x40 ; + INCLUDE "itcm_static_functions.ld" INCLUDE "itcm_functions_includes.ld" . = ALIGN(8); _eitcmfuncs = ABSOLUTE(.); diff --git a/boards/nxp/tropic/src/CMakeLists.txt b/boards/nxp/tropic/src/CMakeLists.txt index 57c5337f9efd..0b238890d027 100644 --- a/boards/nxp/tropic/src/CMakeLists.txt +++ b/boards/nxp/tropic/src/CMakeLists.txt @@ -32,18 +32,19 @@ ############################################################################ px4_add_library(drivers_board - autoleds.c i2c.cpp init.c led.c sdhc.c spi.cpp timer_config.cpp + tropic_led_pwm.cpp usb.c imxrt_flexspi_nor_boot.c imxrt_flexspi_nor_flash.c ) + target_link_libraries(drivers_board PRIVATE drivers__led # drv_led_start diff --git a/boards/nxp/tropic/src/autoleds.c b/boards/nxp/tropic/src/autoleds.c deleted file mode 100644 index 8106e9f7a86b..000000000000 --- a/boards/nxp/tropic/src/autoleds.c +++ /dev/null @@ -1,191 +0,0 @@ -/**************************************************************************** - * - * Copyright (C) 2016-2018 Gregory Nutt. All rights reserved. - * Authors: Gregory Nutt - * David Sidrane - * - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX 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 OWNER 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. - * - ****************************************************************************/ -/* - * This module shall be used during board bring up of Nuttx. - * - * The NXP FMUK66-V3 has a separate Red, Green and Blue LEDs driven by the K66 - * as follows: - * - * LED K66 - * ------ ------------------------------------------------------- - * RED FB_CS0_b/ UART2_CTS_b / ADC0_SE5b / SPI0_SCK / FTM3_CH1/ PTD1 - * GREEN FTM2_FLT0/ CMP0_IN3/ FB_AD6 / I2S0_RX_BCLK/ FTM3_CH5/ ADC1_SE5b/ PTC9 - * BLUE CMP0_IN2/ FB_AD7 / I2S0_MCLK/ FTM3_CH4/ ADC1_SE4b/ PTC8 - * - * If CONFIG_ARCH_LEDs is defined, then NuttX will control the LED on board - * the NXP fmurt1062-v1. The following definitions describe how NuttX controls - * the LEDs: - * - * SYMBOL Meaning LED state - * RED GREEN BLUE - * ------------------- ----------------------- ----------------- - * LED_STARTED NuttX has been started OFF OFF OFF - * LED_HEAPALLOCATE Heap has been allocated OFF OFF ON - * LED_IRQSENABLED Interrupts enabled OFF OFF ON - * LED_STACKCREATED Idle stack created OFF ON OFF - * LED_INIRQ In an interrupt (no change) - * LED_SIGNAL In a signal handler (no change) - * LED_ASSERTION An assertion failed (no change) - * LED_PANIC The system has crashed FLASH OFF OFF - * LED_IDLE K66 is in sleep mode (Optional, not used) - */ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include - -#include -#include - -#include "chip.h" -#include "imxrt_gpio.h" -#include "board_config.h" -#ifdef CONFIG_ARCH_LEDS -__BEGIN_DECLS -extern void led_init(void); -__END_DECLS - -/**************************************************************************** - * Public Functions - ****************************************************************************/ -bool nuttx_owns_leds = true; -/**************************************************************************** - * Name: board_autoled_initialize - ****************************************************************************/ - -void board_autoled_initialize(void) -{ - led_init(); -} - -/**************************************************************************** - * Name: board_autoled_on - ****************************************************************************/ -void phy_set_led(int l, bool s) -{ - -} -void board_autoled_on(int led) -{ - if (!nuttx_owns_leds) { - return; - } - - switch (led) { - default: - break; - - case LED_HEAPALLOCATE: - phy_set_led(BOARD_LED_BLUE, true); - break; - - case LED_IRQSENABLED: - phy_set_led(BOARD_LED_BLUE, false); - phy_set_led(BOARD_LED_GREEN, true); - break; - - case LED_STACKCREATED: - phy_set_led(BOARD_LED_GREEN, true); - phy_set_led(BOARD_LED_BLUE, true); - break; - - case LED_INIRQ: - phy_set_led(BOARD_LED_BLUE, true); - break; - - case LED_SIGNAL: - phy_set_led(BOARD_LED_GREEN, true); - break; - - case LED_ASSERTION: - phy_set_led(BOARD_LED_RED, true); - phy_set_led(BOARD_LED_BLUE, true); - break; - - case LED_PANIC: - phy_set_led(BOARD_LED_RED, true); - break; - - case LED_IDLE : /* IDLE */ - phy_set_led(BOARD_LED_RED, true); - break; - } -} - -/**************************************************************************** - * Name: board_autoled_off - ****************************************************************************/ - -void board_autoled_off(int led) -{ - if (!nuttx_owns_leds) { - return; - } - - switch (led) { - default: - break; - - case LED_SIGNAL: - phy_set_led(BOARD_LED_GREEN, false); - break; - - case LED_INIRQ: - phy_set_led(BOARD_LED_BLUE, false); - break; - - case LED_ASSERTION: - phy_set_led(BOARD_LED_RED, false); - phy_set_led(BOARD_LED_BLUE, false); - break; - - case LED_PANIC: - phy_set_led(BOARD_LED_RED, false); - break; - - case LED_IDLE : /* IDLE */ - phy_set_led(BOARD_LED_RED, false); - break; - } -} - -#endif /* CONFIG_ARCH_LEDS */ diff --git a/boards/nxp/tropic/src/board_config.h b/boards/nxp/tropic/src/board_config.h index 62f87e945f66..a374539c5a31 100644 --- a/boards/nxp/tropic/src/board_config.h +++ b/boards/nxp/tropic/src/board_config.h @@ -44,6 +44,7 @@ ****************************************************************************************************/ #include +#include #include #include @@ -66,9 +67,9 @@ /* An RGB LED is connected through GPIO as shown below: */ #define LED_IOMUX (IOMUX_OPENDRAIN | IOMUX_PULL_NONE | IOMUX_DRIVE_33OHM | IOMUX_SPEED_MEDIUM | IOMUX_SLEW_SLOW) -#define GPIO_nLED_RED /* GPIO_AD_B0_02 GPIO1_IO02 */ (GPIO_PORT1 | GPIO_PIN2 | GPIO_OUTPUT | GPIO_OUTPUT_ZERO | LED_IOMUX) -#define GPIO_nLED_GREEN /* GPIO_B1_03 GPIO2_IO19 */ (GPIO_PORT2 | GPIO_PIN19 | GPIO_OUTPUT | GPIO_OUTPUT_ZERO | LED_IOMUX) -#define GPIO_nLED_BLUE /* GPIO_AD_B0_03 GPIO1_IO03 */ (GPIO_PORT1 | GPIO_PIN3 | GPIO_OUTPUT | GPIO_OUTPUT_ZERO | LED_IOMUX) +#define GPIO_nLED_RED /* GPIO_AD_B0_02 GPIO1_IO02 */ (GPIO_PORT1 | GPIO_PIN2 | GPIO_OUTPUT | GPIO_OUTPUT_ONE | LED_IOMUX) +#define GPIO_nLED_GREEN /* GPIO_B1_03 GPIO2_IO19 */ (GPIO_PORT2 | GPIO_PIN19 | GPIO_OUTPUT | GPIO_OUTPUT_ONE | LED_IOMUX) +#define GPIO_nLED_BLUE /* GPIO_AD_B0_03 GPIO1_IO03 */ (GPIO_PORT1 | GPIO_PIN3 | GPIO_OUTPUT | GPIO_OUTPUT_ONE | LED_IOMUX) #define BOARD_HAS_CONTROL_STATUS_LEDS 1 #define BOARD_OVERLOAD_LED LED_RED @@ -136,6 +137,12 @@ //#define BOARD_ADC_OPEN_CIRCUIT_V (5.6f) +/* Power supply control and monitoring GPIOs */ + +#define GENERAL_INPUT_IOMUX (IOMUX_CMOS_INPUT | IOMUX_PULL_UP_47K | IOMUX_DRIVE_HIZ) +#define GENERAL_OUTPUT_IOMUX (IOMUX_CMOS_OUTPUT | IOMUX_PULL_KEEP | IOMUX_DRIVE_33OHM | IOMUX_SPEED_MEDIUM | IOMUX_SLEW_FAST) + + /* PWM */ @@ -149,25 +156,20 @@ //#define BOARD_HAS_UI_LED_PWM 1 Not ported yet (Still Kinetis driver) #define BOARD_HAS_LED_PWM 1 #define BOARD_LED_PWM_DRIVE_ACTIVE_LOW 1 +#define BOARD_HAS_CUSTOM_LED_PWM 1 -/* UI LEDs are driven by timer 4 the pins have no alternates - * - * nUI_LED_RED GPIO_B0_10 GPIO2_IO10 QTIMER4_TIMER1 - * nUI_LED_GREEN GPIO_B0_11 GPIO2_IO11 QTIMER4_TIMER2 - * nUI_LED_BLUE GPIO_B1_11 GPIO2_IO27 QTIMER4_TIMER3 - */ - +#define PWM_LED_RED /* GPIO_AD_B0_02 */ (GPIO_XBAR1_INOUT16_1 | GENERAL_OUTPUT_IOMUX) +#define PWM_LED_GREEN /* GPIO_B1_03 */ (GPIO_FLEXPWM2_PWMB03_4 | GENERAL_OUTPUT_IOMUX) +#define PWM_LED_BLUE /* GPIO_AD_B0_03 */ (GPIO_XBAR1_INOUT17_1 | GENERAL_OUTPUT_IOMUX) -/* Power supply control and monitoring GPIOs */ -#define GENERAL_INPUT_IOMUX (IOMUX_CMOS_INPUT | IOMUX_PULL_UP_47K | IOMUX_DRIVE_HIZ) -#define GENERAL_OUTPUT_IOMUX (IOMUX_CMOS_OUTPUT | IOMUX_PULL_KEEP | IOMUX_DRIVE_33OHM | IOMUX_SPEED_MEDIUM | IOMUX_SLEW_FAST) /* Tone alarm output */ //FIXME FlexPWM TONE DRIVER -//#define TONE_ALARM_TIMER 2 /* GPT 2 */ -//#define TONE_ALARM_CHANNEL 3 /* GPIO_AD_B1_07 GPT2_COMPARE3 */ +#define TONE_ALARM_FLEXPWM PWMA_VAL +#define TONE_ALARM_TIMER 3 /* FlexPWM 3 */ +#define TONE_ALARM_CHANNEL 1 /* GPIO_EMC_31 PWM3_PWMA01 */ #define GPIO_BUZZER_1 /* GPIO_EMC_31 GPIO4_IO31 */ (GPIO_PORT1 | GPIO_PIN23 | GPIO_OUTPUT | GPIO_OUTPUT_ZERO | GENERAL_OUTPUT_IOMUX) diff --git a/boards/nxp/tropic/src/imxrt_flexspi_nor_flash.c b/boards/nxp/tropic/src/imxrt_flexspi_nor_flash.c index 1e17bf2f633a..f7ffe4e46db7 100644 --- a/boards/nxp/tropic/src/imxrt_flexspi_nor_flash.c +++ b/boards/nxp/tropic/src/imxrt_flexspi_nor_flash.c @@ -35,84 +35,48 @@ const struct flexspi_nor_config_s g_flash_config = { .tag = FLEXSPI_CFG_BLK_TAG, .version = FLEXSPI_CFG_BLK_VERSION, .read_sample_clksrc = FLASH_READ_SAMPLE_CLK_LOOPBACK_FROM_SCKPAD, - .cs_hold_time = 3u, - .cs_setup_time = 3u, + .cs_hold_time = 1u, + .cs_setup_time = 1u, .column_address_width = 0u, .device_type = FLEXSPI_DEVICE_TYPE_SERIAL_NOR, .sflash_pad_type = SERIAL_FLASH_4PADS, .serial_clk_freq = FLEXSPI_SERIAL_CLKFREQ_133MHz, - .sflash_a1size = 2u * 1024u * 1024u, + .sflash_a1size = 8u * 1024u * 1024u, .data_valid_time = { 0u, 0u }, .lookup_table = { - /* LUTs */ - - FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0xeb, - RADDR_SDR, FLEXSPI_4PAD, 0x18), - FLEXSPI_LUT_SEQ(DUMMY_SDR, FLEXSPI_4PAD, 0x06, - READ_SDR, FLEXSPI_4PAD, 0x04), - 0x00000000, - 0x00000000, - - FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x05, - READ_SDR, FLEXSPI_1PAD, 0x04), - 0x00000000, - 0x00000000, - 0x00000000, - - 0x00000000, - 0x00000000, - 0x00000000, - 0x00000000, - - FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x01, STOP, FLEXSPI_1PAD, 0x0), - 0x00000000, - 0x00000000, - 0x00000000, - - 0x00000000, - 0x00000000, - 0x00000000, - 0x00000000, - - FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x20, - RADDR_SDR, FLEXSPI_1PAD, 0x18), - 0x00000000, - 0x00000000, - 0x00000000, - - 0x00000000, - 0x00000000, - 0x00000000, - 0x00000000, - - 0x00000000, - 0x00000000, - 0x00000000, - 0x00000000, - - FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0xd8, - RADDR_SDR, FLEXSPI_1PAD, 0x18), - 0x00000000, - 0x00000000, - 0x00000000, - - FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x02, - RADDR_SDR, FLEXSPI_1PAD, 0x18), - FLEXSPI_LUT_SEQ(WRITE_SDR, FLEXSPI_1PAD, 0x04, - STOP, FLEXSPI_1PAD, 0x0), - 0x00000000, - 0x00000000, - - 0x00000000, - 0x00000000, - 0x00000000, - 0x00000000, - - FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x60, STOP, FLEXSPI_1PAD, 0x0), + /* Fast Read Quad I/O */ + [0 + 0] = FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0xeb, + RADDR_SDR, FLEXSPI_4PAD, 0x18), + [0 + 1] = FLEXSPI_LUT_SEQ(DUMMY_SDR, FLEXSPI_4PAD, 0x06, + READ_SDR, FLEXSPI_4PAD, 0x04), + + /* Read Status Register-1 */ + [4 * 1 + 0] = FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x05, + READ_SDR, FLEXSPI_1PAD, 0x04), + + /* Write Status Register-1 */ + [4 * 3 + 0] = FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x01, STOP, FLEXSPI_1PAD, 0x0), + + /* Sector Erase (4KB) */ + [4 * 5 + 0] = FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x20, + RADDR_SDR, FLEXSPI_1PAD, 0x18), + + /* Block Erase (64KB) */ + [4 * 8 + 0] = FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0xd8, + RADDR_SDR, FLEXSPI_1PAD, 0x18), + + /* Page Program */ + [4 * 9 + 0] = FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x02, + RADDR_SDR, FLEXSPI_1PAD, 0x18), + [4 * 9 + 1] = FLEXSPI_LUT_SEQ(WRITE_SDR, FLEXSPI_1PAD, 0x04, + STOP, FLEXSPI_1PAD, 0x0), + + /* Chip Erase */ + [4 * 11 + 0] = FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x60, STOP, FLEXSPI_1PAD, 0x0), }, }, diff --git a/boards/nxp/tropic/src/imxrt_flexspi_nor_flash.h b/boards/nxp/tropic/src/imxrt_flexspi_nor_flash.h index 999f3ae323ab..11904fae65d0 100644 --- a/boards/nxp/tropic/src/imxrt_flexspi_nor_flash.h +++ b/boards/nxp/tropic/src/imxrt_flexspi_nor_flash.h @@ -194,9 +194,9 @@ enum flexspi_serial_clkfreq_e { FLEXSPI_SERIAL_CLKFREQ_75MHz = 4, FLEXSPI_SERIAL_CLKFREQ_80MHz = 5, FLEXSPI_SERIAL_CLKFREQ_100MHz = 6, - FLEXSPI_SERIAL_CLKFREQ_133MHz = 7, - FLEXSPI_SERIAL_CLKFREQ_166MHz = 8, - FLEXSPI_SERIAL_CLKFREQ_200MHz = 9, + FLEXSPI_SERIAL_CLKFREQ_120MHz = 7, + FLEXSPI_SERIAL_CLKFREQ_133MHz = 8, + FLEXSPI_SERIAL_CLKFREQ_166MHz = 9, }; /* FlexSPI clock configuration type */ diff --git a/boards/nxp/tropic/src/init.c b/boards/nxp/tropic/src/init.c index a552e226942f..9d6c106a03bd 100644 --- a/boards/nxp/tropic/src/init.c +++ b/boards/nxp/tropic/src/init.c @@ -324,18 +324,19 @@ int imxrt_phy_boardinitialize(int intf) return OK; } -void imxrt_flexio_clocking(void) { - uint32_t reg; - reg = getreg32(IMXRT_CCM_CDCDR); - reg &= ~(CCM_CDCDR_FLEXIO1_CLK_SEL_MASK | - CCM_CDCDR_FLEXIO1_CLK_PODF_MASK | - CCM_CDCDR_FLEXIO1_CLK_PRED_MASK); - reg |= CCM_CDCDR_FLEXIO1_CLK_SEL(CONFIG_FLEXIO1_CLK); - reg |= CCM_CDCDR_FLEXIO1_CLK_PODF - (CCM_PODF_FROM_DIVISOR(CONFIG_FLEXIO1_PODF_DIVIDER)); - reg |= CCM_CDCDR_FLEXIO1_CLK_PRED - (CCM_PRED_FROM_DIVISOR(CONFIG_FLEXIO1_PRED_DIVIDER)); - putreg32(reg, IMXRT_CCM_CDCDR); +void imxrt_flexio_clocking(void) +{ + uint32_t reg; + reg = getreg32(IMXRT_CCM_CDCDR); + reg &= ~(CCM_CDCDR_FLEXIO1_CLK_SEL_MASK | + CCM_CDCDR_FLEXIO1_CLK_PODF_MASK | + CCM_CDCDR_FLEXIO1_CLK_PRED_MASK); + reg |= CCM_CDCDR_FLEXIO1_CLK_SEL(CONFIG_FLEXIO1_CLK); + reg |= CCM_CDCDR_FLEXIO1_CLK_PODF + (CCM_PODF_FROM_DIVISOR(CONFIG_FLEXIO1_PODF_DIVIDER)); + reg |= CCM_CDCDR_FLEXIO1_CLK_PRED + (CCM_PRED_FROM_DIVISOR(CONFIG_FLEXIO1_PRED_DIVIDER)); + putreg32(reg, IMXRT_CCM_CDCDR); } diff --git a/boards/nxp/tropic/src/tropic_led_pwm.cpp b/boards/nxp/tropic/src/tropic_led_pwm.cpp new file mode 100644 index 000000000000..22ef3a357541 --- /dev/null +++ b/boards/nxp/tropic/src/tropic_led_pwm.cpp @@ -0,0 +1,218 @@ +/**************************************************************************** + * + * Copyright (c) 2024 PX4 Development Team. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name Airmind 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 OWNER 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. + * + ****************************************************************************/ + +/** +* @file tropic_led_pwm.cpp +*/ + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +#include +#include "imxrt_xbar.h" +#include "imxrt_periphclks.h" +#include "hardware/imxrt_tmr.h" +#include "hardware/imxrt_flexpwm.h" + +#define LED_PWM_FREQ 1000 +#define FLEXPWM_FREQ 1000000 +#define QTMR_FREQ (144000000/128) + +#define SM_SPACING (IMXRT_FLEXPWM_SM1CNT_OFFSET-IMXRT_FLEXPWM_SM0CNT_OFFSET) + +#define FLEXPWM_TIMER_BASE IMXRT_FLEXPWM2_BASE + +/* Register accessors */ +#define _REG(_addr) (*(volatile uint16_t *)(_addr)) +#define _REG16(_base, _reg) (*(volatile uint16_t *)(_base + _reg)) +#define FLEXPWMREG(_tmr, _sm, _reg) _REG16(FLEXPWM_TIMER_BASE + ((_sm) * SM_SPACING), (_reg)) +#define QTMRREG(_reg, _chn) _REG16(IMXRT_QTIMER4_BASE + ((_chn) * IMXRT_TMR_CHANNEL_SPACING),(_reg)) + +/* FlexPWM Registers for LED_G */ +#define rINIT(_tim, _sm) FLEXPWMREG(_tim, _sm,IMXRT_FLEXPWM_SM0INIT_OFFSET) /* Initial Count Register */ +#define rCTRL(_tim, _sm) FLEXPWMREG(_tim, _sm,IMXRT_FLEXPWM_SM0CTRL_OFFSET) /* Control Register */ +#define rCTRL2(_tim, _sm) FLEXPWMREG(_tim, _sm,IMXRT_FLEXPWM_SM0CTRL2_OFFSET) /* Control 2 Register */ +#define rFSTS0(_tim) FLEXPWMREG(_tim, 0, IMXRT_FLEXPWM_FSTS0_OFFSET) /* Fault Status Register */ +#define rVAL0(_tim, _sm) FLEXPWMREG(_tim, _sm,IMXRT_FLEXPWM_SM0VAL0_OFFSET) /* Value Register 0 */ +#define rVAL1(_tim, _sm) FLEXPWMREG(_tim, _sm,IMXRT_FLEXPWM_SM0VAL1_OFFSET) /* Value Register 1 */ +#define rVAL2(_tim, _sm) FLEXPWMREG(_tim, _sm,IMXRT_FLEXPWM_SM0VAL2_OFFSET) /* Value Register 2 */ +#define rVAL3(_tim, _sm) FLEXPWMREG(_tim, _sm,IMXRT_FLEXPWM_SM0VAL3_OFFSET) /* Value Register 3 */ +#define rVAL4(_tim, _sm) FLEXPWMREG(_tim, _sm,IMXRT_FLEXPWM_SM0VAL4_OFFSET) /* Value Register 4 */ +#define rVAL5(_tim, _sm) FLEXPWMREG(_tim, _sm,IMXRT_FLEXPWM_SM0VAL5_OFFSET) /* Value Register 5 */ +#define rFFILT0(_tim) FLEXPWMREG(_tim, 0, IMXRT_FLEXPWM_FFILT0_OFFSET) /* Fault Filter Register */ +#define rDISMAP0(_tim, _sm) FLEXPWMREG(_tim, _sm,IMXRT_FLEXPWM_SM0DISMAP0_OFFSET) /* Fault Disable Mapping Register 0 */ +#define rDISMAP1(_tim, _sm) FLEXPWMREG(_tim, _sm,IMXRT_FLEXPWM_SM0DISMAP1_OFFSET) /* Fault Disable Mapping Register 1 */ +#define rOUTEN(_tim) FLEXPWMREG(_tim, 0, IMXRT_FLEXPWM_OUTEN_OFFSET) /* Output Enable Register */ +#define rDTSRCSEL(_tim) FLEXPWMREG(_tim, 0, IMXRT_FLEXPWM_DTSRCSEL_OFFSET) /* PWM Source Select Register */ +#define rMCTRL(_tim) FLEXPWMREG(_tim, 0, IMXRT_FLEXPWM_MCTRL_OFFSET) /* Master Control Register */ + +#define QTMR_rCOMP1(_chn) QTMRREG(IMXRT_TMR_COMP1_OFFSET, _chn) +#define QTMR_rCOMP2(_chn) QTMRREG(IMXRT_TMR_COMP2_OFFSET, _chn) +#define QTMR_rCAPT(_chn) QTMRREG(IMXRT_TMR_CAPT_OFFSET, _chn) +#define QTMR_rLOAD(_chn) QTMRREG(IMXRT_TMR_LOAD_OFFSET, _chn) +#define QTMR_rHOLD(_chn) QTMRREG(IMXRT_TMR_HOLD_OFFSET, _chn) +#define QTMR_rCNTR(_chn) QTMRREG(IMXRT_TMR_CNTR_OFFSET, _chn) +#define QTMR_rCTRL(_chn) QTMRREG(IMXRT_TMR_CTRL_OFFSET, _chn) +#define QTMR_rSCTRL(_chn) QTMRREG(IMXRT_TMR_SCTRL_OFFSET, _chn) +#define QTMR_rCMPLD1(_chn) QTMRREG(IMXRT_TMR_CMPLD1_OFFSET, _chn) +#define QTMR_rCMPLD2(_chn) QTMRREG(IMXRT_TMR_CMPLD2_OFFSET, _chn) +#define QTMR_rCSCTRL(_chn) QTMRREG(IMXRT_TMR_CSCTRL_OFFSET, _chn) +#define QTMR_rFILT(_chn) QTMRREG(IMXRT_TMR_FILT_OFFSET, _chn) +#define QTMR_rDMA(_chn) QTMRREG(IMXRT_TMR_DMA_OFFSET, _chn) +#define QTMR_rENBL(_chn) QTMRREG(IMXRT_TMR_ENBL_OFFSET, _chn) + +#define FLEXPWM_TIMER 2 +#define FLEXPWM_SM 3 + +#define FREQ + +static void flexpwm_led_green(uint16_t cvalue) +{ + if (cvalue == 0) { + rMCTRL(FLEXPWM_TIMER) &= ~MCTRL_RUN(1 << FLEXPWM_SM); + px4_arch_configgpio(GPIO_nLED_GREEN); + + } else { + rMCTRL(FLEXPWM_TIMER) |= (1 << (FLEXPWM_SM + MCTRL_CLDOK_SHIFT)); + rVAL1(FLEXPWM_TIMER, FLEXPWM_SM) = (FLEXPWM_FREQ / LED_PWM_FREQ) - 1; + rVAL5(FLEXPWM_TIMER, FLEXPWM_SM) = (FLEXPWM_FREQ / LED_PWM_FREQ) - (cvalue * 3); + rMCTRL(FLEXPWM_TIMER) |= MCTRL_LDOK(1 << FLEXPWM_SM) | MCTRL_RUN(1 << FLEXPWM_SM); + px4_arch_configgpio(PWM_LED_GREEN); + } +} + +static void init_qtimer(unsigned channel) +{ + QTMR_rCNTR(channel) = 0; /* Reset counter */ + QTMR_rSCTRL(channel) = (TMR_SCTRL_OEN | TMR_SCTRL_FORCE); /* Enable output */ + QTMR_rCSCTRL(channel) = (TMR_CSCTRL_CL1_COMP1); + QTMR_rCOMP1(channel) = 0x1; /* Store initial value to the duty-compare register */ + QTMR_rCMPLD1(channel) = 0x1; /* Store initial value to the duty-compare register */ + QTMR_rCOMP2(channel) = 0x1; /* Store initial value to the duty-compare register */ + QTMR_rCMPLD2(channel) = 0x1; /* Store initial value to the duty-compare register */ + QTMR_rCTRL(channel) = (TMR_CTRL_PCS_DIV32 | TMR_CTRL_OUTMODE_TOG_ALT | TMR_CTRL_DIR | + TMR_CTRL_CM_MODE1); /* Run counter */ +} + +int +led_pwm_servo_set(unsigned channel, uint8_t cvalue) +{ + if (channel == 2) { + + if (cvalue == 0) { + px4_arch_configgpio(GPIO_nLED_RED); + + } else { + px4_arch_configgpio(PWM_LED_RED); + QTMR_rCMPLD1(0) = (uint16_t)cvalue * 256; + } + + } else if (channel == 1) { + flexpwm_led_green(cvalue); + + } else if (channel == 0) { + + if (cvalue == 0) { + px4_arch_configgpio(GPIO_nLED_BLUE); + + } else { + px4_arch_configgpio(PWM_LED_BLUE); + QTMR_rCMPLD1(1) = (uint16_t)cvalue * 256; + } + } + + return 0; +} + +int led_pwm_servo_init() +{ + /* PWM_LED_GREEN - FLEXPWM2_PWMB03 */ + imxrt_clockall_pwm2(); + + + /* PWM_LED_RED PWM_LED_BLUE - QTIMER4 */ + imxrt_clockall_timer4(); + + /* Clear all Faults */ + rFSTS0(FLEXPWM_TIMER) = FSTS_FFLAG_MASK; + rMCTRL(FLEXPWM_TIMER) |= (1 << (FLEXPWM_SM + MCTRL_CLDOK_SHIFT)); + + rCTRL2(FLEXPWM_TIMER, FLEXPWM_SM) = SMCTRL2_CLK_SEL_EXT_CLK | SMCTRL2_DBGEN | SMCTRL2_INDEP; + rCTRL(FLEXPWM_TIMER, FLEXPWM_SM) = SMCTRL_PRSC_DIV16 | SMCTRL_FULL; + /* Edge aligned at 0 */ + rINIT(FLEXPWM_TIMER, FLEXPWM_SM) = 0; + rVAL0(FLEXPWM_TIMER, FLEXPWM_SM) = 0; + rVAL2(FLEXPWM_TIMER, FLEXPWM_SM) = 0; + rVAL4(FLEXPWM_TIMER, FLEXPWM_SM) = 0; + rFFILT0(FLEXPWM_TIMER) &= ~FFILT_FILT_PER_MASK; + rDISMAP0(FLEXPWM_TIMER, FLEXPWM_SM) = 0xf000; + rDISMAP1(FLEXPWM_TIMER, FLEXPWM_SM) = 0xf000; + + rOUTEN(FLEXPWM_TIMER) |= OUTEN_PWMB_EN(1 << FLEXPWM_SM); + + rDTSRCSEL(FLEXPWM_TIMER) = 0; + rMCTRL(FLEXPWM_TIMER) |= MCTRL_LDOK(1 << FLEXPWM_SM); + + /* QTMR */ + init_qtimer(0); + init_qtimer(1); + + /* Red - QTIMER4_TMR0 */ + imxrt_xbar_connect(IMXRT_XBARA1_OUT_IOMUX_XBAR_IO16_SEL_OFFSET, IMXRT_XBARA1_IN_QTIMER4_TMR0_OUT); + + /* Blue - QTIMER4_TMR1 */ + imxrt_xbar_connect(IMXRT_XBARA1_OUT_IOMUX_XBAR_IO17_SEL_OFFSET, IMXRT_XBARA1_IN_QTIMER4_TMR1_OUT); + + /* Set XBAR 16 and 17 as an output */ + putreg32((1 << 28) | (1 << 29), IMXRT_IOMUXC_GPR_GPR6); + + return OK; +} diff --git a/boards/nxp/tropic/src/usb.c b/boards/nxp/tropic/src/usb.c index d723fdb65688..99e885964307 100644 --- a/boards/nxp/tropic/src/usb.c +++ b/boards/nxp/tropic/src/usb.c @@ -74,7 +74,7 @@ int imxrt_usb_initialize(void) // We abuse VBUS2 to check if system power checks VBUS gets below 4.7V putreg32(USB_ANALOG_USB_VBUS_DETECT_VBUSVALID_THRESH_4V7 | USB_ANALOG_USB_VBUS_DETECT_VBUSVALID_PWRUP_CMPS, - IMXRT_USB_ANALOG_USB2_VBUS_DETECT); + IMXRT_USB_ANALOG_USB2_VBUS_DETECT); return 0; } /************************************************************************************ diff --git a/platforms/nuttx/src/px4/nxp/imxrt/tone_alarm/ToneAlarmInterface.cpp b/platforms/nuttx/src/px4/nxp/imxrt/tone_alarm/ToneAlarmInterface.cpp index 01389b120093..0c3a10d661dc 100644 --- a/platforms/nuttx/src/px4/nxp/imxrt/tone_alarm/ToneAlarmInterface.cpp +++ b/platforms/nuttx/src/px4/nxp/imxrt/tone_alarm/ToneAlarmInterface.cpp @@ -41,15 +41,155 @@ #include #include "chip.h" +#ifdef TONE_ALARM_FLEXPWM +#include "hardware/imxrt_flexpwm.h" +#else #include "hardware/imxrt_gpt.h" +#endif #include "imxrt_periphclks.h" +#define CAT4_(A, B, C, D) A##B##C##D +#define CAT4(A, B, C, D) CAT4_(A, B, C, D) + #define CAT3_(A, B, C) A##B##C #define CAT3(A, B, C) CAT3_(A, B, C) #define CAT2_(A, B) A##B #define CAT2(A, B) CAT2_(A, B) +#ifdef TONE_ALARM_FLEXPWM + + +/* +* Period of the free-running counter, in microseconds. +*/ +#define TONE_ALARM_COUNTER_PERIOD 4294967296 + +/* Tone Alarm configuration */ + +#define TONE_ALARM_TIMER_CLOCK BOARD_GPT_FREQUENCY /* The input clock frequency to the GPT block */ +#define TONE_ALARM_TIMER_BASE CAT3(IMXRT_FLEXPWM, TONE_ALARM_TIMER,_BASE) /* The Base address of the GPT */ +#define TONE_ALARM_TIMER_VECTOR CAT4(IMXRT_IRQ_FLEXPWM, TONE_ALARM_TIMER, _, TONE_ALARM_CHANNEL) /* The GPT Interrupt vector */ + +#if TONE_ALARM_TIMER == 1 +# define TONE_ALARM_CLOCK_ALL() imxrt_clockall_pwm1() /* The Clock Gating macro for this PWM */ +#elif TONE_ALARM_TIMER == 2 +# define TONE_ALARM_CLOCK_ALL() imxrt_clockall_pwm2() /* The Clock Gating macro for this PWM */ +#elif TONE_ALARM_TIMER == 3 +# define TONE_ALARM_CLOCK_ALL() imxrt_clockall_pwm3() /* The Clock Gating macro for this PWM */ +#elif TONE_ALARM_TIMER == 4 +# define TONE_ALARM_CLOCK_ALL() imxrt_clockall_pwm4() /* The Clock Gating macro for this PWM */ +#endif + +# define TONE_ALARM_TIMER_FREQ 1000000 + +#define SM_SPACING (IMXRT_FLEXPWM_SM1CNT_OFFSET-IMXRT_FLEXPWM_SM0CNT_OFFSET) + +/* Register accessors */ +#define _REG(_addr) (*(volatile uint16_t *)(_addr)) +#define _REG16(_base, _reg) (*(volatile uint16_t *)(_base + _reg)) +#define REG(_tmr, _sm, _reg) _REG16(TONE_ALARM_TIMER_BASE + ((_sm) * SM_SPACING), (_reg)) + + +#define rINIT(_tim, _sm) REG(_tim, _sm,IMXRT_FLEXPWM_SM0INIT_OFFSET) /* Initial Count Register */ +#define rCTRL(_tim, _sm) REG(_tim, _sm,IMXRT_FLEXPWM_SM0CTRL_OFFSET) /* Control Register */ +#define rCTRL2(_tim, _sm) REG(_tim, _sm,IMXRT_FLEXPWM_SM0CTRL2_OFFSET) /* Control 2 Register */ +#define rFSTS0(_tim) REG(_tim, 0, IMXRT_FLEXPWM_FSTS0_OFFSET) /* Fault Status Register */ +#define rVAL0(_tim, _sm) REG(_tim, _sm,IMXRT_FLEXPWM_SM0VAL0_OFFSET) /* Value Register 0 */ +#define rVAL1(_tim, _sm) REG(_tim, _sm,IMXRT_FLEXPWM_SM0VAL1_OFFSET) /* Value Register 1 */ +#define rVAL2(_tim, _sm) REG(_tim, _sm,IMXRT_FLEXPWM_SM0VAL2_OFFSET) /* Value Register 2 */ +#define rVAL3(_tim, _sm) REG(_tim, _sm,IMXRT_FLEXPWM_SM0VAL3_OFFSET) /* Value Register 3 */ +#define rVAL4(_tim, _sm) REG(_tim, _sm,IMXRT_FLEXPWM_SM0VAL4_OFFSET) /* Value Register 4 */ +#define rVAL5(_tim, _sm) REG(_tim, _sm,IMXRT_FLEXPWM_SM0VAL5_OFFSET) /* Value Register 5 */ +#define rFFILT0(_tim) REG(_tim, 0, IMXRT_FLEXPWM_FFILT0_OFFSET) /* Fault Filter Register */ +#define rDISMAP0(_tim, _sm) REG(_tim, _sm,IMXRT_FLEXPWM_SM0DISMAP0_OFFSET) /* Fault Disable Mapping Register 0 */ +#define rDISMAP1(_tim, _sm) REG(_tim, _sm,IMXRT_FLEXPWM_SM0DISMAP1_OFFSET) /* Fault Disable Mapping Register 1 */ +#define rOUTEN(_tim) REG(_tim, 0, IMXRT_FLEXPWM_OUTEN_OFFSET) /* Output Enable Register */ +#define rDTSRCSEL(_tim) REG(_tim, 0, IMXRT_FLEXPWM_DTSRCSEL_OFFSET) /* PWM Source Select Register */ +#define rMCTRL(_tim) REG(_tim, 0, IMXRT_FLEXPWM_MCTRL_OFFSET) /* Master Control Register */ + +namespace ToneAlarmInterface +{ + +void init() +{ +#if defined(TONE_ALARM_TIMER) + /* configure the GPIO to the idle state */ + px4_arch_configgpio(GPIO_TONE_ALARM_IDLE); + + /* Enable the Module clock */ + + TONE_ALARM_CLOCK_ALL(); + + /* Clear all Faults */ + rFSTS0(TONE_ALARM_TIMER) = FSTS_FFLAG_MASK; + rMCTRL(TONE_ALARM_TIMER) |= (1 << (TONE_ALARM_CHANNEL + MCTRL_CLDOK_SHIFT)); + + rCTRL2(TONE_ALARM_TIMER, TONE_ALARM_CHANNEL) = SMCTRL2_CLK_SEL_EXT_CLK | SMCTRL2_DBGEN | SMCTRL2_INDEP; + rCTRL(TONE_ALARM_TIMER, TONE_ALARM_CHANNEL) = SMCTRL_PRSC_DIV16 | SMCTRL_FULL; + /* Edge aligned at 0 */ + rINIT(TONE_ALARM_TIMER, TONE_ALARM_CHANNEL) = 0; + rVAL0(TONE_ALARM_TIMER, TONE_ALARM_CHANNEL) = 0; + rVAL2(TONE_ALARM_TIMER, TONE_ALARM_CHANNEL) = 0; + rVAL4(TONE_ALARM_TIMER, TONE_ALARM_CHANNEL) = 0; + rFFILT0(TONE_ALARM_TIMER) &= ~FFILT_FILT_PER_MASK; + rDISMAP0(TONE_ALARM_TIMER, TONE_ALARM_CHANNEL) = 0xf000; + rDISMAP1(TONE_ALARM_TIMER, TONE_ALARM_CHANNEL) = 0xf000; + + rOUTEN(TONE_ALARM_TIMER) |= TONE_ALARM_FLEXPWM == PWMA_VAL ? OUTEN_PWMA_EN(1 << TONE_ALARM_CHANNEL) + : OUTEN_PWMB_EN(1 << TONE_ALARM_CHANNEL); + + rDTSRCSEL(TONE_ALARM_TIMER) = 0; + rMCTRL(TONE_ALARM_TIMER) |= MCTRL_LDOK(1 << TONE_ALARM_CHANNEL); +#endif /* TONE_ALARM_TIMER */ +} + +hrt_abstime start_note(unsigned frequency) +{ + hrt_abstime time_started = 0; +#if defined(TONE_ALARM_TIMER) + + rMCTRL(TONE_ALARM_TIMER) |= (1 << (TONE_ALARM_CHANNEL + MCTRL_CLDOK_SHIFT)); + + rVAL1(TONE_ALARM_TIMER, TONE_ALARM_CHANNEL) = (TONE_ALARM_TIMER_FREQ / frequency) - 1; + + if (TONE_ALARM_FLEXPWM == PWMA_VAL) { + rVAL3(TONE_ALARM_TIMER, TONE_ALARM_CHANNEL) = ((TONE_ALARM_TIMER_FREQ / frequency) / 2); + + } else { + rVAL5(TONE_ALARM_TIMER, TONE_ALARM_CHANNEL) = ((TONE_ALARM_TIMER_FREQ / frequency) / 2); + } + + rMCTRL(TONE_ALARM_TIMER) |= MCTRL_LDOK(1 << TONE_ALARM_CHANNEL) | MCTRL_RUN(1 << TONE_ALARM_CHANNEL); + + // configure the GPIO to enable timer output + irqstate_t flags = enter_critical_section(); + time_started = hrt_absolute_time(); + px4_arch_configgpio(GPIO_TONE_ALARM); + leave_critical_section(flags); +#endif /* TONE_ALARM_TIMER */ + + return time_started; +} + +void stop_note() +{ +#if defined(TONE_ALARM_TIMER) + /* stop the current note */ + + rMCTRL(TONE_ALARM_TIMER) &= ~MCTRL_RUN(1 << TONE_ALARM_CHANNEL); + + /* + * Make sure the GPIO is not driving the speaker. + */ + px4_arch_configgpio(GPIO_TONE_ALARM_IDLE); +#endif /* TONE_ALARM_TIMER */ +} + +} /* namespace ToneAlarmInterface */ + +#else + /* Check that tone alarm and HRT timers are different */ #if defined(TONE_ALARM_TIMER) && defined(HRT_TIMER) # if TONE_ALARM_TIMER == HRT_TIMER @@ -134,8 +274,6 @@ #define CR_OM CAT3(GPT_CR_OM, TONE_ALARM_CHANNEL,_TOGGLE) /* Output Compare mode */ -#define CBRK_BUZZER_KEY 782097 - namespace ToneAlarmInterface { @@ -215,3 +353,5 @@ void stop_note() } } /* namespace ToneAlarmInterface */ + +#endif