Compare commits

..

12 Commits

Author SHA1 Message Date
Alexander Lerach 9b55dc81ca bl_update: Allow booting from SD card (without forced BL copy to ROMFS) 2025-08-20 18:22:42 +02:00
chfriedrich98 a1bc09a6ad rover: seperate speed control 2025-08-20 10:54:16 +02:00
Hamish Willee e81c62cc36 Add note on INS page about adding the driver modules (#25464) 2025-08-20 18:01:37 +10:00
Hamish Willee 18d76b18b9 docs_flaw_checker.yml3 - use sed to strip out the escapes (#25463) 2025-08-20 16:40:56 +10:00
Hamish Willee 722580760c docs_flaw_checker.yml pt 2 (#25462) 2025-08-20 16:35:49 +10:00
Hamish Willee c65b1d845a docs_flaw_checker.yml - attempt to fix the flaw safely (#25461) 2025-08-20 16:31:12 +10:00
Hamish Willee 71b8e299fd MAV_CMD_REQUEST_MESSAGE support for MESSAGE_INTERVAL (#25460)
* MAV_CMD_REQUEST_MESSAGE support for MESSAGE_INTERVAL

* Default should be -1 for stream

* Format

---------

Co-authored-by: PX4BuildBot <bot@pixhawk.org>
2025-08-20 15:07:44 +10:00
chfriedrich98 eeaf1d7959 docs: new rover stick input scaling parameters (#25427)
* docs: new rover stick input scaling parameters

* docs: clarify rover basic setup

* Update docs/en/config_rover/basic_setup.md

* Minor subedit

---------

Co-authored-by: Hamish Willee <hamishwillee@gmail.com>
2025-08-20 14:12:31 +10:00
Andrew Wilkins 35ff853f76 Docs/test card update (#25451)
* added VIO test card

* added tickets for regression testing

* Subedit

---------

Co-authored-by: Hamish Willee <hamishwillee@gmail.com>
2025-08-20 12:08:49 +10:00
henrykotze 8b58c01cd7 ESP32 Support Sponsored by AutonoSky
nsh console running on USB
param module running
working with i2c and common drivers
provided implementation for drv_pwm_output.h
i2cdetect working as expected with no device
mavlink started succesfully
mounts sd card and logger runs
logger to file succesfully
pwm_servo implemented without using Nuttx lib
pwm_out outputs expected waveforms
- however currently if the frequency is higher than what the pwm_out
driver runs, there will be aliasing, based on how the registers gets
resets
wifi softap working
- Seeing wifi hotspot
- cant connect due to wrong password
- problems with adjusting ssid and password
wifi ssid and password being set accordinglu
connected to wifi hotspot with dhpcd
- made some changes to nuttx to only build for SoftAP mode, however this
was effectivelyy removing the ifdef for STATION mode. Should investigate
the coexist option again
added ifdef to not use timer 0 when wifi enabled
- reverted esp32 rt_timer to make use of timer 0 by default

fix setting incorrect bit in hrt timer register

- hrt running as expected, but on startup the pwm_out driver starts up
at about 200Hz and then rises over a minute or so 250Hz. Not sure if
this was present previously, and could be due to Wifi running at time
priority on timer 0

pull xtensa compilers in setup.ubuntu.sh
revert logger stacksize and cmake argument
esp32 chip revision and PX4 UUID implemented

spi board reset implemented, formatting checked

devkit acts on startup as a wifi bridge for comms

- the most usefull setting for the general developer when buying a esp32 devkit
- testing Mavlink shell using ./Tools/mavlink_shell.py
- todo: Test mavlink messages being forward

improve wifi telemetry by increasing prio

- Remove power save mode on wifi
- increased daemon thread schedule priority to 50

compiles without Nuttx changes

- updated compiler settings to match those of nuttx on px4 side

add espressif_esp32 to excluded boards

ci: allow docker to find xtensa compilers
2025-08-19 11:09:56 -07:00
Silvan Fuhrer b3c7667f41 Fw rate controller: enable yaw rate controller when feeding in yaw rate setpoints outside of manual control (#25457)
Signed-off-by: Silvan <silvan@auterion.com>
2025-08-19 18:41:49 +02:00
Alvaro Fernandez 333b77cb38 fw_mode_manager: fixed altitude hold for auto fixed-bank loiter (#25456) 2025-08-19 17:05:13 +02:00
154 changed files with 9102 additions and 453 deletions
+2 -1
View File
@@ -43,7 +43,8 @@ jobs:
- name: Save JSON file containing files to link check
run: |
echo "$ALL_CHANGED_FILES"
echo "$ALL_CHANGED_FILES" > ./logs/prFiles.json
# echo "$ALL_CHANGED_FILES" > ./logs/prFiles.json
echo "$ALL_CHANGED_FILES" | sed 's/\\//g' | jq '.' > ./logs/prFiles.json
env:
ALL_CHANGED_FILES: ${{ steps.get_changed_markdown_english.outputs.all_changed_files }}
+2 -2
View File
@@ -208,12 +208,12 @@ set(OPTIONAL_BOARD_EXTRAS)
file(GLOB OPTIONAL_BOARD_EXTRAS ${PX4_BOARD_DIR}/extras/*)
# bootloader (optional)
# - if systemcmds/bl_update included and board bootloader available then generate rc.board_bootloader_upgrade and copy bootloader binary
# - if systemcmds/bl_update included (with romfs copy) and board bootloader available then generate rc.board_bootloader_upgrade and copy bootloader binary
# - otherwise remove bootloader binary from extras in final ROMFS
foreach(board_extra_file ${OPTIONAL_BOARD_EXTRAS})
file(RELATIVE_PATH extra_file_base_name ${PX4_BOARD_DIR}/extras/ ${board_extra_file})
if(${extra_file_base_name} MATCHES "${PX4_BOARD_VENDOR}_${PX4_BOARD_MODEL}_bootloader.bin")
if(CONFIG_SYSTEMCMDS_BL_UPDATE)
if(CONFIG_SYSTEMCMDS_BL_UPDATE AND CONFIG_BL_UPDATE_BL_ROMFS)
# generate rc.board_bootloader_upgrade
set(BOARD_FIRMWARE_BIN "${PX4_BOARD_VENDOR}_${PX4_BOARD_MODEL}_bootloader.bin")
message(STATUS "ROMFS: Adding platforms/nuttx/init/rc.board_bootloader_upgrade -> /etc/init.d/rc.board_bootloader_upgrade")
+19 -1
View File
@@ -613,7 +613,9 @@ else
. ${R}etc/init.d/rc.autostart.post
fi
#
# Bootloader upgrade (ROMFS)
#
set BOARD_BOOTLOADER_UPGRADE ${R}etc/init.d/rc.board_bootloader_upgrade
if [ -f $BOARD_BOOTLOADER_UPGRADE ]
then
@@ -621,6 +623,22 @@ else
fi
unset BOARD_BOOTLOADER_UPGRADE
#
# Bootloader upgrade (SD card)
#
if param compare -s SYS_BL_UPDATE 2
then
if [ -f "/fs/microsd/bl/bl.bin" ]
then
param set SYS_BL_UPDATE 0
param save
echo "bootloader update..."
bl_update "/fs/microsd/bl/bl.bin"
echo "bootloader update done, rebooting"
reboot
fi
fi
#
# Check if UAVCAN is enabled, default to it for ESCs.
#
+1 -1
View File
@@ -38,7 +38,7 @@ if args.filter:
default_container = 'ghcr.io/px4/px4-dev:v1.16.0-rc1-258-g0369abd556'
build_configs = []
grouped_targets = {}
excluded_boards = ['modalai_voxl2', 'px4_ros2'] # TODO: fix and enable
excluded_boards = ['modalai_voxl2', 'px4_ros2', 'espressif_esp32'] # TODO: fix and enable
excluded_manufacturers = ['atlflight']
excluded_platforms = ['qurt']
excluded_labels = [
+2
View File
@@ -29,6 +29,8 @@ RUN git config --global --add safe.directory '*'
# Create user with id 1001 (jenkins docker workflow default)
RUN useradd --shell /bin/bash -u 1001 -c "" -m user && usermod -a -G dialout user
ENV PATH="${PATH}:/opt/xtensa-esp-elf/bin"
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
CMD ["/bin/bash"]
+7
View File
@@ -155,7 +155,14 @@ if [[ $INSTALL_NUTTX == "true" ]]; then
g++-multilib \
gcc-arm-none-eabi \
gcc-multilib \
esptool \
;
echo
echo "Fetching Xtensa compilers"
wget -q -P $DIR https://github.com/espressif/crosstool-NG/releases/download/esp-13.2.0_20240530/xtensa-esp-elf-13.2.0_20240530-x86_64-linux-gnu.tar.xz
sudo tar -xf $DIR/xtensa-esp-elf-13.2.0_20240530-x86_64-linux-gnu.tar.xz -C /opt
echo 'export PATH=$PATH:/opt/xtensa-esp-elf/bin/' >> /home/$USER/.bashrc
fi
if [[ "${INSTALL_ARCH}" == "aarch64" ]]; then
@@ -75,6 +75,7 @@ CONFIG_MODULES_UUV_POS_CONTROL=y
CONFIG_MODULES_VTOL_ATT_CONTROL=y
CONFIG_SYSTEMCMDS_ACTUATOR_TEST=y
CONFIG_SYSTEMCMDS_BL_UPDATE=y
CONFIG_BL_UPDATE_BL_ROMFS=y
CONFIG_SYSTEMCMDS_BSONDUMP=y
CONFIG_SYSTEMCMDS_DUMPFILE=y
CONFIG_SYSTEMCMDS_GPIO=y
+1
View File
@@ -35,6 +35,7 @@ CONFIG_MODULES_SENSORS=y
CONFIG_MODULES_SIMULATION_SIMULATOR_SIH=y
CONFIG_SYSTEMCMDS_ACTUATOR_TEST=y
CONFIG_SYSTEMCMDS_BL_UPDATE=y
CONFIG_BL_UPDATE_BL_ROMFS=y
CONFIG_SYSTEMCMDS_DMESG=y
CONFIG_SYSTEMCMDS_DUMPFILE=y
CONFIG_SYSTEMCMDS_HARDFAULT_LOG=y
+1
View File
@@ -71,6 +71,7 @@ CONFIG_MODULES_UUV_POS_CONTROL=y
CONFIG_MODULES_VTOL_ATT_CONTROL=y
CONFIG_SYSTEMCMDS_ACTUATOR_TEST=y
CONFIG_SYSTEMCMDS_BL_UPDATE=y
CONFIG_BL_UPDATE_BL_ROMFS=y
CONFIG_SYSTEMCMDS_BSONDUMP=y
CONFIG_SYSTEMCMDS_DMESG=y
CONFIG_SYSTEMCMDS_DUMPFILE=y
+1
View File
@@ -8,4 +8,5 @@ CONFIG_MODULES_LOCAL_POSITION_ESTIMATOR=n
CONFIG_BOARD_TESTING=y
CONFIG_DRIVERS_TEST_PPM=y
CONFIG_SYSTEMCMDS_BL_UPDATE=y
CONFIG_BL_UPDATE_BL_ROMFS=y
CONFIG_SYSTEMCMDS_MICROBENCH=y
@@ -74,6 +74,7 @@ CONFIG_MODULES_UXRCE_DDS_CLIENT=y
CONFIG_MODULES_VTOL_ATT_CONTROL=y
CONFIG_SYSTEMCMDS_ACTUATOR_TEST=y
CONFIG_SYSTEMCMDS_BL_UPDATE=y
CONFIG_BL_UPDATE_BL_ROMFS=y
CONFIG_SYSTEMCMDS_BSONDUMP=y
CONFIG_SYSTEMCMDS_DMESG=y
CONFIG_SYSTEMCMDS_GPIO=y
@@ -75,6 +75,7 @@ CONFIG_MODULES_UXRCE_DDS_CLIENT=y
CONFIG_MODULES_VTOL_ATT_CONTROL=y
CONFIG_SYSTEMCMDS_ACTUATOR_TEST=y
CONFIG_SYSTEMCMDS_BL_UPDATE=y
CONFIG_BL_UPDATE_BL_ROMFS=y
CONFIG_SYSTEMCMDS_BSONDUMP=y
CONFIG_SYSTEMCMDS_DMESG=y
CONFIG_SYSTEMCMDS_GPIO=y
@@ -75,6 +75,7 @@ CONFIG_MODULES_UUV_POS_CONTROL=y
CONFIG_MODULES_VTOL_ATT_CONTROL=y
CONFIG_SYSTEMCMDS_ACTUATOR_TEST=y
CONFIG_SYSTEMCMDS_BL_UPDATE=y
CONFIG_BL_UPDATE_BL_ROMFS=y
CONFIG_SYSTEMCMDS_BSONDUMP=y
CONFIG_SYSTEMCMDS_DMESG=y
CONFIG_SYSTEMCMDS_DUMPFILE=y
Binary file not shown.
Binary file not shown.
Binary file not shown.
+39
View File
@@ -0,0 +1,39 @@
CONFIG_BOARD_TOOLCHAIN="xtensa-esp32-elf"
CONFIG_BOARD_ARCHITECTURE="esp32"
CONFIG_BOARD_ROMFSROOT="cannode"
CONFIG_BOARD_EXTERNAL_METADATA=y
CONFIG_BOARD_ETHERNET=y
CONFIG_DRIVERS_PWM_OUT=y
CONFIG_MODULES_CONTROL_ALLOCATOR=y
CONFIG_MODULES_DATAMAN=y
# CONFIG_DATAMAN_PERSISTENT_STORAGE is not set
CONFIG_NUM_MISSION_ITMES_SUPPORTED=1
CONFIG_MODULES_EVENTS=y
CONFIG_MODULES_GIMBAL=y
CONFIG_MODULES_LOAD_MON=y
CONFIG_MODULES_LOGGER=y
CONFIG_LOGGER_STACK_SIZE=4000
CONFIG_MODULES_MAVLINK=y
CONFIG_MODULES_NAVIGATOR=y
# CONFIG_NAVIGATOR_ADSB is not set
CONFIG_MODULES_PAYLOAD_DELIVERER=y
CONFIG_SYSTEMCMDS_BSONDUMP=y
CONFIG_SYSTEMCMDS_DMESG=y
CONFIG_SYSTEMCMDS_DUMPFILE=y
CONFIG_SYSTEMCMDS_I2CDETECT=y
CONFIG_SYSTEMCMDS_MFT=y
CONFIG_SYSTEMCMDS_MTD=y
CONFIG_SYSTEMCMDS_NETMAN=y
CONFIG_SYSTEMCMDS_NSHTERM=y
CONFIG_SYSTEMCMDS_PARAM=y
CONFIG_SYSTEMCMDS_PERF=y
CONFIG_SYSTEMCMDS_REBOOT=y
CONFIG_SYSTEMCMDS_SD_BENCH=y
CONFIG_SYSTEMCMDS_SD_STRESS=y
CONFIG_SYSTEMCMDS_SYSTEM_TIME=y
CONFIG_SYSTEMCMDS_TOP=y
CONFIG_SYSTEMCMDS_TOPIC_LISTENER=y
CONFIG_SYSTEMCMDS_UORB=y
CONFIG_SYSTEMCMDS_VER=y
CONFIG_SYSTEMCMDS_WORK_QUEUE=y
CONFIG_BOARD_PWM_FREQ=250
+13
View File
@@ -0,0 +1,13 @@
{
"board_id": 42,
"magic": "ESP32",
"description": "Firmware for the ESP32",
"image": "",
"build_time": 0,
"summary": "ESP32",
"version": "0.1",
"image_size": 0,
"image_maxsize": 1032192,
"git_identity": "",
"board_revision": 0
}
@@ -0,0 +1,8 @@
#!/bin/sh
#
# board specific defaults
#------------------------------------------------------------------------------
dhcpd_start wlan0
mavlink start -u 14550 -o 14550 -m 0 -r 1000 -x -p -s
mavlink start -d /dev/ttyS1 -b 115200 -f -w -Z
@@ -0,0 +1,6 @@
#!/bin/sh
#
# board specific MAVLink startup script.
#------------------------------------------------------------------------------
# Start MAVLink on the USB port
@@ -0,0 +1,4 @@
#!/bin/sh
#
# board specific sensors init
#------------------------------------------------------------------------------
@@ -0,0 +1,61 @@
/************************************************************************************
* configs/px4fmu/include/board.h
* include/arch/board/board.h
*
* Copyright (C) 2009 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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.
*
************************************************************************************/
#ifndef __ARCH_BOARD_BOARD_H
#define __ARCH_BOARD_BOARD_H
/************************************************************************************
* Included Files
************************************************************************************/
#include <nuttx/config.h>
#ifndef __ASSEMBLY__
# include <stdint.h>
#endif
#include <arch/board/esp32_board.h>
#define LED_STARTED 0 /* LED2 */
#define LED_HEAPALLOCATE 1 /* LED3 */
#define LED_IRQSENABLED 2 /* LED3 + LED2 */
#define LED_STACKCREATED 3 /* LED3 */
#define LED_INIRQ 4 /* LED1 + LED3 */
#define LED_SIGNAL 5 /* LED2 + LED3 */
#define LED_ASSERTION 6 /* LED1 + LED2 + LED3 */
#define LED_PANIC 7 /* LED1 + N/C + N/C */
#endif /* __ARCH_BOARD_BOARD_H */
@@ -0,0 +1,85 @@
/****************************************************************************
* boards/xtensa/esp32/esp32-devkitc/include/board.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __BOARDS_XTENSA_ESP32_ESP32_CORE_INCLUDE_BOARD_H
#define __BOARDS_XTENSA_ESP32_ESP32_CORE_INCLUDE_BOARD_H
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Clocking *****************************************************************/
/* The ESP32 Core board V2 is fitted with either a 26 a 40MHz crystal */
#ifdef CONFIG_ESP32_XTAL_26MHz
# define BOARD_XTAL_FREQUENCY 26000000
#else
# define BOARD_XTAL_FREQUENCY 40000000
#endif
/* Clock reconfiguration is currently disabled, so the CPU will be running
* at the XTAL frequency or at two times the XTAL frequency, depending upon
* how we load the code:
*
* - If we load the code into FLASH at address 0x1000 where it is started by
* the second level bootloader, then the frequency is the crystal
* frequency.
* - If we load the code into IRAM after the second level bootloader has run
* this frequency will be twice the crystal frequency.
*
* Don't ask me for an explanation.
*/
/* Note: The bootloader (esp-idf bootloader.bin) configures:
*
* - CPU frequency to 80MHz
* - The XTAL frequency according to the SDK config CONFIG_ESP32_XTAL_FREQ,
* which is 40MHz by default.
*
* Reference:
* https://github.com/espressif/esp-idf/blob
* /6fd855ab8d00d23bad4660216bc2122c2285d5be/components
* /bootloader_support/src/bootloader_clock.c#L38-L62
*/
#ifdef CONFIG_ESP32_RUN_IRAM
# define BOARD_CLOCK_FREQUENCY (2 * BOARD_XTAL_FREQUENCY)
#else
#ifdef CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ
# define BOARD_CLOCK_FREQUENCY (CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ * 1000000)
#else
# define BOARD_CLOCK_FREQUENCY 80000000
#endif
#endif
/* LED definitions **********************************************************/
/* Define how many LEDs this board has (needed by userleds) */
#define BOARD_NLEDS 1
/* GPIO pins used by the GPIO Subsystem */
#define BOARD_NGPIOOUT 1 /* Amount of GPIO Output pins */
#define BOARD_NGPIOIN 1 /* Amount of GPIO Input without Interruption */
#define BOARD_NGPIOINT 1 /* Amount of GPIO Input w/ Interruption pins */
#endif /* __BOARDS_XTENSA_ESP32_ESP32_CORE_INCLUDE_BOARD_H */
@@ -0,0 +1,219 @@
#
# This file is autogenerated: PLEASE DO NOT EDIT IT.
#
# You can use "make menuconfig" to make any modifications to the installed .config file.
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
# modifications.
#
# CONFIG_ESP32_SPI3_DMA is not set
# CONFIG_ESP32_SPI_SWCS is not set
# CONFIG_ESP32_WIFI_RX_AMPDU is not set
# CONFIG_ESP32_WIFI_TX_AMPDU is not set
# CONFIG_MMCSD_HAVE_CARDDETECT is not set
# CONFIG_MMCSD_HAVE_WRITEPROTECT is not set
# CONFIG_MMCSD_MMCSUPPORT is not set
# CONFIG_NSH_DISABLE_DATE is not set
# CONFIG_SPI_CALLBACK is not set
CONFIG_ALLOW_BSD_COMPONENTS=y
CONFIG_ARCH="xtensa"
CONFIG_ARCH_BOARD_COMMON=y
CONFIG_ARCH_BOARD_CUSTOM=y
CONFIG_ARCH_BOARD_CUSTOM_DIR="../../../../boards/espressif/esp32/nuttx-config"
CONFIG_ARCH_BOARD_CUSTOM_DIR_RELPATH=y
CONFIG_ARCH_BOARD_CUSTOM_NAME=""
CONFIG_ARCH_CHIP="esp32"
CONFIG_ARCH_CHIP_ESP32=y
CONFIG_ARCH_CHIP_ESP32WROOM32=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_ARCH_XTENSA=y
CONFIG_BOARDCTL_MKRD=y
CONFIG_BOARDCTL_RESET=y
CONFIG_BOARD_LOOPSPERMSEC=16717
CONFIG_BUILTIN=y
CONFIG_DEBUG_FULLOPT=y
CONFIG_DEBUG_SYMBOLS=y
CONFIG_DEBUG_TCBINFO=y
CONFIG_DEV_FIFO_SIZE=0
CONFIG_DEV_PIPE_MAXSIZE=1024
CONFIG_DEV_PIPE_SIZE=70
CONFIG_DEV_URANDOM=y
CONFIG_DRIVERS_IEEE80211=y
CONFIG_DRIVERS_WIRELESS=y
CONFIG_ELF=y
CONFIG_ESP32_FLASH_FREQ_80M=y
CONFIG_ESP32_FLASH_MODE_QIO=y
CONFIG_ESP32_I2C0=y
CONFIG_ESP32_I2CTIMEOMS=10
CONFIG_ESP32_LEDC=y
CONFIG_ESP32_LEDC_CHANNEL1_PIN=13
CONFIG_ESP32_LEDC_CHANNEL2_PIN=16
CONFIG_ESP32_LEDC_CHANNEL3_PIN=17
CONFIG_ESP32_LEDC_TIM0=y
CONFIG_ESP32_LEDC_TIM0_CHANNELS=4
CONFIG_ESP32_SPI3=y
CONFIG_ESP32_SPIFLASH=y
CONFIG_ESP32_SPIFLASH_SPIFFS=y
CONFIG_ESP32_UART0=y
CONFIG_ESP32_UART1=y
CONFIG_ESP32_UART1_RXPIN=14
CONFIG_ESP32_UART1_TXPIN=12
CONFIG_ESP32_WIFI=y
CONFIG_ESP32_WIFI_DYNAMIC_RXBUF_NUM=16
CONFIG_ESP32_WIFI_DYNAMIC_TXBUF_NUM=16
CONFIG_ESP32_WIFI_SAVE_PARAM=y
CONFIG_ESP32_WIFI_STATION_SOFTAP_COEXISTENCE=y
CONFIG_EXAMPLES_CALIB_UDELAY=y
CONFIG_EXAMPLES_DHCPD=y
CONFIG_FAT_DMAMEMORY=y
CONFIG_FAT_LCNAMES=y
CONFIG_FAT_LFN=y
CONFIG_FAT_LFN_ALIAS_HASH=y
CONFIG_FAT_LFN_UTF8=y
CONFIG_FSUTILS_IPCFG=y
CONFIG_FS_BINFS=y
CONFIG_FS_CROMFS=y
CONFIG_FS_FAT=y
CONFIG_FS_FATTIME=y
CONFIG_FS_PROCFS=y
CONFIG_FS_PROCFS_REGISTER=y
CONFIG_FS_ROMFS=y
CONFIG_GRAN=y
CONFIG_GRAN_INTR=y
CONFIG_HAVE_CXX=y
CONFIG_HAVE_CXXINITIALIZE=y
CONFIG_I2C=y
CONFIG_IDLETHREAD_STACKSIZE=2048
CONFIG_IEEE80211_BROADCOM_DEFAULT_COUNTRY="27"
CONFIG_IEEE80211_BROADCOM_SCHED_PRIORITY=50
CONFIG_INIT_ENTRYPOINT="nsh_main"
CONFIG_INIT_STACKSIZE=6000
CONFIG_INTELHEX_BINARY=y
CONFIG_IOB_THROTTLE=0
CONFIG_IPCFG_BINARY=y
CONFIG_IPCFG_CHARDEV=y
CONFIG_IPCFG_PATH="/fs/mtd_net"
CONFIG_LIBC_MAX_EXITFUNS=1
CONFIG_MMCSD=y
CONFIG_MM_REGIONS=3
CONFIG_MTD_RAMTRON=y
CONFIG_NAME_MAX=48
CONFIG_NETDB_DNSCLIENT=y
CONFIG_NETDEVICES=y
CONFIG_NETDEV_LATEINIT=y
CONFIG_NETDEV_PHY_IOCTL=y
CONFIG_NETDEV_WIRELESS_IOCTL=y
CONFIG_NETDOWN_NOTIFIER=y
CONFIG_NETINIT_DNS=y
CONFIG_NETINIT_DNSIPADDR=0xA290AFE
CONFIG_NETINIT_DRIPADDR=0XA290AFE
CONFIG_NETINIT_IPADDR=0xC0A80001
CONFIG_NETINIT_MONITOR=y
CONFIG_NETINIT_THREAD=y
CONFIG_NETINIT_THREAD_PRIORITY=49
CONFIG_NETINIT_WAPI_ALG=0
CONFIG_NETINIT_WAPI_AUTHWPA=0x00000001
CONFIG_NETINIT_WAPI_CIPHERMODE=0x00000001
CONFIG_NETINIT_WAPI_PASSPHRASE="px4-esp32"
CONFIG_NETINIT_WAPI_SSID="px4-esp32"
CONFIG_NETINIT_WAPI_STAMODE=3
CONFIG_NETUTILS_DHCPC_BOOTP_FLAGS=0x0000
CONFIG_NETUTILS_DHCPD=y
CONFIG_NETUTILS_DHCPD_DNSIP=0xc0a80001
CONFIG_NETUTILS_DHCPD_MAXLEASES=2
CONFIG_NETUTILS_DHCPD_ROUTERIP=0xc0a80001
CONFIG_NETUTILS_DHCPD_STACKSIZE=3048
CONFIG_NETUTILS_DHCPD_STARTIP=0xc0a80002
CONFIG_NETUTILS_TELNETC=y
CONFIG_NETUTILS_TELNETD=y
CONFIG_NET_ARP_IPIN=y
CONFIG_NET_ARP_SEND=y
CONFIG_NET_BROADCAST=y
CONFIG_NET_ETH_PKTSIZE=1518
CONFIG_NET_ICMP=y
CONFIG_NET_ICMP_SOCKET=y
CONFIG_NET_NETLINK=y
CONFIG_NET_SOLINGER=y
CONFIG_NET_TCP=y
CONFIG_NET_TCPBACKLOG=y
CONFIG_NET_TCP_DELAYED_ACK=y
CONFIG_NET_TCP_WRITE_BUFFERS=y
CONFIG_NET_UDP=y
CONFIG_NET_UDP_WRITE_BUFFERS=y
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_CROMFSETC=y
CONFIG_NSH_DISABLE_BASENAME=y
CONFIG_NSH_DISABLE_CMP=y
CONFIG_NSH_DISABLE_DD=y
CONFIG_NSH_DISABLE_DIRNAME=y
CONFIG_NSH_DISABLE_HEXDUMP=y
CONFIG_NSH_DISABLE_LOSETUP=y
CONFIG_NSH_DISABLE_MKFIFO=y
CONFIG_NSH_DISABLE_MKRD=y
CONFIG_NSH_DISABLE_PRINTF=y
CONFIG_NSH_DISABLE_PUT=y
CONFIG_NSH_DISABLE_TRUNCATE=y
CONFIG_NSH_DISABLE_UNAME=y
CONFIG_NSH_DISABLE_WGET=y
CONFIG_NSH_DISABLE_XD=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_LINELEN=128
CONFIG_NSH_MAXARGUMENTS=15
CONFIG_NSH_NESTDEPTH=8
CONFIG_NSH_READLINE=y
CONFIG_NSH_ROMFSETC=y
CONFIG_NSH_ROMFSSECTSIZE=128
CONFIG_NSH_VARS=y
CONFIG_PIPES=y
CONFIG_PREALLOC_TIMERS=50
CONFIG_PRIORITY_INHERITANCE=y
CONFIG_PTHREAD_MUTEX_TYPES=y
CONFIG_PTHREAD_STACK_MIN=512
CONFIG_PWM_MULTICHAN=y
CONFIG_PWM_NCHANNELS=4
CONFIG_RAMTRON_EMULATE_PAGE_SHIFT=10
CONFIG_RAMTRON_EMULATE_SECTOR_SHIFT=10
CONFIG_RAMTRON_SETSPEED=y
CONFIG_RAM_SIZE=114688
CONFIG_RAM_START=0x20000000
CONFIG_RAW_BINARY=y
CONFIG_READLINE_CMD_HISTORY=y
CONFIG_READLINE_CMD_HISTORY_LEN=4
CONFIG_READLINE_CMD_HISTORY_LINELEN=64
CONFIG_READLINE_TABCOMPLETION=y
CONFIG_SCHED_HPWORK=y
CONFIG_SCHED_HPWORKPRIORITY=249
CONFIG_SCHED_HPWORKSTACKSIZE=1280
CONFIG_SCHED_INSTRUMENTATION=y
CONFIG_SCHED_INSTRUMENTATION_EXTERNAL=y
CONFIG_SCHED_INSTRUMENTATION_SWITCH=y
CONFIG_SCHED_LPWORK=y
CONFIG_SCHED_LPWORKPRIOMAX=178
CONFIG_SCHED_WAITPID=y
CONFIG_SEM_PREALLOCHOLDERS=32
CONFIG_SERIAL_TERMIOS=y
CONFIG_SIG_DEFAULT=y
CONFIG_SIG_SIGALRM_ACTION=y
CONFIG_SIG_SIGCONDTIMEDOUT=19
CONFIG_SIG_SIGUSR1_ACTION=y
CONFIG_SIG_SIGUSR2_ACTION=y
CONFIG_SIG_SIGWORK=20
CONFIG_SPIFFS_NAME_MAX=48
CONFIG_STACK_COLORATION=y
CONFIG_START_DAY=30
CONFIG_START_MONTH=11
CONFIG_STDIO_BUFFER_SIZE=32
CONFIG_SYSTEM_DHCPC_RENEW=y
CONFIG_SYSTEM_MDIO=y
CONFIG_SYSTEM_NETDB=y
CONFIG_SYSTEM_NSH=y
CONFIG_SYSTEM_NSH_STACKSIZE=1000
CONFIG_SYSTEM_PING=y
CONFIG_TASK_NAME_SIZE=24
CONFIG_TLS_TASK_NELEM=4
CONFIG_UART0_SERIAL_CONSOLE=y
CONFIG_USEC_PER_TICK=1000
CONFIG_WIRELESS=y
CONFIG_WIRELESS_WAPI=y
CONFIG_WIRELESS_WAPI_CMDTOOL=y
CONFIG_WIRELESS_WAPI_STACKSIZE=4096
@@ -0,0 +1,296 @@
/****************************************************************************
* boards/xtensa/esp32/common/scripts/esp32.ld
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/* Default entry point: */
ENTRY(__start);
SECTIONS
{
/* Send .iram0 code to iram */
.iram0.vectors :
{
/* Vectors go to IRAM */
_init_start = ABSOLUTE(.);
/* Vectors according to builds/RF-2015.2-win32/esp108_v1_2_s5_512int_2/config.html */
. = 0x0;
KEEP (*(.window_vectors.text));
. = 0x180;
KEEP (*(.xtensa_level2_vector.text));
. = 0x1c0;
KEEP (*(.xtensa_level3_vector.text));
. = 0x200;
KEEP (*(.xtensa_level4_vector.text));
. = 0x240;
KEEP (*(.xtensa_level5_vector.text));
. = 0x280;
KEEP (*(.debug_exception_vector.text));
. = 0x2c0;
KEEP (*(.nmi_vector.text));
. = 0x300;
KEEP (*(.kernel_exception_vector.text));
. = 0x340;
KEEP (*(.user_exception_vector.text));
. = 0x3c0;
KEEP (*(.double_exception_vector.text));
. = 0x400;
*(.*_vector.literal)
. = ALIGN (16);
*(.entry.text)
*(.init.literal)
*(.init)
_init_end = ABSOLUTE(.);
} > iram0_0_seg
.iram0.text :
{
/* Code marked as running out of IRAM */
_iram_text_start = ABSOLUTE(.);
*(.iram1 .iram1.*)
*librtc.a:(.literal .text .literal.* .text.*)
*libarch.a:esp32_spiflash.*(.literal .text .literal.* .text.*)
*libarch.a:xtensa_cpupause.*(.literal .text .literal.* .text.*)
*libarch.a:xtensa_copystate.*(.literal .text .literal.* .text.*)
*libarch.a:xtensa_interruptcontext.*(.literal .text .literal.* .text.*)
*libarch.a:xtensa_testset.*(.literal .text .literal.* .text.*)
*libsched.a:sched_suspendscheduler.*(.literal .text .literal.* .text.*)
*libsched.a:sched_note.*(.literal .text .literal.* .text.*)
*libsched.a:sched_thistask.*(.literal .text .literal.* .text.*)
*libsched.a:spinlock.*(.literal .text .literal.* .text.*)
*libsched.a:irq_csection.*(.literal .text .literal.* .text.*)
*libsched.a:irq_dispatch.*(.literal .text .literal.* .text.*)
*(.wifirxiram .wifirxiram.*)
*(.wifi0iram .wifi0iram.*)
*(.wifislpiram .wifislpiram.*)
*(.wifislprxiram .wifislprxiram.*)
*(.phyiram .phyiram.*)
_iram_text_end = ABSOLUTE(.);
/* IRAM heap starts at the end of iram0_0_seg */
. = ALIGN (4);
_siramheap = ABSOLUTE(.);
} > iram0_0_seg
/* Shared RAM */
.dram0.bss (NOLOAD) :
{
/* .bss initialized on power-up */
. = ALIGN (8);
_sbss = ABSOLUTE(.);
_bss_start = ABSOLUTE(.);
*(.ext_ram.bss*)
_bt_bss_start = ABSOLUTE(.);
*libbt.a:(.bss .bss.* COMMON)
. = ALIGN (4);
_bt_bss_end = ABSOLUTE(.);
_btdm_bss_start = ABSOLUTE(.);
*libbtdm_app.a:(.bss .bss.* COMMON)
. = ALIGN (4);
_btdm_bss_end = ABSOLUTE(.);
. = ALIGN (8);
*(.dynsbss)
*(.sbss)
*(.sbss.*)
*(.gnu.linkonce.sb.*)
*(.scommon)
*(.sbss2)
*(.sbss2.*)
*(.gnu.linkonce.sb2.*)
*(.dynbss)
KEEP (*(.bss))
*(.bss.*)
*(.share.mem)
*(.gnu.linkonce.b.*)
*(COMMON)
*libarch.a:esp32_spiflash.*(.bss .bss.* COMMON)
*libarch.a:xtensa_cpupause.*(.bss .bss.* COMMON)
*libarch.a:xtensa_copystate.*(.bss .bss.* COMMON)
*libarch.a:xtensa_interruptcontext.*(.bss .bss.* COMMON)
*libarch.a:xtensa_testset.*(.bss .bss.* COMMON)
*libsched.a:sched_suspendscheduler.*(.bss .bss.* COMMON)
*libsched.a:sched_thistask.*(.bss .bss.* COMMON)
*libsched.a:sched_note.*(.bss .bss.* COMMON)
*libsched.a:spinlock.*(.bss .bss.* COMMON)
*libsched.a:irq_csection.*(.bss .bss.* COMMON)
*libsched.a:irq_dispatch.*(.bss .bss.* COMMON)
. = ALIGN(8);
_bss_end = ABSOLUTE(.);
_ebss = ABSOLUTE(.);
} >dram0_0_seg
.noinit (NOLOAD):
{
/* This section contains data that is not initialized during load,
* or during the application's initialization sequence.
*/
*(.noinit)
} >dram0_0_seg
.dram0.data :
{
/* .data initialized on power-up in ROMed configurations. */
_sdata = ABSOLUTE(.);
_bt_data_start = ABSOLUTE(.);
*libbt.a:(.data .data.*)
. = ALIGN (4);
_bt_data_end = ABSOLUTE(.);
_btdm_data_start = ABSOLUTE(.);
*libbtdm_app.a:(.data .data.*)
. = ALIGN (4);
_btdm_data_end = ABSOLUTE(.);
KEEP (*(.data))
KEEP (*(.data.*))
KEEP (*(.gnu.linkonce.d.*))
KEEP (*(.data1))
KEEP (*(.sdata))
KEEP (*(.sdata.*))
KEEP (*(.gnu.linkonce.s.*))
KEEP (*(.sdata2))
KEEP (*(.sdata2.*))
KEEP (*(.gnu.linkonce.s2.*))
KEEP (*(.jcr))
*(.dram1 .dram1.*)
*libphy.a:(.rodata .rodata.*)
*libarch.a:esp32_spiflash.*(.rodata .rodata.*)
*libarch.a:xtensa_cpupause.*(.rodata .rodata.*)
*libarch.a:xtensa_copystate.*(.rodata .rodata.*)
*libarch.a:xtensa_interruptcontext.*(.rodata .rodata.*)
*libarch.a:xtensa_testset.*(.rodata .rodata.*)
*libsched.a:sched_suspendscheduler.*(.rodata .rodata.*)
*libsched.a:sched_thistask.*(.rodata .rodata.*)
*libsched.a:sched_note.*(.rodata .rodata.*)
*libsched.a:spinlock.*(.rodata .rodata.*)
*libsched.a:irq_csection.*(.rodata .rodata.*)
*libsched.a:irq_dispatch.*(.rodata .rodata.*)
. = ALIGN(4);
_edata = ABSOLUTE(.);
/* Heap starts at the end of .data */
_sheap = ABSOLUTE(.);
} >dram0_0_seg
/* External memory bss, from any global variable with EXT_RAM_ATTR attribute */
.extmem.bss (NOLOAD) :
{
_sbss_extmem = ABSOLUTE(.);
*(.extmem.bss .extmem.bss.*)
. = ALIGN(4);
_ebss_extmem = ABSOLUTE(.);
} > extmem_seg
.flash.rodata :
{
_srodata = ABSOLUTE(.);
*(.rodata)
*(.rodata.*)
*(.irom1.text) /* catch stray ICACHE_RODATA_ATTR */
*(.gnu.linkonce.r.*)
*(.rodata1)
__XT_EXCEPTION_TABLE_ = ABSOLUTE(.);
*(.xt_except_table)
*(.gcc_except_table)
*(.gcc_except_table.*)
*(.gnu.linkonce.e.*)
*(.gnu.version_r)
*(.eh_frame)
. = (. + 3) & ~ 3;
/* C++ constructor and destructor tables, properly ordered: */
_sinit = ABSOLUTE(.);
KEEP (*crtbegin.o(.ctors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
_einit = ABSOLUTE(.);
KEEP (*crtbegin.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
/* C++ exception handlers table: */
__XT_EXCEPTION_DESCS_ = ABSOLUTE(.);
*(.xt_except_desc)
*(.gnu.linkonce.h.*)
__XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.);
*(.xt_except_desc_end)
*(.dynamic)
*(.gnu.version_d)
_erodata = ABSOLUTE(.);
/* Literals are also RO data. */
_lit4_start = ABSOLUTE(.);
*(*.lit4)
*(.lit4.*)
*(.gnu.linkonce.lit4.*)
_lit4_end = ABSOLUTE(.);
. = ALIGN(4);
} >default_rodata_seg
.flash.text :
{
_stext = .;
_text_start = ABSOLUTE(.);
*(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
*(.irom0.text) /* catch stray ICACHE_RODATA_ATTR */
*(.fini.literal)
*(.fini)
*(.gnu.version)
_text_end = ABSOLUTE(.);
_etext = .;
} >default_code_seg
.rtc.text :
{
. = ALIGN(4);
*(.rtc.literal .rtc.text)
} >rtc_iram_seg
.rtc.data :
{
*(.rtc.data)
*(.rtc.rodata)
/* Whatever is left from the RTC memory is used as a special heap. */
. = ALIGN (4);
_srtcheap = ABSOLUTE(.);
} > rtc_slow_seg
}
@@ -0,0 +1,121 @@
/****************************************************************************
* boards/xtensa/esp32/common/scripts/esp32.template.ld
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* ESP32 Linker Script Memory Layout
*
* This file describes the memory layout (memory blocks) as virtual
* memory addresses.
*
* esp32.ld contains output sections to link compiler output into these
* memory blocks.
*
* NOTE: That this is not the actual linker script but rather a "template"
* for the esp32_out.ld script. This template script is passed through
* the C preprocessor to include selected configuration options.
*
****************************************************************************/
/* config.h -- Autogenerated! Do not edit. */
/* Used to represent the values of tristate options */
/* General Definitions ***********************************/
/* Sanity Checks *****************************************/
/* If the end of RAM is not specified then it is assumed to be
* the beginning of RAM plus the RAM size.
*/
/* If the end of FLASH is not specified then it is assumed to be
* the beginning of FLASH plus the FLASH size.
*/
/****************************************************************************
* boards/xtensa/esp32/common/scripts/esp32_aliases.ld
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/* config.h -- Autogenerated! Do not edit. */
/* Lower-case aliases for symbols not compliant to nxstyle */
/* Bluetooth needs symbol alias, to be removed after IDF rename it */
MEMORY
{
/* Below values assume the flash cache is on, and have the blocks this
* uses subtracted from the length of the various regions. The 'data access
* port' dram/drom regions map to the same iram/irom regions but are
* connected to the data port of the CPU and e.g. allow bytewise access.
*/
/* IRAM for PRO cpu. Not sure if happy with this, this is MMU area... */
iram0_0_seg (RX) : org = 0x40080000, len = 0x20000
/* Flash mapped instruction data. */
/* The 0x20 offset is a convenience for the app binary image generation.
* Flash cache has 64KB pages. The .bin file which is flashed to the chip
* has a 0x18 byte file header, and each segment has a 0x08 byte segment
* header. Setting this offset makes it simple to meet the flash cache MMU's
* constraint that (paddr % 64KB == vaddr % 64KB).
*/
irom0_0_seg (RX) : org = 0x400d0020, len = 0x330000 - 0x20
/* Shared data RAM, excluding memory reserved for ROM bss/data/stack.
* Enabling Bluetooth & Trace Memory features in menuconfig will decrease
* the amount of RAM available.
*
* Note: The length of this section should be 0x50000, and this extra
* DRAM is available in heap at runtime. However due to static ROM memory
* usage at this 176KB mark, the additional static memory temporarily cannot
* be used.
*/
dram0_0_seg (RW) : org = 0x3ffb0000 + 0,
len = 0x2c200 - 0 - 0
/* Flash mapped constant data */
/* The 0x20 offset is a convenience for the app binary image generation.
* Flash cache has 64KB pages. The .bin file which is flashed to the chip
* has a 0x18 byte file header, and each segment has a 0x08 byte segment
* header. Setting this offset makes it simple to meet the flash cache MMU's
* constraint that (paddr % 64KB == vaddr % 64KB).
*/
drom0_0_seg (R) : org = 0x3f400020, len = 0x400000 - 0x20
/* RTC fast memory (executable). Persists over deep sleep. */
rtc_iram_seg (RWX) : org = 0x400c0000, len = 0x2000
/* RTC slow memory (data accessible). Persists over deep sleep.
* Start of RTC slow memory is reserved for ULP co-processor code + data,
* if enabled.
*/
rtc_slow_seg (RW) : org = 0x50000000 + 0,
len = 0x1000 - 0
/* External memory, including data and text */
extmem_seg (RWX) : org = 0x3f800000, len = 0x400000
}
REGION_ALIAS("default_rodata_seg", drom0_0_seg);
REGION_ALIAS("default_code_seg", irom0_0_seg);
/* Heap ends at top of dram0_0_seg */
_eheap = 0x40000000 - 0;
/* IRAM heap ends at top of dram0_0_seg */
_eiramheap = 0x400a0000;
/* Mark the end of the RTC heap (top of the RTC region) */
_ertcheap = 0x50001fff;
EXTERN(board_get_manifest)
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,78 @@
/****************************************************************************
* boards/xtensa/esp32/common/scripts/esp32.ld
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/* Default entry point: */
MEMORY
{
/* Below values assume the flash cache is on, and have the blocks this
* uses subtracted from the length of the various regions. The 'data access
* port' dram/drom regions map to the same iram/irom regions but are
* connected to the data port of the CPU and e.g. allow bytewise access.
*/
/* IRAM for PRO cpu. Not sure if happy with this, this is MMU area... */
iram0_0_seg (RX) : org = 0x40080000, len = 0x20000
/* Flash mapped instruction data. */
/* The 0x20 offset is a convenience for the app binary image generation.
* Flash cache has 64KB pages. The .bin file which is flashed to the chip
* has a 0x18 byte file header, and each segment has a 0x08 byte segment
* header. Setting this offset makes it simple to meet the flash cache MMU's
* constraint that (paddr % 64KB == vaddr % 64KB).
*/
irom0_0_seg (RX) : org = 0x400d0020, len = 0x330000 - 0x20
/* Shared data RAM, excluding memory reserved for ROM bss/data/stack.
* Enabling Bluetooth & Trace Memory features in menuconfig will decrease
* the amount of RAM available.
*
* Note: The length of this section should be 0x50000, and this extra
* DRAM is available in heap at runtime. However due to static ROM memory
* usage at this 176KB mark, the additional static memory temporarily cannot
* be used.
*/
dram0_0_seg (RW) : org = 0x3ffb0000 + 0,
len = 0x2c200 - 0 - 0
/* Flash mapped constant data */
/* The 0x20 offset is a convenience for the app binary image generation.
* Flash cache has 64KB pages. The .bin file which is flashed to the chip
* has a 0x18 byte file header, and each segment has a 0x08 byte segment
* header. Setting this offset makes it simple to meet the flash cache MMU's
* constraint that (paddr % 64KB == vaddr % 64KB).
*/
drom0_0_seg (R) : org = 0x3f400020, len = 0x400000 - 0x20
/* RTC fast memory (executable). Persists over deep sleep. */
rtc_iram_seg (RWX) : org = 0x400c0000, len = 0x2000
/* RTC slow memory (data accessible). Persists over deep sleep.
* Start of RTC slow memory is reserved for ULP co-processor code + data,
* if enabled.
*/
rtc_slow_seg (RW) : org = 0x50000000 + 0,
len = 0x1000 - 0
/* External memory, including data and text */
extmem_seg (RWX) : org = 0x3f800000, len = 0x400000
}
REGION_ALIAS("default_rodata_seg", drom0_0_seg);
REGION_ALIAS("default_code_seg", irom0_0_seg);
/* Heap ends at top of dram0_0_seg */
_eheap = 0x40000000 - 0;
/* IRAM heap ends at top of dram0_0_seg */
_eiramheap = 0x400a0000;
/* Mark the end of the RTC heap (top of the RTC region) */
_ertcheap = 0x50001fff;
@@ -0,0 +1,72 @@
############################################################################
# boards/xtensa/esp32/esp32-devkitc/scripts/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
include $(TOPDIR)/.config
include $(TOPDIR)/tools/Config.mk
include $(TOPDIR)/tools/esp32/Config.mk
include $(TOPDIR)/arch/xtensa/src/lx6/Toolchain.defs
ARCHSCRIPT += $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32_rom.ld
# Pick the linker scripts from the board level if they exist, if not
# pick the common linker scripts.
ifeq ($(CONFIG_BUILD_PROTECTED),y)
ARCHSCRIPT += $(call FINDSCRIPT,protected_memory.ld)
ARCHSCRIPT += $(call FINDSCRIPT,kernel-space.ld)
else
ARCHSCRIPT += $(call FINDSCRIPT,flat_memory.ld)
ifeq ($(CONFIG_ESP32_APP_FORMAT_MCUBOOT),y)
ARCHSCRIPT += $(call FINDSCRIPT,mcuboot_sections.ld)
else
ARCHSCRIPT += $(call FINDSCRIPT,legacy_sections.ld)
endif
endif
ARCHPICFLAGS = -fpic
# if SPIRAM/PSRAM is used then we need to include a workaround
ifeq ($(CONFIG_ESP32_SPIRAM),y)
ARCHCFLAGS += -mfix-esp32-psram-cache-issue
endif
CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe
CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe
CXXPICFLAGS = $(ARCHPICFLAGS) $(CXXFLAGS)
CPPFLAGS := $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
AFLAGS := $(CFLAGS) -D__ASSEMBLY__
# Loadable module definitions
CMODULEFLAGS = $(CFLAGS) -mtext-section-literals
LDMODULEFLAGS = -r -e module_initialize
LDMODULEFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)/libs/libc/modlib/gnu-elf.ld)
# ELF module definitions
CELFFLAGS = $(CFLAGS) -mtext-section-literals
CXXELFFLAGS = $(CXXFLAGS) -mtext-section-literals
LDELFFLAGS = -r -e main
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)binfmt$(DELIM)libelf$(DELIM)gnu-elf.ld)
+54
View File
@@ -0,0 +1,54 @@
############################################################################
#
# Copyright (c) 2021 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 PX4 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.
#
############################################################################
add_library(drivers_board
i2c.cpp
init.c
led.c
spi.cpp
timer_config.cpp
# usb.c
esp32_board_spiflash.c
esp32_board_wlan_setup.c
mtd.cpp
)
target_link_libraries(drivers_board
PRIVATE
arch_io_pins
arch_spi
drivers__led # drv_led_start
nuttx_arch # sdio
nuttx_drivers # sdio
px4_layer
)
+120
View File
@@ -0,0 +1,120 @@
/****************************************************************************
*
* Copyright (c) 2021 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 PX4 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 board_config.h
*
* board internal definitions
*/
#pragma once
/****************************************************************************************************
* Included Files
****************************************************************************************************/
#include <px4_platform_common/px4_config.h>
#include <nuttx/compiler.h>
#include <stdint.h>
/* LEDs */
#define GPIO_LED_BLUE 4 | GPIO_OUTPUT
/* GPIOs available*/
#define GPIO_1 4 | GPIO_OUTPUT
#define GPIO_2 4 | GPIO_OUTPUT
#define GPIO_3 4 | GPIO_OUTPUT
#define GPIO_4 4 | GPIO_OUTPUT
#define PX4_NUMBER_I2C_BUSES 2
#define BOARD_SPI_BUS_MAX_BUS_ITEMS 2
/*
* ADC channels
*
* These are the channel numbers of the ADCs of the microcontroller that can be used by the Px4 Firmware in the adc driver
*/
#define ADC_CHANNELS (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) // Change this later based on the adc channels actually used
#define ADC_BATTERY_VOLTAGE_CHANNEL 1 // Corresponding GPIO 27. Used in init.c for disabling GPIO_IE
#define ADC_BATTERY_CURRENT_CHANNEL 2 // Corresponding GPIO 28. Used in init.c for disabling GPIO_IE
#define ADC_RC_RSSI_CHANNEL 0
/* High-resolution timer */
/*
* For wifi to work, it needs to use its own timer.
* Make sure you are not using the timer for hrt
* that is being using for the wifi
*/
#define HRT_TIMER 2
/* This board provides a DMA pool and APIs */ // Needs to be figured out
#define BOARD_DMA_ALLOC_POOL_SIZE 2048
#define BOARD_ENABLE_CONSOLE_BUFFER
#define BOARD_CONSOLE_BUFFER_SIZE (1024*3)
/* PWM
*/
#define DIRECT_PWM_OUTPUT_CHANNELS 4
// Has pwm outputs
#define BOARD_HAS_PWM DIRECT_PWM_OUTPUT_CHANNELS
// #define BOARD_ADC_USB_CONNECTED (px4_arch_gpioread(GPIO_USB_VBUS_VALID));
int esp32_spiflash_init(void);
int esp32_partition_init(void);
__BEGIN_DECLS
#ifndef __ASSEMBLY__
/****************************************************************************************************
* Name: rp2040_usbinitialize
*
* Description:
* Called to configure USB IO.
*
****************************************************************************************************/
extern void esp32_spiinitialize(void);
extern void board_peripheral_reset(int ms);
#include <px4_platform_common/board_common.h>
#endif /* __ASSEMBLY__ */
__END_DECLS
@@ -0,0 +1,574 @@
/****************************************************************************
* boards/xtensa/esp32/common/src/esp32_board_spiflash.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/fs/fs.h>
#include <nuttx/kmalloc.h>
#include <nuttx/mtd/mtd.h>
#include <nuttx/spi/spi.h>
#ifdef CONFIG_ESP32_SPIFLASH_NXFFS
#include <nuttx/fs/nxffs.h>
#endif
#ifdef CONFIG_BCH
#include <nuttx/drivers/drivers.h>
#endif
#include "esp32_spiflash.h"
#include "esp32_board_spiflash_setup.h"
// #define CONFIG_ESP32_SPIFLASH_SPIFFS
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
#ifdef CONFIG_ESP32_OTA_PARTITION_ENCRYPT
# define OTA_ENCRYPT true
#else
# define OTA_ENCRYPT false
#endif
#ifdef CONFIG_ESP32_WIFI_MTD_ENCRYPT
# define WIFI_ENCRYPT true
#else
# define WIFI_ENCRYPT false
#endif
#ifdef CONFIG_ESP32_STORAGE_MTD_ENCRYPT
# define STORAGE_ENCRYPT true
#else
# define STORAGE_ENCRYPT false
#endif
/****************************************************************************
* Private Types
****************************************************************************/
#ifdef CONFIG_ESP32_HAVE_OTA_PARTITION
struct ota_partition_s {
uint32_t offset; /* Partition offset from the beginning of MTD */
uint32_t size; /* Partition size in bytes */
const char *devpath; /* Partition device path */
};
#endif
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
#ifdef CONFIG_ESP32_HAVE_OTA_PARTITION
static int init_ota_partitions(void);
#endif
/****************************************************************************
* Private Data
****************************************************************************/
#ifdef CONFIG_ESP32_HAVE_OTA_PARTITION
static const struct ota_partition_s g_ota_partition_table[] = {
{
.offset = CONFIG_ESP32_OTA_PRIMARY_SLOT_OFFSET,
.size = CONFIG_ESP32_OTA_SLOT_SIZE,
.devpath = CONFIG_ESP32_OTA_PRIMARY_SLOT_DEVPATH
},
{
.offset = CONFIG_ESP32_OTA_SECONDARY_SLOT_OFFSET,
.size = CONFIG_ESP32_OTA_SLOT_SIZE,
.devpath = CONFIG_ESP32_OTA_SECONDARY_SLOT_DEVPATH
},
{
.offset = CONFIG_ESP32_OTA_SCRATCH_OFFSET,
.size = CONFIG_ESP32_OTA_SCRATCH_SIZE,
.devpath = CONFIG_ESP32_OTA_SCRATCH_DEVPATH
}
};
#endif
/****************************************************************************
* Private Functions
****************************************************************************/
#ifdef CONFIG_ESP32_HAVE_OTA_PARTITION
static int init_ota_partitions(void)
{
struct mtd_dev_s *mtd;
#ifdef CONFIG_BCH
char blockdev[18];
#endif
int ret = OK;
for (int i = 0; i < ARRAYSIZE(g_ota_partition_table); ++i) {
const struct ota_partition_s *part = &g_ota_partition_table[i];
mtd = esp32_spiflash_alloc_mtdpart(part->offset, part->size,
OTA_ENCRYPT);
ret = ftl_initialize(i, mtd);
if (ret < 0) {
ferr("ERROR: Failed to initialize the FTL layer: %d\n", ret);
return ret;
}
#ifdef CONFIG_BCH
snprintf(blockdev, sizeof(blockdev), "/dev/mtdblock%d", i);
ret = bchdev_register(blockdev, part->devpath, false);
if (ret < 0) {
ferr("ERROR: bchdev_register %s failed: %d\n", part->devpath, ret);
return ret;
}
#endif
}
return ret;
}
#endif
/****************************************************************************
* Name: setup_smartfs
*
* Description:
* Provide a block driver wrapper around MTD partition and mount a
* SMART FS over it.
*
* Parameters:
* smartn - Number used to register the mtd partition: /dev/smartx, where
* x = smartn.
* mtd - Pointer to a pre-allocated mtd partition.
* mnt_pt - Mount point
*
* Returned Value:
* Zero on success; a negated errno value on failure.
*
****************************************************************************/
#ifdef CONFIG_ESP32_SPIFLASH_SMARTFS
static int setup_smartfs(int smartn, struct mtd_dev_s *mtd,
const char *mnt_pt)
{
int ret = OK;
char path[22];
ret = smart_initialize(smartn, mtd, NULL);
if (ret < 0) {
finfo("smart_initialize failed, Trying to erase first...\n");
ret = mtd->ioctl(mtd, MTDIOC_BULKERASE, 0);
if (ret < 0) {
ferr("ERROR: ioctl(BULKERASE) failed: %d\n", ret);
return ret;
}
finfo("Erase successful, initializing it again.\n");
ret = smart_initialize(smartn, mtd, NULL);
if (ret < 0) {
ferr("ERROR: smart_initialize failed: %d\n", ret);
return ret;
}
}
if (mnt_pt != NULL) {
snprintf(path, sizeof(path), "/dev/smart%d", smartn);
ret = nx_mount(path, mnt_pt, "smartfs", 0, NULL);
if (ret < 0) {
ferr("ERROR: Failed to mount the FS volume: %d\n", ret);
return ret;
}
}
return ret;
}
#endif
/****************************************************************************
* Name: setup_littlefs
*
* Description:
* Register a mtd driver and mount a Little FS over it.
*
* Parameters:
* path - Path name used to register the mtd driver.
* mtd - Pointer to a pre-allocated mtd partition.
* mnt_pt - Mount point
* priv - Privileges
*
* Returned Value:
* Zero on success; a negated errno value on failure.
*
****************************************************************************/
#ifdef CONFIG_ESP32_SPIFLASH_LITTLEFS
static int setup_littlefs(const char *path, struct mtd_dev_s *mtd,
const char *mnt_pt, int priv)
{
int ret = OK;
ret = register_mtddriver(path, mtd, priv, NULL);
if (ret < 0) {
ferr("ERROR: Failed to register MTD: %d\n", ret);
return -ENOMEM;
}
if (mnt_pt != NULL) {
ret = nx_mount(path, mnt_pt, "littlefs", 0, NULL);
if (ret < 0) {
ret = nx_mount(path, mnt_pt, "littlefs", 0, "forceformat");
if (ret < 0) {
ferr("ERROR: Failed to mount the FS volume: %d\n", ret);
return ret;
}
}
}
return OK;
}
#endif
/****************************************************************************
* Name: setup_spiffs
*
* Description:
* Register a mtd driver and mount a SPIFFS over it.
*
* Parameters:
* path - Path name used to register the mtd driver.
* mtd - Pointer to a pre-allocated mtd partition.
* mnt_pt - Mount point
* priv - Privileges
*
* Returned Value:
* Zero on success; a negated errno value on failure.
*
****************************************************************************/
#ifdef CONFIG_ESP32_SPIFLASH_SPIFFS
static int setup_spiffs(const char *path, struct mtd_dev_s *mtd,
const char *mnt_pt, int priv)
{
int ret = OK;
ret = register_mtddriver(path, mtd, priv, NULL);
if (ret < 0) {
ferr("ERROR: Failed to register MTD: %d\n", ret);
return -ENOMEM;
}
if (mnt_pt != NULL) {
ret = nx_mount(path, mnt_pt, "spiffs", 0, NULL);
if (ret < 0) {
ferr("ERROR: Failed to mount the FS volume: %d\n", ret);
return ret;
}
}
return ret;
}
#endif
/****************************************************************************
* Name: setup_nxffs
*
* Description:
* Register a mtd driver and mount a SPIFFS over it.
*
* Parameters:
* mtd - Pointer to a pre-allocated mtd partition.
* mnt_pt - Mount point
*
* Returned Value:
* Zero on success; a negated errno value on failure.
*
****************************************************************************/
#ifdef CONFIG_ESP32_SPIFLASH_NXFFS
static int setup_nxffs(struct mtd_dev_s *mtd, const char *mnt_pt)
{
int ret = OK;
ret = nxffs_initialize(mtd);
if (ret < 0) {
ferr("ERROR: NXFFS init failed: %d\n", ret);
return ret;
}
if (mnt_pt != NULL) {
ret = nx_mount(NULL, mnt_pt, "nxffs", 0, NULL);
if (ret < 0) {
ferr("ERROR: Failed to mount the FS volume: %d\n", ret);
return ret;
}
}
return ret;
}
#endif
/****************************************************************************
* Name: init_wifi_partition
*
* Description:
* Initialize partition that is dedicated to Wi-Fi.
*
* Returned Value:
* Zero on success; a negated errno value on failure.
*
****************************************************************************/
#ifdef CONFIG_ESP32_WIFI_SAVE_PARAM
static int init_wifi_partition(void)
{
int ret = OK;
struct mtd_dev_s *mtd;
mtd = esp32_spiflash_alloc_mtdpart(CONFIG_ESP32_WIFI_MTD_OFFSET,
CONFIG_ESP32_WIFI_MTD_SIZE,
WIFI_ENCRYPT);
if (!mtd) {
ferr("ERROR: Failed to alloc MTD partition of SPI Flash\n");
return -ENOMEM;
}
#ifdef CONFIG_ESP32_SPIFLASH_SMARTFS
ret = setup_smartfs(1, mtd, CONFIG_ESP32_WIFI_FS_MOUNTPT);
if (ret < 0) {
ferr("ERROR: Failed to setup smartfs\n");
return ret;
}
#elif defined(CONFIG_ESP32_SPIFLASH_LITTLEFS)
const char *path = "/dev/mtdblock1";
ret = setup_littlefs(path, mtd, CONFIG_ESP32_WIFI_FS_MOUNTPT, 0777);
if (ret < 0) {
ferr("ERROR: Failed to setup littlefs\n");
return ret;
}
#elif defined(CONFIG_ESP32_SPIFLASH_SPIFFS)
const char *path = "/dev/mtdblock1";
ret = setup_spiffs(path, mtd, CONFIG_ESP32_WIFI_FS_MOUNTPT, 0777);
if (ret < 0) {
ferr("ERROR: Failed to setup spiffs\n");
return ret;
}
#else
ferr("ERROR: No supported FS selected. Wi-Fi partition "
"should be mounted before Wi-Fi initialization\n");
#endif
return ret;
}
#endif
/****************************************************************************
* Name: init_storage_partition
*
* Description:
* Initialize partition that is dedicated to general use.
*
* Returned Value:
* Zero on success; a negated errno value on failure.
*
****************************************************************************/
static int init_storage_partition(void)
{
int ret = OK;
struct mtd_dev_s *mtd;
mtd = esp32_spiflash_alloc_mtdpart(CONFIG_ESP32_STORAGE_MTD_OFFSET,
CONFIG_ESP32_STORAGE_MTD_SIZE,
STORAGE_ENCRYPT);
if (!mtd) {
ferr("ERROR: Failed to alloc MTD partition of SPI Flash\n");
return -ENOMEM;
}
#ifdef CONFIG_ESP32_SPIFLASH_SMARTFS
ret = setup_smartfs(0, mtd, NULL);
if (ret < 0) {
ferr("ERROR: Failed to setup smartfs\n");
return ret;
}
#elif defined(CONFIG_ESP32_SPIFLASH_NXFFS)
ret = setup_nxffs(mtd, "/mnt");
if (ret < 0) {
ferr("ERROR: Failed to setup nxffs\n");
return ret;
}
#elif defined(CONFIG_ESP32_SPIFLASH_LITTLEFS)
const char *path = "/dev/esp32flash";
ret = setup_littlefs(path, mtd, NULL, 0755);
if (ret < 0) {
ferr("ERROR: Failed to setup littlefs\n");
return ret;
}
#elif defined(CONFIG_ESP32_SPIFLASH_SPIFFS)
const char *path = "/dev/esp32flash";
ret = setup_spiffs(path, mtd, NULL, 0755);
if (ret < 0) {
ferr("ERROR: Failed to setup spiffs\n");
return ret;
}
#else
ret = register_mtddriver("/dev/esp32flash", mtd, 0755, NULL);
if (ret < 0) {
ferr("ERROR: Failed to register MTD: %d\n", ret);
return ret;
}
#endif
return ret;
}
#define CONFIG_ESP32_PARAM_MTD_OFFSET 0x330000
#define CONFIG_ESP32_PARAM_MTD_SIZE 0x10000
static int init_param_partition(void)
{
int ret = OK;
struct mtd_dev_s *mtd;
mtd = esp32_spiflash_alloc_mtdpart(CONFIG_ESP32_PARAM_MTD_OFFSET,
CONFIG_ESP32_PARAM_MTD_SIZE,
STORAGE_ENCRYPT);
if (!mtd) {
ferr("ERROR: Failed to alloc PARAM MTD partition of SPI Flash\n");
return -ENOMEM;
}
ret = register_mtddriver("/fs/mtd_params", mtd, 0755, NULL);
if (ret < 0) {
ferr("ERROR: Failed to register PARAM MTD: %d\n", ret);
return ret;
}
return ret;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: esp32_spiflash_init
*
* Description:
* Initialize the SPI Flash and register the MTD.
*
* Input Parameters:
* None.
*
* Returned Value:
* Zero (OK) is returned on success. A negated errno value is returned
* on failure.
*
****************************************************************************/
int esp32_spiflash_init(void)
{
int ret = OK;
#ifdef CONFIG_ESP32_HAVE_OTA_PARTITION
ret = init_ota_partitions();
if (ret < 0) {
return ret;
}
#endif
#ifdef CONFIG_ESP32_WIFI_SAVE_PARAM
ret = init_wifi_partition();
if (ret < 0) {
return ret;
}
#endif
ret = init_storage_partition();
if (ret < 0) {
return ret;
}
ret = init_param_partition();
if (ret < 0) {
return ret;
}
return ret;
}
@@ -0,0 +1,353 @@
/****************************************************************************
* boards/xtensa/esp32/common/src/esp32_board_spiflash.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/fs/fs.h>
#include <nuttx/kmalloc.h>
#include <nuttx/mtd/mtd.h>
#include <nuttx/spi/spi.h>
#ifdef CONFIG_ESP32_SPIFLASH_NXFFS
#include <nuttx/fs/nxffs.h>
#endif
#ifdef CONFIG_BCH
#include <nuttx/drivers/drivers.h>
#endif
#include <px4_platform_common/log.h>
#define MODULE_NAME "spiflash"
#include "esp32_spiflash.h"
#include "esp32_partition.h"
// #include "esp32_board_spiflash_setup.h"
#include "board_config.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
#ifdef CONFIG_ESP32_OTA_PARTITION_ENCRYPT
# define OTA_ENCRYPT true
#else
# define OTA_ENCRYPT false
#endif
#ifdef CONFIG_ESP32_WIFI_MTD_ENCRYPT
# define WIFI_ENCRYPT true
#else
# define WIFI_ENCRYPT false
#endif
#ifdef CONFIG_ESP32_STORAGE_MTD_ENCRYPT
# define STORAGE_ENCRYPT true
#else
# define STORAGE_ENCRYPT false
#endif
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
int esp32_spiflash_init(void);
int esp32_partition_init(void);
static int init_ota_partitions(void)
{
struct mtd_dev_s *mtd;
char blockdev[18];
int ret = OK;
mtd = esp32_spiflash_alloc_mtdpart(CONFIG_ESP32_STORAGE_MTD_OFFSET, CONFIG_ESP32_STORAGE_MTD_SIZE, false);
ret = ftl_initialize(0, mtd);
if (ret < 0) {
PX4_INFO("ERROR: Failed to initialize the FTL layer: %d\n", ret);
return ret;
}
snprintf(blockdev, sizeof(blockdev), "/dev/mtdblock%d", 0);
ret = bchdev_register(blockdev, "/fs/mtd_params", false);
if (ret < 0) {
PX4_INFO("ERROR: bchdev_register %s failed: %d\n", "/fs/mtd_params", ret);
return ret;
}
return ret;
}
/****************************************************************************
* Name: setup_smartfs
*
* Description:
* Provide a block driver wrapper around MTD partition and mount a
* SMART FS over it.
*
* Parameters:
* smartn - Number used to register the mtd partition: /dev/smartx, where
* x = smartn.
* mtd - Pointer to a pre-allocated mtd partition.
* mnt_pt - Mount point
*
* Returned Value:
* Zero on success; a negated errno value on failure.
*
****************************************************************************/
/****************************************************************************
* Name: setup_littlefs
*
* Description:
* Register a mtd driver and mount a Little FS over it.
*
* Parameters:
* path - Path name used to register the mtd driver.
* mtd - Pointer to a pre-allocated mtd partition.
* mnt_pt - Mount point
* priv - Privileges
*
* Returned Value:
* Zero on success; a negated errno value on failure.
*
****************************************************************************/
static int setup_littlefs(const char *path, struct mtd_dev_s *mtd,
const char *mnt_pt, int priv)
{
int ret = OK;
ret = register_mtddriver(path, mtd, priv, NULL);
if (ret < 0) {
PX4_INFO("ERROR: Failed to register MTD: %d\n", ret);
return -ENOMEM;
}
// if (mnt_pt != NULL)
// {
// ret = nx_mount(path, "/mnt/lfs", "littlefs", 0, "");
// if (ret < 0)
// {
// ret = nx_mount(path, "/fs/lfs", "littlefs", 0, "forceformat");
// if (ret < 0)
// {
// PX4_INFO("ERROR: Failed to mount the FS volume: %d\n", ret);
// return ret;
// }
// }
// }
return OK;
}
/****************************************************************************
* Name: setup_spiffs
*
* Description:
* Register a mtd driver and mount a SPIFFS over it.
*
* Parameters:
* path - Path name used to register the mtd driver.
* mtd - Pointer to a pre-allocated mtd partition.
* mnt_pt - Mount point
* priv - Privileges
*
* Returned Value:
* Zero on success; a negated errno value on failure.
*
****************************************************************************/
static int setup_spiffs(const char *path, struct mtd_dev_s *mtd,
const char *mnt_pt, int priv)
{
int ret = OK;
ret = register_mtddriver(path, mtd, priv, NULL);
if (ret < 0) {
ferr("ERROR: Failed to register MTD: %d\n", ret);
return -ENOMEM;
}
if (mnt_pt != NULL) {
ret = nx_mount(path, mnt_pt, "spiffs", 0, NULL);
if (ret < 0) {
ferr("ERROR: Failed to mount the FS volume: %d\n", ret);
return ret;
}
}
return ret;
}
/****************************************************************************
* Name: setup_nxffs
*
* Description:
* Register a mtd driver and mount a SPIFFS over it.
*
* Parameters:
* mtd - Pointer to a pre-allocated mtd partition.
* mnt_pt - Mount point
*
* Returned Value:
* Zero on success; a negated errno value on failure.
*
****************************************************************************/
#ifdef CONFIG_ESP32_SPIFLASH_NXFFS
static int setup_nxffs(struct mtd_dev_s *mtd, const char *mnt_pt)
{
int ret = OK;
ret = nxffs_initialize(mtd);
if (ret < 0) {
ferr("ERROR: NXFFS init failed: %d\n", ret);
return ret;
}
if (mnt_pt != NULL) {
ret = nx_mount(NULL, mnt_pt, "nxffs", 0, NULL);
if (ret < 0) {
ferr("ERROR: Failed to mount the FS volume: %d\n", ret);
return ret;
}
}
return ret;
}
#endif
/****************************************************************************
* Name: init_storage_partition
*
* Description:
* Initialize partition that is dedicated to general use.
*
* Returned Value:
* Zero on success; a negated errno value on failure.
*
****************************************************************************/
static int init_storage_partition(void)
{
int ret = OK;
struct mtd_dev_s *mtd;
mtd = esp32_spiflash_alloc_mtdpart(CONFIG_ESP32_STORAGE_MTD_OFFSET,
CONFIG_ESP32_STORAGE_MTD_SIZE,
STORAGE_ENCRYPT);
if (!mtd) {
PX4_INFO("ERROR: Failed to alloc MTD partition of SPI Flash\n");
return -ENOMEM;
}
const char *path = "/dev/esp32flash";
ret = setup_littlefs(path, mtd, "/mnt/esp32", 0755);
if (ret < 0) {
PX4_INFO("ERROR: Failed to setup littlefs\n");
return ret;
}
// const char *path = "/dev/esp32flash";
// ret = setup_spiffs(path, mtd, "/mnt/spiffs/", 0755);
// if (ret < 0)
// {
// ferr("ERROR: Failed to setup spiffs\n");
// return ret;
// }
return ret;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: esp32_spiflash_init
*
* Description:
* Initialize the SPI Flash and register the MTD.
*
* Input Parameters:
* None.
*
* Returned Value:
* Zero (OK) is returned on success. A negated errno value is returned
* on failure.
*
****************************************************************************/
int esp32_spiflash_init(void)
{
int ret = OK;
ret = init_ota_partitions();
PX4_INFO("ret = %d = init_ota_paritions()\n", ret);
if (ret < 0) {
return ret;
}
// ret = esp32_partition_init();
// if (ret < 0)
// {
// syslog(LOG_ERR, "ERROR: Failed to initialize partition error=%d\n",
// ret);
// }
//
// ret = init_storage_partition();
// PX4_INFO("ret = %d = init_storage_paritions()\n", ret);
// if (ret < 0)
// {
// return ret;
// }
return ret;
}
@@ -0,0 +1,68 @@
/****************************************************************************
* boards/xtensa/esp32/common/include/esp32_board_spiflash.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_ESP32_BOARD_SPIFLASH_H
#define __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_ESP32_BOARD_SPIFLASH_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#ifndef __ASSEMBLY__
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: esp32_spiflash_init
*
* Description:
* Initialize the SPI Flash and register the MTD.
*
* Input Parameters:
* None.
*
* Returned Value:
* Zero (OK) is returned on success. A negated errno value is returned
* on failure.
*
****************************************************************************/
int esp32_spiflash_init(void);
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* __ASSEMBLY__ */
#endif /* __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_ESP32_BOARD_SPIFLASH_H */
@@ -0,0 +1,91 @@
/****************************************************************************
* boards/xtensa/esp32/common/src/esp32_board_wlan.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <syslog.h>
#include <debug.h>
#include <nuttx/wireless/wireless.h>
#include "esp32_spiflash.h"
#include "esp32_wlan.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_wlan_init
*
* Description:
* Configure the wireless subsystem.
*
* Returned Value:
* Zero (OK) is returned on success; A negated errno value is returned
* to indicate the nature of any failure.
*
****************************************************************************/
int board_wlan_init(void)
{
int ret = OK;
#ifdef ESP32_WLAN_HAS_STA
// ret = esp32_wlan_sta_initialize();
// if (ret)
// {
// printf("ERROR: Failed to initialize Wi-Fi station\n");
// return ret;
// }
#endif
#ifdef ESP32_WLAN_HAS_SOFTAP
ret = esp32_wlan_softap_initialize();
if (ret) {
wlerr("ERROR: Failed to initialize Wi-Fi softAP\n");
return ret;
}
#endif
// netlib_ifup("wlan1");
// dhcpd_start("wlan1");
return ret;
}
@@ -0,0 +1,73 @@
/****************************************************************************
* boards/xtensa/esp32/common/include/esp32_board_wlan.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_ESP32_BOARD_WLAN_H
#define __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_ESP32_BOARD_WLAN_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#ifndef __ASSEMBLY__
/****************************************************************************
* Public Data
****************************************************************************/
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#ifdef CONFIG_ESP32_WIRELESS
/****************************************************************************
* Name: board_wlan_init
*
* Description:
* Configure the wireless subsystem.
*
* Returned Value:
* Zero (OK) is returned on success; A negated errno value is returned
* to indicate the nature of any failure.
*
****************************************************************************/
int board_wlan_init(void);
#endif /* CONFIG_ESP32_WIRELESS */
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* __ASSEMBLY__ */
#endif /* __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_ESP32_BOARD_WLAN_H */
+38
View File
@@ -0,0 +1,38 @@
/****************************************************************************
*
* Copyright (C) 2021 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 PX4 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.
*
****************************************************************************/
#include <px4_arch/i2c_hw_description.h>
constexpr px4_i2c_bus_t px4_i2c_buses[I2C_BUS_MAX_BUS_ITEMS] = {
initI2CBusInternal(1),
};
+300
View File
@@ -0,0 +1,300 @@
/****************************************************************************
*
* Copyright (c) 2021 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 PX4 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 init.c
*
* board specific early startup code. This file implements the
* board_app_initialize() function that is called early by nsh during startup.
*
* Code here is run before the rcS script is invoked; it should start required
* subsystems and perform board-specific initialization.
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <px4_platform_common/px4_config.h>
#include <px4_platform_common/tasks.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <debug.h>
#include <errno.h>
#include <syslog.h>
#include <nuttx/board.h>
#include <nuttx/spi/spi.h>
#include <nuttx/i2c/i2c_master.h>
#include <nuttx/analog/adc.h>
#include <nuttx/sdio.h>
#include <nuttx/mmcsd.h>
#include <nuttx/mm/gran.h>
#include <chip.h>
#include "board_config.h"
#include <arch/board/board.h>
#include <px4_platform_common/px4_manifest.h>
#include <drivers/drv_hrt.h>
#include <drivers/drv_board_led.h>
#include <systemlib/px4_macros.h>
#include <px4_arch/io_timer.h>
#include <px4_platform_common/init.h>
#include <px4_platform/board_dma_alloc.h>
#define LEDC_LS_SIG_OUT0_IDX 79
#include "esp32_board_wlan_setup.h"
#ifdef CONFIG_ESP32_SPIFLASH
#include "esp32_board_spiflash_setup.h"
#endif
#include "esp32_rt_timer.h"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/**
* Ideally we'd be able to get these from arm_internal.h,
* but since we want to be able to disable the NuttX use
* of leds for system indication at will and there is no
* separate switch, we need to build independent of the
* CONFIG_ARCH_LEDS configuration switch.
*/
__BEGIN_DECLS
extern void led_init(void);
extern void led_on(int led);
extern void led_off(int led);
__END_DECLS
/****************************************************************************
* Protected Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/************************************************************************************
* Name: board_peripheral_reset
*
* Description:
*
************************************************************************************/
__EXPORT void board_peripheral_reset(int ms)
{
UNUSED(ms);
}
/************************************************************************************
* Name: board_on_reset
*
* Description:
* Optionally provided function called on entry to board_system_reset
* It should perform any house keeping prior to the rest.
*
* status - 1 if resetting to boot loader
* 0 if just resetting
*
************************************************************************************/
__EXPORT void board_on_reset(int status)
{
// Configure the GPIO pins to outputs and keep them low.
for (int i = 0; i < DIRECT_PWM_OUTPUT_CHANNELS; ++i) {
px4_arch_configgpio(io_timer_channel_get_gpio_output(i));
esp32_gpio_matrix_out(timer_io_channels[i].gpio_out, LEDC_LS_SIG_OUT0_IDX + timer_io_channels[i].timer_channel, 0, 0);
}
/*
* On resets invoked from system (not boot) insure we establish a low
* output state (discharge the pins) on PWM pins before they become inputs.
*/
if (status >= 0) {
up_mdelay(400);
}
}
/************************************************************************************
* Name: board_read_VBUS_state
*
* Description:
* All boards must provide a way to read the state of VBUS, this my be simple
* digital input on a GPIO. Or something more complicated like a Analong input
* or reading a bit from a USB controller register.
*
* Returns - 0 if connected.
*
************************************************************************************/
int board_read_VBUS_state(void)
{
// return BOARD_ADC_USB_CONNECTED ? 0 : 1;
return 0;
}
/************************************************************************************
* Name: esp32_board_initialize
*
* Description:
* All architectures must provide the following entry point. This entry point
* is called early in the initialization -- after all memory has been configured
* and mapped but before any devices have been initialized.
*
************************************************************************************/
__EXPORT void
esp32_board_initialize(void)
{
// /* Reset all PWM to Low outputs */
board_on_reset(-1);
// /* configure LEDs */
board_autoled_initialize();
up_mdelay(2);
esp32_spiinitialize();
}
/****************************************************************************
* Name: board_app_initialize
*
* Description:
* Perform application specific initialization. This function is never
* called directly from application code, but only indirectly via the
* (non-standard) boardctl() interface using the command BOARDIOC_INIT.
*
* Input Parameters:
* arg - The boardctl() argument is passed to the board_app_initialize()
* implementation without modification. The argument has no
* meaning to NuttX; the meaning of the argument is a contract
* between the board-specific initalization logic and the the
* matching application logic. The value cold be such things as a
* mode enumeration value, a set of DIP switch switch settings, a
* pointer to configuration data read from a file or serial FLASH,
* or whatever you would like to do with it. Every implementation
* should accept zero/NULL as a default configuration.
*
* Returned Value:
* Zero (OK) is returned on success; a negated errno value is returned on
* any failure to indicate the nature of the failure.
*
****************************************************************************/
#ifdef CONFIG_ESP32_SPI2
static struct spi_dev_s *spi2;
#endif
#ifdef CONFIG_ESP32_SPI3
static struct spi_dev_s *spi3;
#endif
__EXPORT int board_app_initialize(uintptr_t arg)
{
px4_platform_init();
/* configure the DMA allocator */ // Needs to be figured out
if (board_dma_alloc_init() < 0) {
syslog(LOG_ERR, "DMA alloc FAILED\n");
}
/* initial LED state */
drv_led_start();
#ifdef CONFIG_ESP32_SPI2
spi2 = esp32_spibus_initialize(2);
if (!spi2) {
syslog(LOG_ERR, "[boot] FAILED to initialize SPI port 2\n");
// led_on(LED_RED);
}
// Default SPI1 to 10MHz
SPI_SETFREQUENCY(spi2, 10000000);
SPI_SETBITS(spi2, 8);
SPI_SETMODE(spi2, SPIDEV_MODE3);
up_udelay(20);
#endif
#ifdef CONFIG_ESP32_SPI3
spi3 = esp32_spibus_initialize(3);
if (!spi3) {
syslog(LOG_ERR, "[boot] FAILED to initialize SPI port 3\n");
// led_on(LED_RED);
}
/* Now bind the SPI interface to the MMCSD driver */
int result = mmcsd_spislotinitialize(CONFIG_NSH_MMCSDMINOR, CONFIG_NSH_MMCSDSLOTNO, spi3);
if (result != OK) {
syslog(LOG_ERR, "[boot] FAILED to bind SPI port 3 to the MMCSD driver\n");
}
#endif
int ret = esp32_spiflash_init();
if (ret) {
syslog(LOG_ERR, "ERROR: Failed to initialize SPI Flash\n");
}
esp32_rt_timer_init();
led_on(GPIO_LED_BLUE);
up_mdelay(100);
led_off(GPIO_LED_BLUE);
up_mdelay(100);
led_on(GPIO_LED_BLUE);
up_mdelay(100);
led_off(GPIO_LED_BLUE);
/* Configure the HW based on the manifest */
px4_platform_configure();
up_mdelay(1000);
board_wlan_init();
return OK;
}
+102
View File
@@ -0,0 +1,102 @@
/****************************************************************************
*
* Copyright (c) 2013 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 PX4 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 led.c
*
* PX4FMU LED backend.
*/
#include <px4_platform_common/px4_config.h>
#include <stdbool.h>
#include "board_config.h"
#include <arch/board/board.h>
/*
* Ideally we'd be able to get these from arm_internal.h,
* but since we want to be able to disable the NuttX use
* of leds for system indication at will and there is no
* separate switch, we need to build independent of the
* CONFIG_ARCH_LEDS configuration switch.
*/
__BEGIN_DECLS
extern void led_init(void);
extern void led_on(int led);
extern void led_off(int led);
extern void led_toggle(int led);
__END_DECLS
static uint32_t g_ledmap[] = {
GPIO_LED_BLUE, // Indexed by LED_BLUE
};
__EXPORT void led_init(void)
{
/* Configure LED GPIOs for output */
for (size_t l = 0; l < (sizeof(g_ledmap) / sizeof(g_ledmap[0])); l++) {
px4_arch_configgpio(g_ledmap[l]);
}
}
static void phy_set_led(int led, bool state)
{
/* Pull Down to switch on */
px4_arch_gpiowrite(g_ledmap[led], !state);
}
static bool phy_get_led(int led)
{
return !px4_arch_gpioread(g_ledmap[led]);
}
__EXPORT void led_on(int led)
{
phy_set_led(led, true);
}
__EXPORT void led_off(int led)
{
phy_set_led(led, false);
}
__EXPORT void led_toggle(int led)
{
phy_set_led(led, !phy_get_led(led));
}
+76
View File
@@ -0,0 +1,76 @@
/****************************************************************************
*
* Copyright (C) 2020 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 PX4 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.
*
****************************************************************************/
#include <nuttx/config.h>
#include <board_config.h>
#include <nuttx/spi/spi.h>
#include <px4_platform_common/px4_manifest.h>
// KiB BS nB
static const px4_mft_device_t flash = { // 24AA64FT on Base 8K 32 X 256
.bus_type = px4_mft_device_t::ONCHIP
};
static const px4_mtd_entry_t fmu_flash = {
.device = &flash,
.npart = 1,
.partd = {
{
.type = MTD_PARAMETERS,
.path = "/fs/mtd_params",
.nblocks = 1
}
},
};
static const px4_mtd_manifest_t board_mtd_config = {
.nconfigs = 1,
.entries = {
&fmu_flash,
}
};
static const px4_mft_entry_s mtd_mft = {
.type = MTD,
.pmft = (void *) &board_mtd_config,
};
static const px4_mft_s mft = {
.nmft = 1,
.mfts = {&mtd_mft}
};
const px4_mft_s *board_get_manifest(void)
{
return &mft;
}
+52
View File
@@ -0,0 +1,52 @@
/****************************************************************************
*
* Copyright (C) 2020 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 PX4 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.
*
****************************************************************************/
#include <px4_arch/spi_hw_description.h>
#include <drivers/drv_sensor.h>
#include <nuttx/spi/spi.h>
const constexpr px4_spi_bus_t px4_spi_buses[SPI_BUS_MAX_BUS_ITEMS] = {
#ifdef CONFIG_ESP32_SPI2
initSPIBus(SPI::Bus::SPI2, {
initSPIDevice(SPIDEV_FLASH(0), SPI::CS{GPIO::Pin(CONFIG_ESP32_SPI2_CSPIN)}),
}),
#endif
#ifdef CONFIG_ESP32_SPI3
initSPIBus(SPI::Bus::SPI3, {
initSPIDevice(SPIDEV_MMCSD(0), SPI::CS{GPIO::Pin(CONFIG_ESP32_SPI3_CSPIN)})
}),
#endif
};
static constexpr bool unused = validateSPIConfig(px4_spi_buses);
@@ -0,0 +1,48 @@
/****************************************************************************
*
* Copyright (C) 2021 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 PX4 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.
*
****************************************************************************/
#include <px4_arch/io_timer_hw_description.h>
constexpr io_timers_t io_timers[MAX_IO_TIMERS] = {
initIOTimer(Timer::Timer0), // this refers to LEDC periherals
};
constexpr timer_io_channels_t timer_io_channels[MAX_TIMER_IO_CHANNELS] = {
initIOTimerChannel(io_timers, {Timer::Timer0, Timer::Channel0}, {GPIO::Pin(CONFIG_ESP32_LEDC_CHANNEL0_PIN)}),
initIOTimerChannel(io_timers, {Timer::Timer0, Timer::Channel1}, {GPIO::Pin(CONFIG_ESP32_LEDC_CHANNEL1_PIN)}),
initIOTimerChannel(io_timers, {Timer::Timer0, Timer::Channel2}, {GPIO::Pin(CONFIG_ESP32_LEDC_CHANNEL2_PIN)}),
initIOTimerChannel(io_timers, {Timer::Timer0, Timer::Channel3}, {GPIO::Pin(CONFIG_ESP32_LEDC_CHANNEL3_PIN)}),
};
// constexpr io_timers_channel_mapping_t io_timers_channel_mapping = initIOTimerChannelMapping(io_timers,
// timer_io_channels);
+84
View File
@@ -0,0 +1,84 @@
/****************************************************************************
*
* Copyright (C) 2021 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 PX4 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 usb.c
*
* Board-specific USB functions.
*/
/************************************************************************************
* Included Files
************************************************************************************/
#include <px4_platform_common/px4_config.h>
#include <sys/types.h>
#include <stdint.h>
#include <stdbool.h>
#include <debug.h>
#include <nuttx/usb/usbdev.h>
#include <nuttx/usb/usbdev_trace.h>
#include <xtensa.h>
#include "board_config.h"
/************************************************************************************
* Name: rp2040_usbinitialize
*
* Description:
* Called to setup USB-related GPIO pins for the omnibusf4sd board.
*
************************************************************************************/
__EXPORT void esp32_usbinitialize(void)
{
// px4_arch_configgpio(GPIO_USB_VBUS_VALID);
}
/************************************************************************************
* Name: stm32_usbsuspend
*
* Description:
* Board logic must provide the stm32_usbsuspend logic if the USBDEV driver is
* used. This function is called whenever the USB enters or leaves suspend mode.
* This is an opportunity for the board logic to shutdown clocks, power, etc.
* while the USB is suspended.
*
************************************************************************************/
__EXPORT void esp32_usbsuspend(FAR struct usbdev_s *dev, bool resume)
{
uinfo("resume: %d\n", resume);
}
+1
View File
@@ -66,6 +66,7 @@ CONFIG_MODULES_UXRCE_DDS_CLIENT=y
CONFIG_MODULES_VTOL_ATT_CONTROL=y
CONFIG_SYSTEMCMDS_ACTUATOR_TEST=y
CONFIG_SYSTEMCMDS_BL_UPDATE=y
CONFIG_BL_UPDATE_BL_ROMFS=y
CONFIG_SYSTEMCMDS_DMESG=y
CONFIG_SYSTEMCMDS_DUMPFILE=y
CONFIG_SYSTEMCMDS_GPIO=y
+1
View File
@@ -68,6 +68,7 @@ CONFIG_MODULES_UXRCE_DDS_CLIENT=y
CONFIG_MODULES_VTOL_ATT_CONTROL=y
CONFIG_SYSTEMCMDS_ACTUATOR_TEST=y
CONFIG_SYSTEMCMDS_BL_UPDATE=y
CONFIG_BL_UPDATE_BL_ROMFS=y
CONFIG_SYSTEMCMDS_DMESG=y
CONFIG_SYSTEMCMDS_DUMPFILE=y
CONFIG_SYSTEMCMDS_GPIO=y
+1
View File
@@ -79,6 +79,7 @@ CONFIG_MODULES_UUV_POS_CONTROL=y
CONFIG_MODULES_VTOL_ATT_CONTROL=y
CONFIG_SYSTEMCMDS_ACTUATOR_TEST=y
CONFIG_SYSTEMCMDS_BL_UPDATE=y
CONFIG_BL_UPDATE_BL_ROMFS=y
CONFIG_SYSTEMCMDS_BSONDUMP=y
CONFIG_SYSTEMCMDS_DMESG=y
CONFIG_SYSTEMCMDS_DUMPFILE=y
+1
View File
@@ -84,6 +84,7 @@ CONFIG_MODULES_UXRCE_DDS_CLIENT=y
CONFIG_MODULES_VTOL_ATT_CONTROL=y
CONFIG_SYSTEMCMDS_ACTUATOR_TEST=y
CONFIG_SYSTEMCMDS_BL_UPDATE=y
CONFIG_BL_UPDATE_BL_ROMFS=y
CONFIG_SYSTEMCMDS_BSONDUMP=y
CONFIG_SYSTEMCMDS_DMESG=y
CONFIG_SYSTEMCMDS_DUMPFILE=y
+1
View File
@@ -79,6 +79,7 @@ CONFIG_MODULES_UXRCE_DDS_CLIENT=y
CONFIG_MODULES_VTOL_ATT_CONTROL=y
CONFIG_SYSTEMCMDS_ACTUATOR_TEST=y
CONFIG_SYSTEMCMDS_BL_UPDATE=y
CONFIG_BL_UPDATE_BL_ROMFS=y
CONFIG_SYSTEMCMDS_BSONDUMP=y
CONFIG_SYSTEMCMDS_DMESG=y
CONFIG_SYSTEMCMDS_DUMPFILE=y
+1
View File
@@ -67,6 +67,7 @@ CONFIG_MODULES_UXRCE_DDS_CLIENT=y
CONFIG_MODULES_VTOL_ATT_CONTROL=y
CONFIG_SYSTEMCMDS_ACTUATOR_TEST=y
CONFIG_SYSTEMCMDS_BL_UPDATE=y
CONFIG_BL_UPDATE_BL_ROMFS=y
CONFIG_SYSTEMCMDS_BSONDUMP=y
CONFIG_SYSTEMCMDS_DMESG=y
CONFIG_SYSTEMCMDS_GPIO=y
@@ -73,6 +73,7 @@ CONFIG_MODULES_UUV_POS_CONTROL=y
CONFIG_MODULES_VTOL_ATT_CONTROL=y
CONFIG_SYSTEMCMDS_ACTUATOR_TEST=y
CONFIG_SYSTEMCMDS_BL_UPDATE=y
CONFIG_BL_UPDATE_BL_ROMFS=y
CONFIG_SYSTEMCMDS_BSONDUMP=y
CONFIG_SYSTEMCMDS_DMESG=y
CONFIG_SYSTEMCMDS_DUMPFILE=y
+1
View File
@@ -73,6 +73,7 @@ CONFIG_MODULES_UUV_POS_CONTROL=y
CONFIG_MODULES_VTOL_ATT_CONTROL=y
CONFIG_SYSTEMCMDS_ACTUATOR_TEST=y
CONFIG_SYSTEMCMDS_BL_UPDATE=y
CONFIG_BL_UPDATE_BL_ROMFS=y
CONFIG_SYSTEMCMDS_BSONDUMP=y
CONFIG_SYSTEMCMDS_DMESG=y
CONFIG_SYSTEMCMDS_DUMPFILE=y
+1
View File
@@ -73,6 +73,7 @@ CONFIG_MODULES_UUV_POS_CONTROL=y
CONFIG_MODULES_VTOL_ATT_CONTROL=y
CONFIG_SYSTEMCMDS_ACTUATOR_TEST=y
CONFIG_SYSTEMCMDS_BL_UPDATE=y
CONFIG_BL_UPDATE_BL_ROMFS=y
CONFIG_SYSTEMCMDS_BSONDUMP=y
CONFIG_SYSTEMCMDS_DMESG=y
CONFIG_SYSTEMCMDS_DUMPFILE=y
+1
View File
@@ -75,6 +75,7 @@ CONFIG_MODULES_UUV_POS_CONTROL=y
CONFIG_MODULES_VTOL_ATT_CONTROL=y
CONFIG_SYSTEMCMDS_ACTUATOR_TEST=y
CONFIG_SYSTEMCMDS_BL_UPDATE=y
CONFIG_BL_UPDATE_BL_ROMFS=y
CONFIG_SYSTEMCMDS_BSONDUMP=y
CONFIG_SYSTEMCMDS_DUMPFILE=y
CONFIG_SYSTEMCMDS_GPIO=y
+1
View File
@@ -8,4 +8,5 @@ CONFIG_MODULES_LOCAL_POSITION_ESTIMATOR=n
CONFIG_BOARD_TESTING=y
CONFIG_DRIVERS_TEST_PPM=y
CONFIG_SYSTEMCMDS_BL_UPDATE=y
CONFIG_BL_UPDATE_BL_ROMFS=y
CONFIG_SYSTEMCMDS_MICROBENCH=y
+1
View File
@@ -47,6 +47,7 @@ CONFIG_MODULES_SENSORS=y
# CONFIG_SENSORS_VEHICLE_AIRSPEED is not set
# CONFIG_SENSORS_VEHICLE_OPTICAL_FLOW is not set
CONFIG_SYSTEMCMDS_BL_UPDATE=y
CONFIG_BL_UPDATE_BL_ROMFS=y
CONFIG_SYSTEMCMDS_HARDFAULT_LOG=y
CONFIG_SYSTEMCMDS_MFT=y
CONFIG_SYSTEMCMDS_MTD=y
+1
View File
@@ -79,6 +79,7 @@ CONFIG_MODULES_UXRCE_DDS_CLIENT=y
CONFIG_MODULES_VTOL_ATT_CONTROL=y
CONFIG_SYSTEMCMDS_ACTUATOR_TEST=y
CONFIG_SYSTEMCMDS_BL_UPDATE=y
CONFIG_BL_UPDATE_BL_ROMFS=y
CONFIG_SYSTEMCMDS_BSONDUMP=y
CONFIG_SYSTEMCMDS_DUMPFILE=y
CONFIG_SYSTEMCMDS_GPIO=y
+1
View File
@@ -80,6 +80,7 @@ CONFIG_MODULES_UXRCE_DDS_CLIENT=y
CONFIG_MODULES_VTOL_ATT_CONTROL=y
CONFIG_SYSTEMCMDS_ACTUATOR_TEST=y
CONFIG_SYSTEMCMDS_BL_UPDATE=y
CONFIG_BL_UPDATE_BL_ROMFS=y
CONFIG_SYSTEMCMDS_BSONDUMP=y
CONFIG_SYSTEMCMDS_DUMPFILE=y
CONFIG_SYSTEMCMDS_GPIO=y
+1
View File
@@ -77,6 +77,7 @@ CONFIG_MODULES_UXRCE_DDS_CLIENT=y
CONFIG_MODULES_VTOL_ATT_CONTROL=y
CONFIG_SYSTEMCMDS_ACTUATOR_TEST=y
CONFIG_SYSTEMCMDS_BL_UPDATE=y
CONFIG_BL_UPDATE_BL_ROMFS=y
CONFIG_SYSTEMCMDS_BSONDUMP=y
CONFIG_SYSTEMCMDS_DUMPFILE=y
CONFIG_SYSTEMCMDS_GPIO=y
+1
View File
@@ -83,6 +83,7 @@ CONFIG_MODULES_UXRCE_DDS_CLIENT=y
CONFIG_MODULES_VTOL_ATT_CONTROL=y
CONFIG_SYSTEMCMDS_ACTUATOR_TEST=y
CONFIG_SYSTEMCMDS_BL_UPDATE=y
CONFIG_BL_UPDATE_BL_ROMFS=y
CONFIG_SYSTEMCMDS_BSONDUMP=y
CONFIG_SYSTEMCMDS_DMESG=y
CONFIG_SYSTEMCMDS_DUMPFILE=y
+1
View File
@@ -91,6 +91,7 @@ CONFIG_MODULES_UXRCE_DDS_CLIENT=y
CONFIG_MODULES_VTOL_ATT_CONTROL=y
CONFIG_SYSTEMCMDS_ACTUATOR_TEST=y
CONFIG_SYSTEMCMDS_BL_UPDATE=y
CONFIG_BL_UPDATE_BL_ROMFS=y
CONFIG_SYSTEMCMDS_BSONDUMP=y
CONFIG_SYSTEMCMDS_DMESG=y
CONFIG_SYSTEMCMDS_GPIO=y
@@ -72,6 +72,7 @@ CONFIG_MODULES_UXRCE_DDS_CLIENT=y
CONFIG_MODULES_VTOL_ATT_CONTROL=y
CONFIG_SYSTEMCMDS_ACTUATOR_TEST=y
CONFIG_SYSTEMCMDS_BL_UPDATE=y
CONFIG_BL_UPDATE_BL_ROMFS=y
CONFIG_SYSTEMCMDS_BSONDUMP=y
CONFIG_SYSTEMCMDS_DMESG=y
CONFIG_SYSTEMCMDS_DUMPFILE=y
+1
View File
@@ -74,6 +74,7 @@ CONFIG_MODULES_UXRCE_DDS_CLIENT=y
CONFIG_MODULES_VTOL_ATT_CONTROL=y
CONFIG_SYSTEMCMDS_ACTUATOR_TEST=y
CONFIG_SYSTEMCMDS_BL_UPDATE=y
CONFIG_BL_UPDATE_BL_ROMFS=y
CONFIG_SYSTEMCMDS_BSONDUMP=y
CONFIG_SYSTEMCMDS_DUMPFILE=y
CONFIG_SYSTEMCMDS_GPIO=y
+1
View File
@@ -74,6 +74,7 @@ CONFIG_MODULES_UXRCE_DDS_CLIENT=y
CONFIG_MODULES_VTOL_ATT_CONTROL=y
CONFIG_SYSTEMCMDS_ACTUATOR_TEST=y
CONFIG_SYSTEMCMDS_BL_UPDATE=y
CONFIG_BL_UPDATE_BL_ROMFS=y
CONFIG_SYSTEMCMDS_BSONDUMP=y
CONFIG_SYSTEMCMDS_DUMPFILE=y
CONFIG_SYSTEMCMDS_GPIO=y
+1
View File
@@ -61,6 +61,7 @@ CONFIG_MODULES_SIMULATION_SIMULATOR_SIH=y
CONFIG_MODULES_TEMPERATURE_COMPENSATION=y
CONFIG_SYSTEMCMDS_ACTUATOR_TEST=y
CONFIG_SYSTEMCMDS_BL_UPDATE=y
CONFIG_BL_UPDATE_BL_ROMFS=y
CONFIG_SYSTEMCMDS_BSONDUMP=y
CONFIG_SYSTEMCMDS_DMESG=y
CONFIG_SYSTEMCMDS_DUMPFILE=y
+1
View File
@@ -66,6 +66,7 @@ CONFIG_MODULES_TEMPERATURE_COMPENSATION=y
CONFIG_MODULES_VTOL_ATT_CONTROL=y
CONFIG_SYSTEMCMDS_ACTUATOR_TEST=y
CONFIG_SYSTEMCMDS_BL_UPDATE=y
CONFIG_BL_UPDATE_BL_ROMFS=y
CONFIG_SYSTEMCMDS_DMESG=y
CONFIG_SYSTEMCMDS_DUMPFILE=y
CONFIG_SYSTEMCMDS_GPIO=y
+1
View File
@@ -65,6 +65,7 @@ CONFIG_MODULES_TEMPERATURE_COMPENSATION=y
CONFIG_MODULES_VTOL_ATT_CONTROL=y
CONFIG_SYSTEMCMDS_ACTUATOR_TEST=y
CONFIG_SYSTEMCMDS_BL_UPDATE=y
CONFIG_BL_UPDATE_BL_ROMFS=y
CONFIG_SYSTEMCMDS_DMESG=y
CONFIG_SYSTEMCMDS_DUMPFILE=y
CONFIG_SYSTEMCMDS_GPIO=y
+1
View File
@@ -65,6 +65,7 @@ CONFIG_MODULES_TEMPERATURE_COMPENSATION=y
CONFIG_MODULES_VTOL_ATT_CONTROL=y
CONFIG_SYSTEMCMDS_ACTUATOR_TEST=y
CONFIG_SYSTEMCMDS_BL_UPDATE=y
CONFIG_BL_UPDATE_BL_ROMFS=y
CONFIG_SYSTEMCMDS_DMESG=y
CONFIG_SYSTEMCMDS_DUMPFILE=y
CONFIG_SYSTEMCMDS_GPIO=y
Binary file not shown.

After

Width:  |  Height:  |  Size: 269 KiB

+2
View File
@@ -823,6 +823,8 @@
- [Test MC_04 - Failsafe Testing](test_cards/mc_04_failsafe_testing.md)
- [Test MC_05 - Manual Modes (Inside)](test_cards/mc_05_indoor_flight_manual_modes.md)
- [Test MC_06 - Optical Flow (Inside)](test_cards/mc_06_optical_flow.md)
- [Test MC_07 - VIO (Inside)](test_cards/mc_07_vio.md)
- [Test MC_08 - DSHOT ESC](test_cards/mc_08_dshot.md)
- [Unit Tests](test_and_ci/unit_tests.md)
- [Fuzz Tests](test_and_ci/fuzz_tests.md)
- [Continuous Integration](test_and_ci/continous_integration.md)
+55 -12
View File
@@ -26,10 +26,18 @@
That is the minimum setup to use the rover in [Manual mode](../flight_modes_rover/manual.md#manual-mode).
::: info
The rest of the tuning on this page is not mandatory for [Manual mode](../flight_modes_rover/manual.md#manual-mode), but it will have an effect on the behaviour of the rover.
:::
::: warning
Do not skip the rest of this setup if you intend to use more sophisticated modes!
All parameters will be mandatory for all subsequent modes, except those tagged as `(Optional)`.
:::
## Geometric Parameters
Manual mode is also affected by (optional) acceleration/deceleration limits set using the geometric described below.
These limits are mandatory for all other modes.
First, we set up the geometric parameters of the rover:
![Geometric parameters](../../assets/config/rover/geometric_parameters.png)
@@ -41,7 +49,7 @@ Navigate to [Parameters](../advanced_config/parameters.md) in QGroundControl and
2. [RA_MAX_STR_ANG](#RA_MAX_STR_ANG) [deg]: Measure the maximum steering angle.
3. (Optional) [RA_STR_RATE_LIM](#RA_STR_RATE_LIM) [deg/s]: Maximum steering rate you want to allow for your rover.
:::tip
::: tip
This value depends on your rover and use case.
For bigger rovers there might be a mechanical limit that is easy to identify by steering the rover at a standstill and increasing
[RA_STR_RATE_LIM](#RA_STR_RATE_LIM) until you observe the steering rate to no longer be limited by the parameter.
@@ -49,7 +57,7 @@ Navigate to [Parameters](../advanced_config/parameters.md) in QGroundControl and
Increase the parameter until you reach the maximum steering rate you are comfortable with.
:::
:::warning
::: warning
A low maximum steering rate makes the rover worse at tracking steering setpoints, which can lead to a poor performance in the subsequent modes.
:::
@@ -79,14 +87,12 @@ Navigate to [Parameters](../advanced_config/parameters.md) in QGroundControl and
This may or may not be appropriate for your vehicle and use case.
One approach to determine an appropriate value is:
1. From a standstill, give the rover full throttle until it reaches the maximum speed.
2. Disarm the rover and plot the `measured_speed_body_x` from [RoverVelocityStatus](../msg_docs/RoverVelocityStatus.md).
3. Divide the maximum speed by the time it took to reach it and set this as the value for [RO_ACCEL_LIM](#RO_ACCEL_LIM).
Some RC rovers have enough torque to lift up if the maximum acceleration is not limited.
If that is the case:
1. Set [RO_ACCEL_LIM](#RO_ACCEL_LIM) to a low value, give the rover full throttle from a standstill and observe its behaviour.
2. Increase [RO_ACCEL_LIM](#RO_ACCEL_LIM) until the rover starts to lift up during the acceleration.
3. Set [RO_ACCEL_LIM](#RO_ACCEL_LIM) to the highest value that does not cause the rover to lift up.
@@ -102,6 +108,39 @@ Navigate to [Parameters](../advanced_config/parameters.md) in QGroundControl and
This parameter is also used for the calculation of the speed setpoint in modes that are [position controlled](position_tuning.md).
:::
## (Optional) Stick Input Mapping
Input shaping can be used to adjust the default linear mapping from stick inputs $\in [-1, 1]$ to normalized setpoints $\in [-1, 1]$. Applying this specifically to the steering input, can provide a smoother driving experience, by enabling the user to make small adjustments when the stick is close to the center, but still send large inputs when moving them to the edges.
We provide this input shaping through the super exponential function:
$$
\delta = \frac{(f \cdot x^3 + x(1-f)) \cdot (1-g)}{1-g \cdot |x|}
$$
with:
- $\delta \in [-1, 1]=$ Normalized steering setpoint.
- $x \in [-1, 1]=$ Normalized stick input.
- $f=$ [RO_YAW_EXPO](#RO_YAW_EXPO): `0` Purely linear input curve, `1` Purely cubic input curve.
- $g=$ [RO_YAW_SUPEXPO](#RO_YAW_SUPEXPO): `0` Pure Expo function, `0.7` reasonable shape enhancement for intuitive stick feel, `0.95` very strong bent input curve only near maxima have effect.
In [Manual mode](../flight_modes_rover/manual.md#manual-mode) we can additionally scale $\delta$ with an additional parameter $r$:
- Differential Rover: $r=$ [RD_YAW_STK_GAIN](#RD_YAW_STK_GAIN), which enables adjusting the slope of the input mapping. This leads to a normalized steering input $\hat{\delta} = \delta \cdot r \in$ [-[RD_YAW_STK_GAIN](#RD_YAW_STK_GAIN), [RD_YAW_STK_GAIN](#RD_YAW_STK_GAIN)].
- Mecanum Rover: $r=$ [RM_YAW_STK_GAIN](#RM_YAW_STK_GAIN), which enables adjusting the slope of the input mapping. This leads to a normalized steering input $\hat{\delta} = \delta \cdot r \in$ [-[RM_YAW_STK_GAIN](#RM_YAW_STK_GAIN), [RM_YAW_STK_GAIN](#RM_YAW_STK_GAIN)].
This scaling is useful to limit the normalized steering setpoint, if it is too aggresive for your rover in manual mode.
You can experiment with the relationships graphically using the [PX4 SuperExpo Rover calculator](https://www.desmos.com/calculator/gwm8lrlanx).
::: info
In [Acro](../flight_modes_rover/manual.md#acro-mode), [Stabilized](../flight_modes_rover/manual.md#stabilized-mode) and [Position](../flight_modes_rover/manual.md#position-mode) Mode, $\delta$ is instead scaled by $r=$ [RO_YAW_RATE_LIM](../advanced_config/parameter_reference.md#RO_MAX_THR_SPEED) for all rovers. This leads to a yaw rate setpoint $\dot{\psi} = \delta \cdot r \in$ [-[RO_YAW_RATE_LIM](../advanced_config/parameter_reference.md#RO_MAX_THR_SPEED), [RO_YAW_RATE_LIM](../advanced_config/parameter_reference.md#RO_MAX_THR_SPEED)]. This parameter is setup during [rate tuning](rate_tuning.md).
:::
::: info
The input shaping through [RO_YAW_EXPO](#RO_YAW_EXPO) and [RO_YAW_SUPEXPO](#RO_YAW_SUPEXPO) applies for all manual modes, while [RD_YAW_STK_GAIN](#RD_YAW_STK_GAIN)/[RM_YAW_STK_GAIN](#RM_YAW_STK_GAIN) only affects full manual mode.
:::
You can now continue the configuration process with [rate tuning](rate_tuning.md).
## Parameter Overview
@@ -111,6 +150,8 @@ You can now continue the configuration process with [rate tuning](rate_tuning.md
| <a id="RO_MAX_THR_SPEED"></a>[RO_MAX_THR_SPEED](../advanced_config/parameter_reference.md#RO_MAX_THR_SPEED) | Speed the rover drives at maximum throttle | $m/s$ |
| <a id="RO_ACCEL_LIM"></a>[RO_ACCEL_LIM](../advanced_config/parameter_reference.md#RO_ACCEL_LIM) | (Optional) Maximum allowed acceleration | $m/s^2$ |
| <a id="RO_DECEL_LIM"></a>[RO_DECEL_LIM](../advanced_config/parameter_reference.md#RO_DECEL_LIM) | (Optional) Maximum allowed deceleration | $m/s^2$ |
| <a id="RO_YAW_EXPO"></a>[RO_YAW_EXPO](../advanced_config/parameter_reference.md#RO_YAW_EXPO) | (Optional) Yaw rate expo factor | $-$ |
| <a id="RO_YAW_SUPEXPO"></a>[RO_YAW_SUPEXPO](../advanced_config/parameter_reference.md#RO_YAW_SUPEXPO) | (Optional) Yaw rate super expo factor | $-$ |
### Ackermann Specific
@@ -122,12 +163,14 @@ You can now continue the configuration process with [rate tuning](rate_tuning.md
### Differential Specific
| Parameter | Description | Unit |
| ----------------------------------------------------------------------------------------------------- | ----------- | ---- |
| <a id="RD_WHEEL_TRACK"></a>[RD_WHEEL_TRACK](../advanced_config/parameter_reference.md#RD_WHEEL_TRACK) | Wheel track | m |
| Parameter | Description | Unit |
| -------------------------------------------------------------------------------------------------------- | ----------------------------------------- | ---- |
| <a id="RD_WHEEL_TRACK"></a>[RD_WHEEL_TRACK](../advanced_config/parameter_reference.md#RD_WHEEL_TRACK) | Wheel track | $m$ |
| <a id="RD_YAW_STK_GAIN"></a>[RD_YAW_STK_GAIN](../advanced_config/parameter_reference.md#RD_YAW_STK_GAIN) | (Optional) Yaw stick gain for Manual mode | $-$ |
### Mecanum Specific
| Parameter | Description | Unit |
| ----------------------------------------------------------------------------------------------------- | ----------- | ---- |
| <a id="RM_WHEEL_TRACK"></a>[RM_WHEEL_TRACK](../advanced_config/parameter_reference.md#RM_WHEEL_TRACK) | Wheel track | m |
| Parameter | Description | Unit |
| -------------------------------------------------------------------------------------------------------- | ----------------------------------------- | ---- |
| <a id="RM_WHEEL_TRACK"></a>[RM_WHEEL_TRACK](../advanced_config/parameter_reference.md#RM_WHEEL_TRACK) | Wheel track | $m$ |
| <a id="RM_YAW_STK_GAIN"></a>[RM_YAW_STK_GAIN](../advanced_config/parameter_reference.md#RM_YAW_STK_GAIN) | (Optional) Yaw stick gain for Manual mode | $-$ |
+1 -1
View File
@@ -86,7 +86,7 @@ These steps are only necessary if you are tuning/want to unlock the manual [Posi
The rover is now ready to drive in [Position mode](../flight_modes_rover/manual.md#position-mode) and the configuration can be continued with [position tuning](position_tuning.md).
## Attitude Controller Structure (Info Only)
## Velocity Controller Structure (Info Only)
This section provides additional information for developers and people with experience in control system design.
+21 -2
View File
@@ -2,13 +2,32 @@
PX4 typically runs on flight controllers that include an IMU, such as the Pixhawk series, and fuse the sensor data along with GNSS information in the EKF2 estimator to determine vehicle attitude, heading, position, and velocity.
However PX4 can also use some INS devices as either sources of raw data, or as an external estimator, replacing the EKF.
However PX4 can also use some INS devices as either sources of raw data, or as an external estimator, replacing EKF2.
Systems that can be used in this way include:
## Supported INS Systems
INS systems that can be used as a replacement for EKF2 in PX4:
- [InertialLabs](../sensor/inertiallabs.md)
- [VectorNav](../sensor/vectornav.md): IMU/AHRS, GNSS/INS, Dual GNSS/INS systems that can be used as an external INS or as a source of raw sensor data.
## PX4 Firmware
The driver module for your INS system may not be included in the PX4 firmware for your flight controller by default.
You can check by searching the [default.px4board](https://github.com/PX4/PX4-Autopilot/blob/main/boards/px4/fmu-v6c/default.px4board#L25) configuration file for your target board for either:
- `CONFIG_COMMON_INS`, which includes drivers for [all INS systems](https://github.com/PX4/PX4-Autopilot/blob/main/src/drivers/ins/Kconfig).
- The key for the particular INS system you are using, such as:
- `CONFIG_DRIVERS_INS_ILABS`
- `CONFIG_DRIVERS_INS_MICROSTRAIN`
- `CONFIG_DRIVERS_INS_VECTORNAV`
If the required key is not present you can include the module in firmware by adding the key to the `default.px4board` file, or using the [kconfig board configuration tool](../hardware/porting_guide_config.md#px4-board-configuration-kconfig) and then select the driver you want (`Drivers -> INS`).
Note that if you're working on a flight controller where flash memory is limited, you're better off installing just the modules you need.
You will then need to rebuild the firmware.
## Glossary
### Inertial Measurement Unit (IMU)
+2
View File
@@ -28,3 +28,5 @@ These are run by the test team as part of release testing, and for more signific
- [MC_04 - Failsafe Testing](../test_cards/mc_04_failsafe_testing.md)
- [MC_05 - Indoor Flight (Manual Modes)](../test_cards/mc_05_indoor_flight_manual_modes.md)
- [MC_06 - Indoor Flight (Optical Flow)](../test_cards/mc_06_optical_flow.md)
- [MC_07 - VIO (Visual-Inertial Odometry)](../test_cards/mc_07_vio.md)
- [MC_08 - DSHOT ESC](../test_cards/mc_08_dshot.md)
+11 -1
View File
@@ -2,11 +2,19 @@
## Objective
To test that optical flow / external vision work as expected
To test that optical flow works as expected
## Preflight
Disconnect all GPS / compasses and ensure vehicle is using optical flow for navigation
([Setup Information here](../sensor/optical_flow.md))
Ensure there are no other sources of positioning besides optical flow
- [EKF2_OF_CTRL](../advanced_config/parameter_reference.md#EKF2_OF_CTRL): `1`
- [EKF2_GPS_CTRL](../advanced_config/parameter_reference.md#EKF2_GPS_CTRL): `0`
- [EKF2_EV_CTRL](../advanced_config/parameter_reference.md#EKF2_EV_CTRL): `0`
- [SYS_HAS_MAG](../advanced_config/parameter_reference.md#SYS_HAS_MAG): `0`
Ensure that the drone can go into Altitude / Position flight mode while still on the ground
@@ -39,5 +47,7 @@ Ensure that the drone can go into Altitude / Position flight mode while still on
## Expected Results
- Take-off should be smooth as throttle is raised
- Drone should hold altitude in Altitude Flight mode without wandering
- Drone should hold position within 1 meter in Position Flight mode without pilot moving sticks
- No oscillations should present in any of the above flight modes
- Upon landing, copter should not bounce on the ground
+52
View File
@@ -0,0 +1,52 @@
# Test MC_07 - VIO (Visual-Inertial Odometry)
## Objective
To test that external vision (VIO) works as expected
## Preflight
Disconnect all GPS / compasses and ensure vehicle is using VIO for navigation
Ensure that the drone can go into Altitude / Position flight mode while still on the ground
Ensure there are no other sources of positioning besides VIO:
- [EKF2_OF_CTRL](../advanced_config/parameter_reference.md#EKF2_OF_CTRL): `0`
- [EKF2_GPS_CTRL](../advanced_config/parameter_reference.md#EKF2_GPS_CTRL): `0`
- [EKF2_EV_CTRL](../advanced_config/parameter_reference.md#EKF2_EV_CTRL): `15`
- [SYS_HAS_MAG](../advanced_config/parameter_reference.md#SYS_HAS_MAG): `0`
## Flight Tests
❏ Altitude flight mode
&nbsp;&nbsp;&nbsp;&nbsp;❏ Vertical position should hold current value with stick centered
&nbsp;&nbsp;&nbsp;&nbsp;❏ Pitch/Roll/Yaw response 1:1
&nbsp;&nbsp;&nbsp;&nbsp;❏ Throttle response set to climb/descent rate
❏ Position flight mode
&nbsp;&nbsp;&nbsp;&nbsp;❏ Horizontal position should hold current value with stick centered
&nbsp;&nbsp;&nbsp;&nbsp;❏ Vertical position should hold current value with stick centered
&nbsp;&nbsp;&nbsp;&nbsp;❏ Throttle response set to climb/descent rate
&nbsp;&nbsp;&nbsp;&nbsp;❏ Pitch/Roll/Yaw response set to pitch/roll/yaw rates
## Landing
❏ Land in either Position or Altitude mode with the throttle below 40%
❏ Upon touching ground, copter should disarm automatically within 2 seconds (default: see [COM_DISARM_LAND](../advanced_config/parameter_reference.md#COM_DISARM_LAND))
## Expected Results
- Take-off should be smooth as throttle is raised
- Drone should hold altitude in Altitude Flight mode without wandering
- Drone should hold position within 1 meter in Position Flight mode without pilot moving sticks
- No oscillations should present in any of the above flight modes
- Upon landing, copter should not bounce on the ground
+46
View File
@@ -0,0 +1,46 @@
# Test MC_08 - DSHOT ESC
## Objective
Regression test for DSHOT working with PX4
## Preflight
- Ensure vehicle is using a DSHOT ESC.
- Parameter [DSHOT_BIDIR_EN](../advanced_config/parameter_reference.md#DSHOT_BIDIR_EN) is enabled
- Parameter [DSHOT_TEL_CFG](../advanced_config/parameter_reference.md#DSHOT_TEL_CFG) is configured (if ESC supports telemetry)
- Parameter [SDLOG_PROFILE](../advanced_config/parameter_reference.md#SDLOG_PROFILE) has Debug (`5`) checked
## Flight Tests
❏ Stabilized Flight mode
&nbsp;&nbsp;&nbsp;&nbsp;❏ Takeoff in stabilized flight mode to ensure correct motor spin
&nbsp;&nbsp;&nbsp;&nbsp;❏ Pitch/Roll/Yaw response 1:1
&nbsp;&nbsp;&nbsp;&nbsp;❏ Throttle response 1:1
❏ Position flight mode
&nbsp;&nbsp;&nbsp;&nbsp;❏ Horizontal position should hold current value with stick centered
&nbsp;&nbsp;&nbsp;&nbsp;❏ Vertical position should hold current value with stick centered
&nbsp;&nbsp;&nbsp;&nbsp;❏ Throttle response set to climb/descent rate
&nbsp;&nbsp;&nbsp;&nbsp;❏ Pitch/Roll/Yaw response set to pitch/roll/yaw rates
## Landing
❏ Land in either Position or Altitude mode with the throttle below 40%
❏ Upon touching ground, copter should disarm automatically within 2 seconds (default: see [COM_DISARM_LAND](../advanced_config/parameter_reference.md#COM_DISARM_LAND))
## Expected Results
- Download flight logs
- Load into Data Plot Juggler
- Ensure data is logged for esc_status/esc.0x/esc_rpm
![Reference frames](../../assets/test_cards/dshot_log_output.png)
+2 -2
View File
@@ -181,10 +181,10 @@ set(msg_files
RoverPositionSetpoint.msg
RoverRateSetpoint.msg
RoverRateStatus.msg
RoverSpeedSetpoint.msg
RoverSpeedStatus.msg
RoverSteeringSetpoint.msg
RoverThrottleSetpoint.msg
RoverVelocitySetpoint.msg
RoverVelocityStatus.msg
Rpm.msg
RtlStatus.msg
RtlTimeEstimate.msg
+5
View File
@@ -0,0 +1,5 @@
# Rover Speed Setpoint
uint64 timestamp # [us] Time since system start
float32 speed_body_x # [m/s] [@range -inf (Backwards), inf (Forwards)] [@frame Body] Speed setpoint in body x direction
float32 speed_body_y # [m/s] [@range -inf (Left), inf (Right)] [@frame Body] [@invalid NaN If not mecanum] Mecanum only: Speed setpoint in body y direction
-6
View File
@@ -1,6 +0,0 @@
# Rover Velocity Setpoint
uint64 timestamp # [us] Time since system start
float32 speed # [m/s] [@range -inf (Backwards), inf (Forwards)] Speed setpoint
float32 bearing # [rad] [@range -pi,pi] [@frame NED] [@invalid: NaN, speed is defined in body x direction] Bearing setpoint
float32 yaw # [rad] [@range -pi, pi] [@frame NED] [@invalid NaN, Defaults to vehicle yaw] Mecanum only: Yaw setpoint
+100
View File
@@ -242,6 +242,105 @@ if (NOT CONFIG_BUILD_FLAT)
else()
if(CONFIG_ARCH_CHIP_ESP32)
set(PX4_STARTUP_DIR ${PX4_SOURCE_DIR}/platforms/nuttx/NuttX/nuttx/arch/xtensa/src)
set(WIRELESS_LIB ${PX4_STARTUP_DIR}/esp32/esp-wireless-drivers-3rdparty/libs/esp32/)
set(NUTTX_STARTUP_OBJS
${PX4_STARTUP_DIR}/xtensa_vectors.o
${PX4_STARTUP_DIR}/xtensa_window_vector.o
${PX4_STARTUP_DIR}/xtensa_windowspill.o
${PX4_STARTUP_DIR}/xtensa_int_handlers.o
${PX4_STARTUP_DIR}/xtensa_user_handler.o
${PX4_STARTUP_DIR}/xtensa_initialize.o
${PX4_STARTUP_DIR}/xtensa_initialstate.o
${PX4_STARTUP_DIR}/esp32_start.o
${PX4_STARTUP_DIR}/esp32_wdt.o
)
set(NUTTX_NETWORK_LIB
libbtdm_app.a
libcoexist.a
libcore.a
libespnow.a
libnet80211.a
libphy.a
libpp.a
librtc.a
libsmartconfig.a
libwapi.a
libwpa_supplicant.a
)
execute_process(COMMAND touch ${NUTTX_STARTUP_OBJS}
WORKING_DIRECTORY ${PX4_SOURCE_DIR})
set_source_files_properties(
${NUTTX_STARTUP_OBJS}
PROPERTIES
EXTERNAL_OBJECT true
GENERATED true)
target_link_libraries(nuttx_c INTERFACE nuttx_sched) # nxsched_get_streams
target_link_libraries(nuttx_arch
INTERFACE
drivers_board
arch_hrt
arch_board_reset
-L${WIRELESS_LIB}
-Wl,--start-group
${NUTTX_NETWORK_LIB}
-Wl,--end-group
)
target_link_libraries(nuttx_c INTERFACE nuttx_drivers)
target_link_libraries(nuttx_drivers INTERFACE nuttx_c nuttx_fs)
target_link_libraries(nuttx_xx INTERFACE nuttx_c)
target_link_libraries(nuttx_fs INTERFACE nuttx_c nuttx_net)
target_link_libraries(nuttx_net INTERFACE nuttx_mm)
target_link_libraries(px4 PRIVATE
-nostartfiles
-nodefaultlibs
-nostdlib
-nostdinc++
-mlongcalls
-fno-exceptions
-fno-rtti
-Wl,--cref
-L${WIRELESS_LIB}
-Wl,-T${NUTTX_CONFIG_DIR_CYG}/scripts/${SCRIPT_PREFIX}esp32_out.ld
-T${NUTTX_CONFIG_DIR_CYG}/scripts/${SCRIPT_PREFIX}esp32.ld
-T${NUTTX_CONFIG_DIR_CYG}/scripts/${SCRIPT_PREFIX}esp32_rom.ld
-Wl,-Map=${PX4_CONFIG}.map
-Wl,--gc-sections
-Wl,--start-group
${nuttx_libs}
${NUTTX_STARTUP_OBJS}
${NUTTX_NETWORK_LIB}
-Wl,--end-group
m
gcc
)
if(NOT USE_LD_GOLD)
target_link_libraries(px4 PRIVATE -Wl,--print-memory-usage)
endif()
target_link_libraries(px4 PRIVATE ${module_libraries})
if(config_romfs_root)
add_subdirectory(${PX4_SOURCE_DIR}/ROMFS ${PX4_BINARY_DIR}/ROMFS)
target_link_libraries(px4 PRIVATE romfs)
endif()
add_custom_command(OUTPUT ${PX4_BINARY_OUTPUT}
COMMAND esptool --chip esp32 elf2image -o ${PX4_BINARY_OUTPUT} ${PX4_BINARY_DIR_REL}/${FW_NAME}
COMMAND du ${PX4_BINARY_OUTPUT} -h
DEPENDS px4
)
else()
target_link_libraries(nuttx_c INTERFACE nuttx_sched) # nxsched_get_streams
target_link_libraries(nuttx_arch
@@ -294,6 +393,7 @@ else()
COMMAND ${CMAKE_OBJCOPY} -O binary ${PX4_BINARY_DIR_REL}/${FW_NAME} ${PX4_BINARY_OUTPUT}
DEPENDS px4
)
endif()
endif()
@@ -0,0 +1,4 @@
set(cpu_flags "-mlongcalls -Wno-format -Wno-unused-function -fdata-sections -Wno-pointer-arith")#-DDEBUG_BUILD
set(CMAKE_C_FLAGS "${cpu_flags} -Wstrict-prototypes -Wshadow" CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS "${cpu_flags} -nostdinc++ -Wshadow" CACHE STRING "" FORCE)
set(CMAKE_ASM_FLAGS "${cpu_flags} -D__ASSEMBLY__" CACHE STRING "" FORCE)
@@ -0,0 +1,44 @@
# arm-none-eabi-gcc toolchain
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_VERSION 1)
set(triple xtensa-esp32-elf)
set(CMAKE_LIBRARY_ARCHITECTURE ${triple})
set(TOOLCHAIN_PREFIX ${triple})
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_C_COMPILER_TARGET ${triple})
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
set(CMAKE_CXX_COMPILER_TARGET ${triple})
set(CMAKE_ASM_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
# needed for test compilation
set(CMAKE_EXE_LINKER_FLAGS_INIT "--specs=nosys.specs")
# compiler tools
find_program(CMAKE_AR ${TOOLCHAIN_PREFIX}-ar)
find_program(CMAKE_GDB ${TOOLCHAIN_PREFIX}-gdb)
find_program(CMAKE_LD ${TOOLCHAIN_PREFIX}-ld)
find_program(CMAKE_LINKER ${TOOLCHAIN_PREFIX}-ld)
find_program(CMAKE_NM ${TOOLCHAIN_PREFIX}-nm)
find_program(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}-objcopy)
find_program(CMAKE_OBJDUMP ${TOOLCHAIN_PREFIX}-objdump)
find_program(CMAKE_RANLIB ${TOOLCHAIN_PREFIX}-gcc-ranlib)
find_program(CMAKE_STRIP ${TOOLCHAIN_PREFIX}-strip)
set(CMAKE_FIND_ROOT_PATH get_file_component(${CMAKE_C_COMPILER} PATH))
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
# os tools
foreach(tool grep make)
string(TOUPPER ${tool} TOOL)
find_program(${TOOL} ${tool})
if(NOT ${TOOL})
message(FATAL_ERROR "could not find ${tool}")
endif()
endforeach()
+3
View File
@@ -170,6 +170,9 @@ function(px4_os_determine_build_chip)
elseif(CONFIG_ARCH_CHIP_RP2040)
set(CHIP_MANUFACTURER "rpi")
set(CHIP "rp2040")
elseif(CONFIG_ARCH_CHIP_ESP32)
set(CHIP_MANUFACTURER "espressif")
set(CHIP "esp32")
else()
message(FATAL_ERROR "Could not determine chip architecture from NuttX config. You may have to add it.")
endif()
@@ -1,7 +1,7 @@
#! /bin/sh
#
# Bootloader upgrade
# Bootloader upgrade (ROMFS)
#
if param compare -s SYS_BL_UPDATE 1
then
+1 -22
View File
@@ -80,7 +80,7 @@
// RESET finalise flash programming, reset chip and starts application
//
#define BL_PROTOCOL_REVISION 6 // The revision of the bootloader protocol
#define BL_PROTOCOL_REVISION 5 // The revision of the bootloader protocol
//* Next revision needs to update
// protocol bytes
@@ -158,8 +158,6 @@
static uint8_t bl_type;
static uint8_t last_input;
static int unlock_seq[] = { 0x93, 0x7C, 0xA1, 0x4E, 0x5D, 0xF0, 0xB5, 0x68 };
int get_version(int n, uint8_t *version_str)
{
int len = strlen(BOOTLOADER_VERSION);
@@ -628,8 +626,6 @@ bootloader(unsigned timeout)
volatile uint32_t bl_state = 0; // Must see correct command sequence to erase and reboot (commit first word)
uint32_t address = board_info.fw_size; /* force erase before upload will work */
uint32_t first_word = 0xffffffff;
uint32_t unlock_idx = 0;
bool bl_locked = true;
/* (re)start the timer system */
arch_systic_init();
@@ -668,23 +664,6 @@ bootloader(unsigned timeout)
bool full_erase = false;
if (bl_locked) {
if (unlock_seq[unlock_idx] == c) {
unlock_idx++;
sync_response();
} else {
unlock_idx = 0;
invalid_response();
}
if (unlock_idx >= sizeof(unlock_seq)) {
bl_locked = false;
}
continue;
}
// handle the command byte
switch (c) {
@@ -129,7 +129,11 @@ bool SerialImpl::configure()
default:
speed = _baudrate;
#ifdef CONFIG_ARCH_CHIP_ESP32
PX4_WARN("Using non-standard baudrate: %u", _baudrate);
#else
PX4_WARN("Using non-standard baudrate: %lu", _baudrate);
#endif
break;
}
@@ -0,0 +1,34 @@
############################################################################
#
# Copyright (c) 2019 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 PX4 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.
#
############################################################################
add_subdirectory(${PX4_CHIP})
@@ -0,0 +1,6 @@
add_subdirectory(hrt hrt)
add_subdirectory(version version)
add_subdirectory(board_critmon board_critmon)
add_subdirectory(board_reset board_reset)
add_subdirectory(spi spi)
add_subdirectory(io_pins io_pins)
@@ -0,0 +1,36 @@
############################################################################
#
# Copyright (C) 2021 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 PX4 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.
#
############################################################################
px4_add_library(arch_board_critmon
board_critmon.c
)
@@ -0,0 +1,66 @@
/************************************************************************************
*
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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.
*
************************************************************************************/
/************************************************************************************
* Included Files
************************************************************************************/
#include <nuttx/config.h>
#include <arch/board/board.h>
#if defined(CONFIG_SCHED_CRITMONITOR) || defined(CONFIG_SCHED_IRQMONITOR)
/************************************************************************************
* Public Functions
************************************************************************************/
#error "missing implementation for up_critmon_gettime() and up_critmon_convert()"
/************************************************************************************
* Name: up_critmon_gettime
************************************************************************************/
// uint32_t up_critmon_gettime(void)
// {
// }
/************************************************************************************
* Name: up_critmon_convert
************************************************************************************/
// void up_critmon_convert(uint32_t elapsed, FAR struct timespec *ts)
// {
// }
#endif /* CONFIG_SCHED_CRITMONITOR */
@@ -0,0 +1,43 @@
############################################################################
#
# Copyright (C) 2021 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 PX4 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.
#
############################################################################
px4_add_library(arch_board_reset
board_reset.cpp
)
# up_systemreset
if (NOT DEFINED CONFIG_BUILD_FLAT)
target_link_libraries(arch_board_reset PRIVATE nuttx_karch)
else()
target_link_libraries(arch_board_reset PRIVATE nuttx_arch)
endif()
@@ -0,0 +1,105 @@
/****************************************************************************
*
* Copyright (C) 2021 PX4 Development Team. All rights reserved.
* Author: @author David Sidrane <david_s5@nscdg.com>
*
* 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 PX4 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 board_reset.cpp
* Implementation of RP2040 based Board RESET API
*/
#include <px4_platform_common/px4_config.h>
#include <px4_platform_common/shutdown.h>
#include <systemlib/px4_macros.h>
#include <errno.h>
#include <nuttx/board.h>
#include <nuttx/arch.h>
#include "esp32_systemreset.h"
// Functions in here are modified so that board_reset() function resembles
// the one available in nuttx's boards/raspberrypi-pico folder.
#ifdef CONFIG_BOARDCTL_RESET
/****************************************************************************
* Name: board_reset
*
* Description:
* Reset board. Support for this function is required by board-level
* logic if CONFIG_BOARDCTL_RESET is selected.
*
* Input Parameters:
* status - Status information provided with the reset event. This
* meaning of this status information is board-specific. If not
* used by a board, the value zero may be provided in calls to
* board_reset().
*
* Returned Value:
* If this function returns, then it was not possible to power-off the
* board due to some constraints. The return value int this case is a
* board-specific reason for the failure to shutdown.
*
****************************************************************************/
int board_reset(int status)
{
up_systemreset();
return 0;
}
#endif /* CONFIG_BOARDCTL_RESET */
#if defined(SUPPORT_ALT_CAN_BOOTLOADER)
/****************************************************************************
* Name: board_booted_by_px4
*
* Description:
* Determines if the the boot loader was PX4
*
* Input Parameters:
* none
*
* Returned Value:
* true if booted byt a PX4 bootloader.
*
****************************************************************************/
bool board_booted_by_px4(void)
{
uint32_t *vectors = (uint32_t *) STM32_FLASH_BASE;
/* Nuttx uses common vector */
return (vectors[2] == vectors[3]) && (vectors[4] == vectors[5]);
}
#endif
@@ -0,0 +1,41 @@
############################################################################
#
# Copyright (c) 2015-2019 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 PX4 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.
#
############################################################################
px4_add_library(arch_hrt
hrt.c
)
target_compile_options(arch_hrt
PRIVATE
${MAX_CUSTOM_OPT_LEVEL}
-Wno-cast-align # TODO: fix and enable
)
@@ -0,0 +1,636 @@
/****************************************************************************
*
* Copyright (c) 2012, 2013 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 PX4 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 drv_hrt.c
*
* High-resolution timer callouts and timekeeping.
*
* This can use any general or advanced STM32 timer.
*
* Note that really, this could use systick too, but that's
* monopolised by NuttX and stealing it would just be awkward.
*
* We don't use the NuttX STM32 driver per se; rather, we
* claim the timer and then drive it directly.
*/
#include <px4_platform_common/px4_config.h>
#include <nuttx/arch.h>
#include <nuttx/irq.h>
#include <sys/types.h>
#include <stdbool.h>
#include <assert.h>
#include <debug.h>
#include <time.h>
#include <queue.h>
#include <errno.h>
#include <string.h>
#include "esp32_irq.h"
#include <xtensa.h>
#include <board_config.h>
#include <drivers/drv_hrt.h>
#ifdef CONFIG_DEBUG_HRT
# define hrtinfo _info
#else
# define hrtinfo(x...)
#endif
#ifdef HRT_TIMER
/* HRT configuration */
#if HRT_TIMER == 0
# define HRT_TIM_BASE 0x3ff5f000
# define HRT_TIMER_PERIPH 14
# define HRT_TIMER_PRIO 1
# define HRT_TIMER_VECTOR 5 + HRT_TIMER_PERIPH
# define HRT_TIMER_CLOCK 80 * 1000000
# define HRT_TIMER_BASE 0x3ff5f000
# define HRT_TIMER_CLR_OFFSET 0x00a4
# define HRT_TIMER_INT_ENA_OFFSET 0x0098
# define HRT_TIMER_INT_CLR 1 << 0
# if CONFIG_ESP32_WIFI
# error must not set CONFIG_ESP32_WIFI=y and HRT_TIMER=0. WIFI makes use of TIMER=0
# endif
#elif HRT_TIMER == 1
# define HRT_TIM_BASE 0x3ff5f000 + 0x0024
# define HRT_TIMER_PERIPH 15
# define HRT_TIMER_PRIO 1
# define HRT_TIMER_VECTOR 5 + HRT_TIMER_PERIPH
# define HRT_TIMER_CLOCK 80 * 1000000
# define HRT_TIMER_BASE 0x3ff5f000 + 0x0024
# define HRT_TIMER_CLR_OFFSET 0x0080
# define HRT_TIMER_INT_ENA_OFFSET 0x0074
# define HRT_TIMER_INT_CLR 1 << 1
# if CONFIG_ESP32_TIMER1
# error must not set CONFIG_ESP32_TIMER1=y and HRT_TIMER=1
# endif
#elif HRT_TIMER == 2
# define HRT_TIM_BASE 0x3ff5f000 + 0x1000
# define HRT_TIMER_PERIPH 18
# define HRT_TIMER_PRIO 1
# define HRT_TIMER_VECTOR 5 + HRT_TIMER_PERIPH
# define HRT_TIMER_CLOCK 80 * 1000000
# define HRT_TIMER_BASE 0x3ff5f000 + 0x1000
# define HRT_TIMER_CLR_OFFSET 0x00a4
# define HRT_TIMER_INT_ENA_OFFSET 0x0098
# define HRT_TIMER_INT_CLR 1 << 0
# if CONFIG_ESP32_TIMER2
# error must not set CONFIG_ESP32_TIMER2=y and HRT_TIMER=2
# endif
#elif HRT_TIMER == 3
# define HRT_TIM_BASE 0x3ff5f000 + 0x0024 + 0x1000
# define HRT_TIMER_PERIPH 19
# define HRT_TIMER_PRIO 1
# define HRT_TIMER_VECTOR 5 + HRT_TIMER_PERIPH
# define HRT_TIMER_CLOCK 80 * 1000000
# define HRT_TIMER_BASE 0x3ff5f000 + 0x0024 + 0x1000
# define HRT_TIMER_CLR_OFFSET 0x0080
# define HRT_TIMER_INT_ENA_OFFSET 0x0074
# define HRT_TIMER_INT_CLR 1 << 1
# if CONFIG_ESP32_TIMER3
# error must not set CONFIG_ESP32_TIMER3=y and HRT_TIMER=3
# endif
#else
# error HRT_TIMER must be a value between 0 and 3
#endif
#define REG(_reg) (*(volatile uint32_t *)(HRT_TIMER_BASE + _reg))
#define HRT_CONFIG_OFFSET 0x00
#define HRT_LOAD_LO_OFFSET 0x0018
#define HRT_LOAD_HI_OFFSET 0x001c
#define HRT_LOAD_OFFSET 0x0020
#define HRT_ALARM_LO_OFFSET 0x0010
#define HRT_ALARM_HI_OFFSET 0x0014
#define HRT_UPDATE_OFFSET 0x000c
#define HRT_LO_OFFSET 0x0004
#define HRT_HI_OFFSET 0x0008
#define HRT_DIVIDER_S 13
#define HRT_DIVIDER_M 0xffff << 13
#define HRT_ALARM_EN 1 << 10
#define HRT_AUTORELOAD 1 << 29
#define HRT_TIMER_LEVEL_INT_EN 1 << 11
#define HRT_TIMER_INT_ENA 1 << 0
#define HRT_TIMER_EN 1 << 31
#define HRT_INCREASE 1 << 30
#define rLO REG(HRT_LO_OFFSET)
#define rHI REG(HRT_HI_OFFSET)
#define rUPDATE REG(HRT_UPDATE_OFFSET)
#define rALARMLO REG(HRT_ALARM_LO_OFFSET)
#define rALARMHI REG(HRT_ALARM_HI_OFFSET)
/*
* HRT clock must be a multiple of 1MHz greater than 1MHz
*/
#if (HRT_TIMER_CLOCK % 1000000) != 0
# error HRT_TIMER_CLOCK must be a multiple of 1MHz
#endif
#if HRT_TIMER_CLOCK <= 1000000
# error HRT_TIMER_CLOCK must be greater than 1MHz
#endif
/**
* Minimum/maximum deadlines.
*
* These are suitable for use with a 16-bit timer/counter clocked
* at 1MHz. The high-resolution timer need only guarantee that it
* not wrap more than once in the 50ms period for absolute time to
* be consistently maintained.
*
* The minimum deadline must be such that the time taken between
* reading a time and writing a deadline to the timer cannot
* result in missing the deadline.
*/
#define HRT_INTERVAL_MIN 50
#define HRT_INTERVAL_MAX 50000
/*
* Period of the free-running counter, in microseconds.
*/
#define HRT_COUNTER_PERIOD 18446744073709551615
/*
* Scaling factor(s) for the free-running counter; convert an input
* in counts to a time in microseconds.
*/
#define HRT_COUNTER_SCALE(_c) (_c)
/*
* Queue of callout entries.
*/
static struct sq_queue_s callout_queue;
/* latency baseline (last compare value applied) */
static uint64_t latency_baseline;
/* timer count at interrupt (for latency purposes) */
static uint64_t latency_actual;
/* latency histogram */
const uint16_t latency_bucket_count = LATENCY_BUCKET_COUNT;
const uint16_t latency_buckets[LATENCY_BUCKET_COUNT] = { 1, 2, 5, 10, 20, 50, 100, 1000 };
__EXPORT uint32_t latency_counters[LATENCY_BUCKET_COUNT + 1];
/* timer-specific functions */
static void hrt_tim_init(void);
static int hrt_tim_isr(int irq, void *context, void *arg);
static void hrt_latency_update(void);
static void esp32_tim_modifyreg32(uint32_t base, uint32_t offset, uint32_t clearbits, uint32_t setbits);
static void esp32_tim_putreg(uint32_t base, uint32_t offset, uint32_t value);
static uint32_t esp32_tim_getreg(uint32_t base, uint32_t offset);
/* callout list manipulation */
static void hrt_call_internal(struct hrt_call *entry,
hrt_abstime deadline,
hrt_abstime interval,
hrt_callout callout,
void *arg);
static void hrt_call_enter(struct hrt_call *entry);
static void hrt_call_reschedule(void);
static void hrt_call_invoke(void);
int hrt_ioctl(unsigned int cmd, unsigned long arg);
static void esp32_tim_modifyreg32(uint32_t base, uint32_t offset, uint32_t clearbits, uint32_t setbits)
{
modifyreg32(base + offset, clearbits, setbits);
}
static void esp32_tim_putreg(uint32_t base, uint32_t offset, uint32_t value)
{
putreg32(value, base + offset);
}
static uint32_t esp32_tim_getreg(uint32_t base, uint32_t offset)
{
return getreg32(base + offset);
}
/**
* Initialise the timer we are going to use.
*
* We expect that we'll own one of the reduced-function STM32 general
* timers, and that we can use channel 1 in compare mode.
*/
static void
hrt_tim_init(void)
{
// ESP32_TIM_SETPRE(tim, ESP32_HRT_TIMER_PRESCALER);
uint32_t mask = ((uint32_t)(HRT_TIMER_CLOCK / 1000000) - 1) << HRT_DIVIDER_S;
esp32_tim_modifyreg32(HRT_TIM_BASE, HRT_CONFIG_OFFSET, HRT_DIVIDER_M, mask);
// ESP32_TIM_SETMODE(tim, ESP32_TIM_MODE_UP);
esp32_tim_modifyreg32(HRT_TIM_BASE, HRT_CONFIG_OFFSET, 0, HRT_INCREASE);
// ESP32_TIM_CLEAR(tim);
esp32_tim_putreg(HRT_TIM_BASE, HRT_LOAD_LO_OFFSET, 0);
esp32_tim_putreg(HRT_TIM_BASE, HRT_LOAD_HI_OFFSET, 0);
esp32_tim_putreg(HRT_TIM_BASE, HRT_LOAD_OFFSET, 1 << 0); //reload
// ESP32_TIM_SETCTR(tim, 0); //set counter value
esp32_tim_putreg(HRT_TIM_BASE, HRT_LOAD_LO_OFFSET, 0);
esp32_tim_putreg(HRT_TIM_BASE, HRT_LOAD_HI_OFFSET, 0);
// ESP32_TIM_RLD_NOW(tim); //reload value now
esp32_tim_putreg(HRT_TIM_BASE, HRT_LOAD_OFFSET, 1 << 0); //reload
// ESP32_TIM_SETALRVL(tim, 1000); //alarm value
uint64_t val = 1000;
uint64_t low_64 = val & 0xffffffff;
uint64_t high_64 = (val >> 32) & 0xffffffff;
esp32_tim_putreg(HRT_TIM_BASE, HRT_ALARM_LO_OFFSET, (uint32_t)low_64);
esp32_tim_putreg(HRT_TIM_BASE, HRT_ALARM_HI_OFFSET, (uint32_t)high_64);
// ESP32_TIM_SETALRM(tim, true); //enable alarm
esp32_tim_modifyreg32(HRT_TIM_BASE, HRT_CONFIG_OFFSET, 0, HRT_ALARM_EN);
// ESP32_TIM_SETARLD(tim, false); //auto reload
esp32_tim_modifyreg32(HRT_TIM_BASE, HRT_CONFIG_OFFSET, HRT_AUTORELOAD, 0);
// ESP32_TIM_SETISR(tim, hrt_tim_isr, NULL);
esp32_setup_irq(0, HRT_TIMER_PERIPH, HRT_TIMER_PRIO, ESP32_CPUINT_LEVEL);
irq_attach(HRT_TIMER_VECTOR, hrt_tim_isr, NULL);
up_enable_irq(HRT_TIMER_VECTOR);
// ESP32_TIM_ENABLEINT(tim);
esp32_tim_modifyreg32(HRT_TIM_BASE, HRT_CONFIG_OFFSET, 0, HRT_TIMER_LEVEL_INT_EN);
esp32_tim_modifyreg32(HRT_TIM_BASE, HRT_TIMER_INT_ENA_OFFSET, 0, HRT_TIMER_INT_ENA);
// ESP32_TIM_START(tim);
esp32_tim_modifyreg32(HRT_TIM_BASE, HRT_CONFIG_OFFSET, 0, HRT_TIMER_EN);
}
/**
* Handle the compare interrupt by calling the callout dispatcher
* and then re-scheduling the next deadline.
*/
static int IRAM_ATTR
hrt_tim_isr(int irq, void *context, void *arg)
{
// uint32_t status = REG_READ(DPORT_APP_INTR_STATUS_1_REG);
/* grab the timer for latency tracking purposes */
uint32_t value_32;
latency_actual = 0;
/* Dummy value to latch the counter value to read it */
esp32_tim_putreg(HRT_TIM_BASE, HRT_UPDATE_OFFSET, 1 << 0);
/* Read value */
value_32 = esp32_tim_getreg(HRT_TIM_BASE, HRT_HI_OFFSET); /* High 32 bits */
latency_actual |= (uint64_t)value_32;
latency_actual <<= 32;
value_32 = esp32_tim_getreg(HRT_TIM_BASE, HRT_LO_OFFSET); /* Low 32 bits */
latency_actual |= (uint64_t)value_32;
/* do latency calculations */
hrt_latency_update();
/* run any callouts that have met their deadline */
hrt_call_invoke();
/* and schedule the next interrupt */
hrt_call_reschedule();
// acknowledge the interrupt
esp32_tim_putreg(HRT_TIM_BASE, HRT_TIMER_CLR_OFFSET, HRT_TIMER_INT_CLR);
esp32_tim_modifyreg32(HRT_TIM_BASE, HRT_CONFIG_OFFSET, 0, HRT_ALARM_EN);
return OK;
}
/**
* Fetch a never-wrapping absolute time value in microseconds from
* some arbitrary epoch shortly after system start.
*/
hrt_abstime IRAM_ATTR
hrt_absolute_time(void)
{
hrt_abstime abstime;
// uint64_t count;
irqstate_t flags;
/*
* Counter state. Marked volatile as they may change
* inside this routine but outside the irqsave/restore
* pair. Discourage the compiler from moving loads/stores
* to these outside of the protected range.
*/
// static volatile uint64_t last_count;
/* prevent re-entry */
flags = px4_enter_critical_section();
rUPDATE = 1;
abstime = (hrt_abstime)(((uint64_t)rHI << 32) | (uint64_t)rLO);
px4_leave_critical_section(flags);
return abstime;
}
/**
* Store the absolute time in an interrupt-safe fashion
*/
void
hrt_store_absolute_time(volatile hrt_abstime *t)
{
irqstate_t flags = px4_enter_critical_section();
*t = hrt_absolute_time();
px4_leave_critical_section(flags);
}
/**
* Initialise the high-resolution timing module.
*/
void
hrt_init(void)
{
sq_init(&callout_queue);
hrt_tim_init();
}
/**
* Call callout(arg) after interval has elapsed.
*/
void __attribute__((section(".iram1")))
hrt_call_after(struct hrt_call *entry, hrt_abstime delay, hrt_callout callout, void *arg)
{
hrt_call_internal(entry,
hrt_absolute_time() + delay,
0,
callout,
arg);
}
/**
* Call callout(arg) at calltime.
*/
void __attribute__((section(".iram1")))
hrt_call_at(struct hrt_call *entry, hrt_abstime calltime, hrt_callout callout, void *arg)
{
hrt_call_internal(entry, calltime, 0, callout, arg);
}
/**
* Call callout(arg) every period.
*/
void __attribute__((section(".iram1")))
hrt_call_every(struct hrt_call *entry, hrt_abstime delay, hrt_abstime interval, hrt_callout callout, void *arg)
{
hrt_call_internal(entry,
hrt_absolute_time() + delay,
interval,
callout,
arg);
}
static void __attribute__((section(".iram1")))
hrt_call_internal(struct hrt_call *entry, hrt_abstime deadline, hrt_abstime interval, hrt_callout callout, void *arg)
{
irqstate_t flags = px4_enter_critical_section();
/* if the entry is currently queued, remove it */
/* note that we are using a potentially uninitialised
entry->link here, but it is safe as sq_rem() doesn't
dereference the passed node unless it is found in the
list. So we potentially waste a bit of time searching the
queue for the uninitialised entry->link but we don't do
anything actually unsafe.
*/
if (entry->deadline != 0) {
sq_rem(&entry->link, &callout_queue);
}
entry->deadline = deadline;
entry->period = interval;
entry->callout = callout;
entry->arg = arg;
hrt_call_enter(entry);
px4_leave_critical_section(flags);
}
/**
* If this returns true, the call has been invoked and removed from the callout list.
*
* Always returns false for repeating callouts.
*/
bool __attribute__((section(".iram1")))
hrt_called(struct hrt_call *entry)
{
return (entry->deadline == 0);
}
/**
* Remove the entry from the callout list.
*/
void __attribute__((section(".iram1")))
hrt_cancel(struct hrt_call *entry)
{
irqstate_t flags = px4_enter_critical_section();
sq_rem(&entry->link, &callout_queue);
entry->deadline = 0;
/* if this is a periodic call being removed by the callout, prevent it from
* being re-entered when the callout returns.
*/
entry->period = 0;
px4_leave_critical_section(flags);
}
static void __attribute__((section(".iram1")))
hrt_call_enter(struct hrt_call *entry)
{
struct hrt_call *call, *next;
call = (struct hrt_call *)sq_peek(&callout_queue);
if ((call == NULL) || (entry->deadline < call->deadline)) {
sq_addfirst(&entry->link, &callout_queue);
hrtinfo("call enter at head, reschedule\n");
/* we changed the next deadline, reschedule the timer event */
hrt_call_reschedule();
} else {
do {
next = (struct hrt_call *)sq_next(&call->link);
if ((next == NULL) || (entry->deadline < next->deadline)) {
hrtinfo("call enter after head\n");
sq_addafter(&call->link, &entry->link, &callout_queue);
break;
}
} while ((call = next) != NULL);
}
hrtinfo("scheduled\n");
}
static void __attribute__((section(".iram1")))
hrt_call_invoke(void)
{
struct hrt_call *call;
hrt_abstime deadline;
while (true) {
/* get the current time */
hrt_abstime now = hrt_absolute_time();
call = (struct hrt_call *)sq_peek(&callout_queue);
if (call == NULL) {
break;
}
if (call->deadline > now) {
break;
}
sq_rem(&call->link, &callout_queue);
hrtinfo("call pop\n");
/* save the intended deadline for periodic calls */
deadline = call->deadline;
/* zero the deadline, as the call has occurred */
call->deadline = 0;
/* invoke the callout (if there is one) */
if (call->callout) {
hrtinfo("call %p: %p(%p)\n", call, call->callout, call->arg);
call->callout(call->arg);
}
/* if the callout has a non-zero period, it has to be re-entered */
if (call->period != 0) {
// re-check call->deadline to allow for
// callouts to re-schedule themselves
// using hrt_call_delay()
if (call->deadline <= now) {
call->deadline = deadline + call->period;
}
hrt_call_enter(call);
}
}
}
/**
* Reschedule the next timer interrupt.
*
* This routine must be called with interrupts disabled.
*/
static void __attribute__((section(".iram1")))
hrt_call_reschedule()
{
hrt_abstime now = hrt_absolute_time();
struct hrt_call *next = (struct hrt_call *)sq_peek(&callout_queue);
hrt_abstime deadline = now + HRT_INTERVAL_MAX;
/*
* Determine what the next deadline will be.
*
* Note that we ensure that this will be within the counter
* period, so that when we truncate all but the low 16 bits
* the next time the compare matches it will be the deadline
* we want.
*
* It is important for accurate timekeeping that the compare
* interrupt fires sufficiently often that the base_time update in
* hrt_absolute_time runs at least once per timer period.
*/
if (next != NULL) {
hrtinfo("entry in queue\n");
if (next->deadline <= (now + HRT_INTERVAL_MIN)) {
hrtinfo("pre-expired\n");
/* set a minimal deadline so that we call ASAP */
deadline = now + HRT_INTERVAL_MIN;
} else if (next->deadline < deadline) {
hrtinfo("due soon\n");
deadline = next->deadline;
}
}
hrtinfo("schedule for %u at %u\n", (unsigned)(deadline & 0xffffffff), (unsigned)(now & 0xffffffff));
/* set the new compare value and remember it for latency tracking */
latency_baseline = deadline & 0xffff;
rALARMLO = (uint32_t)(deadline & 0xffffffff);
rALARMHI = (uint32_t)((deadline >> 32) & 0xffffffff);
}
static void
hrt_latency_update(void)
{
uint16_t latency = latency_actual - latency_baseline;
unsigned index;
/* bounded buckets */
for (index = 0; index < LATENCY_BUCKET_COUNT; index++) {
if (latency <= latency_buckets[index]) {
latency_counters[index]++;
return;
}
}
/* catch-all at the end */
latency_counters[index]++;
}
void __attribute__((section(".iram1")))
hrt_call_init(struct hrt_call *entry)
{
memset(entry, 0, sizeof(*entry));
}
void __attribute__((section(".iram1")))
hrt_call_delay(struct hrt_call *entry, hrt_abstime delay)
{
entry->deadline = hrt_absolute_time() + delay;
}
#endif /* HRT_TIMER */
@@ -0,0 +1,39 @@
/****************************************************************************
*
* Copyright (c) 2019 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 PX4 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.
*
****************************************************************************/
#pragma once
#include <board_config.h>
#define SYSTEM_ADC_BASE 0 // not used on kinetis
#include <px4_platform/adc.h>
@@ -0,0 +1,245 @@
/****************************************************************************
*
* Copyright (C) 2019 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 PX4 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.
*
****************************************************************************/
#pragma once
#include <stdint.h>
#include "hardware/esp32_tim.h"
#include "hardware/esp32_gpio.h"
#include "hardware/esp32_soc.h"
#include <px4_platform_common/constexpr_util.h>
/*
* Timers
*/
namespace Timer
{
enum Timer {
Timer0 = 0,
Timer1,
Timer2,
Timer3,
};
// These are actually the Operators
enum Channel {
Channel0 = 0,
Channel1,
Channel2,
Channel3,
Channel4,
Channel5,
Channel6,
Channel7
};
struct TimerChannel {
Timer timer;
Channel channel;
};
}
static inline constexpr uint32_t timerBaseRegister(Timer::Timer timer)
{
switch (timer) {
case Timer::Timer0: return DR_REG_PWM_BASE + 0x04;
case Timer::Timer1: return DR_REG_PWM1_BASE + 0x04;
case Timer::Timer2: return DR_REG_PWM1_BASE + 0x04;
case Timer::Timer3: return DR_REG_PWM1_BASE + 0x04;
}
return 0;
}
/*
* GPIO
*/
namespace GPIO
{
enum Pin {
Pin0 = 0,
Pin1,
Pin2,
Pin3,
Pin4,
Pin5,
Pin6,
Pin7,
Pin8,
Pin9,
Pin10,
Pin11,
Pin12,
Pin13,
Pin14,
Pin15,
Pin16,
Pin17,
Pin18,
Pin19,
Pin20,
Pin21,
Pin22,
Pin23,
Pin24,
Pin25,
Pin26,
Pin27,
Pin28,
Pin29,
Pin30,
Pin31,
Pin32,
Pin33,
Pin34,
Pin35,
Pin36,
Pin37,
Pin38,
};
struct GPIOPin {
Pin pin;
};
}
static inline constexpr uint32_t getGPIOPin(GPIO::Pin pin)
{
switch (pin) {
case GPIO::Pin0: return 0;
case GPIO::Pin1: return 1;
case GPIO::Pin2: return 2;
case GPIO::Pin3: return 3;
case GPIO::Pin4: return 4;
case GPIO::Pin5: return 5;
case GPIO::Pin6: return 6;
case GPIO::Pin7: return 7;
case GPIO::Pin8: return 8;
case GPIO::Pin9: return 9;
case GPIO::Pin10: return 10;
case GPIO::Pin11: return 11;
case GPIO::Pin12: return 12;
case GPIO::Pin13: return 13;
case GPIO::Pin14: return 14;
case GPIO::Pin15: return 15;
case GPIO::Pin16: return 16;
case GPIO::Pin17: return 17;
case GPIO::Pin18: return 18;
case GPIO::Pin19: return 19;
case GPIO::Pin20: return 20;
case GPIO::Pin21: return 21;
case GPIO::Pin22: return 22;
case GPIO::Pin23: return 23;
case GPIO::Pin24: return 24;
case GPIO::Pin25: return 25;
case GPIO::Pin26: return 26;
case GPIO::Pin27: return 27;
case GPIO::Pin28: return 28;
case GPIO::Pin29: return 29;
case GPIO::Pin30: return 30;
case GPIO::Pin31: return 31;
case GPIO::Pin32: return 32;
case GPIO::Pin33: return 33;
case GPIO::Pin34: return 34;
case GPIO::Pin35: return 35;
case GPIO::Pin36: return 36;
case GPIO::Pin37: return 37;
case GPIO::Pin38: return 38;
}
return 0;
}
namespace SPI
{
enum class Bus {
SPI1 = 1,
SPI2,
SPI3,
};
using CS = GPIO::GPIOPin; ///< chip-select pin
using DRDY = GPIO::GPIOPin; ///< data ready pin
struct bus_device_external_cfg_t {
CS cs_gpio;
DRDY drdy_gpio;
};
} // namespace SPI
@@ -0,0 +1,56 @@
/****************************************************************************
*
* Copyright (C) 2020 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 PX4 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.
*
****************************************************************************/
#pragma once
#include <px4_arch/hw_description.h>
#include <px4_platform_common/i2c.h>
#if defined(CONFIG_I2C)
static inline constexpr px4_i2c_bus_t initI2CBusInternal(int bus)
{
px4_i2c_bus_t ret{};
ret.bus = bus;
ret.is_external = false;
return ret;
}
static inline constexpr px4_i2c_bus_t initI2CBusExternal(int bus)
{
px4_i2c_bus_t ret{};
ret.bus = bus;
ret.is_external = true;
return ret;
}
#endif // CONFIG_I2C
@@ -0,0 +1,176 @@
/****************************************************************************
*
* Copyright (C) 2012, 2017 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 PX4 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 io_timer.h
*/
#include <px4_platform_common/px4_config.h>
#include <nuttx/arch.h>
#include <nuttx/irq.h>
#include <drivers/drv_hrt.h>
#pragma once
__BEGIN_DECLS
/* configuration limits */
#ifdef BOARD_NUM_IO_TIMERS
#define MAX_IO_TIMERS BOARD_NUM_IO_TIMERS
#else
#define MAX_IO_TIMERS 1
#endif
#if DIRECT_PWM_OUTPUT_CHANNELS > 8
#define MAX_TIMER_IO_CHANNELS DIRECT_PWM_OUTPUT_CHANNELS
#else
#define MAX_TIMER_IO_CHANNELS 8
#endif
#define MAX_LED_TIMERS 2
#define MAX_TIMER_LED_CHANNELS 6
#define MAX_SPIX_SYNC_TIMERS 2
#define MAX_TIMER_SPIX_SYNC_CHANNELS 2
#define IO_TIMER_ALL_MODES_CHANNELS 0
typedef enum io_timer_channel_mode_t {
IOTimerChanMode_NotUsed = 0,
IOTimerChanMode_PWMOut = 1,
IOTimerChanMode_PWMIn = 2,
IOTimerChanMode_Capture = 3,
IOTimerChanMode_OneShot = 4,
IOTimerChanMode_Trigger = 5,
IOTimerChanMode_Dshot = 6,
IOTimerChanMode_LED = 7,
IOTimerChanMode_PPS = 8,
IOTimerChanMode_Other = 9,
IOTimerChanModeSize
} io_timer_channel_mode_t;
typedef uint16_t io_timer_channel_allocation_t; /* big enough to hold MAX_TIMER_IO_CHANNELS */
/* array of timers dedicated to PWM in and out and capture use
*** Note that the clock_freq is set to the source in the clock tree that
*** feeds this specific timer. This can differs by Timer!
*** In PWM mode the timer's prescaler is set to achieve a counter frequency of 1MHz
*** In OneShot mode the timer's prescaler is set to achieve a counter frequency of 8MHz
*** Other prescaler rates can be achieved by fore instance by setting the clock_freq = 1Mhz
*** the resulting PSC will be one and the timer will count at it's clock frequency.
*/
typedef struct io_timers_t {
uint32_t base;
uint32_t clock_register;
uint32_t clock_bit;
uint32_t clock_freq;
uint32_t vectorno;
} io_timers_t;
typedef struct io_timers_channel_mapping_element_t {
uint32_t first_channel_index;
uint32_t channel_count;
uint32_t lowest_timer_channel;
uint32_t channel_count_including_gaps;
} io_timers_channel_mapping_element_t;
/* mapping for each io_timers to timer_io_channels */
typedef struct io_timers_channel_mapping_t {
io_timers_channel_mapping_element_t element[MAX_IO_TIMERS];
} io_timers_channel_mapping_t;
/* array of channels in logical order */
typedef struct timer_io_channels_t {
uint32_t gpio_out;
uint32_t gpio_in;
uint8_t timer_index;
uint8_t timer_channel;
uint16_t masks;
uint8_t ccr_offset;
} timer_io_channels_t;
typedef void (*channel_handler_t)(void *context, const io_timers_t *timer, uint32_t chan_index,
const timer_io_channels_t *chan,
hrt_abstime isrs_time, uint16_t isrs_rcnt);
/* supplied by board-specific code */
__EXPORT extern const io_timers_t io_timers[MAX_IO_TIMERS];
__EXPORT extern const io_timers_channel_mapping_t io_timers_channel_mapping;
__EXPORT extern const timer_io_channels_t timer_io_channels[MAX_TIMER_IO_CHANNELS];
__EXPORT extern const io_timers_t led_pwm_timers[MAX_LED_TIMERS];
__EXPORT extern const timer_io_channels_t led_pwm_channels[MAX_TIMER_LED_CHANNELS];
__EXPORT extern const io_timers_t spix_sync_timers[MAX_SPIX_SYNC_TIMERS];
__EXPORT extern const io_timers_channel_mapping_t spix_sync_channel_mapping;
__EXPORT extern const timer_io_channels_t spix_sync_channels[MAX_TIMER_SPIX_SYNC_CHANNELS];
__EXPORT int io_timer_channel_init(unsigned channel, io_timer_channel_mode_t mode,
channel_handler_t channel_handler, void *context);
__EXPORT int io_timer_init_timer(unsigned timer, io_timer_channel_mode_t mode);
__EXPORT int io_timer_set_pwm_rate(unsigned timer, unsigned rate);
__EXPORT int io_timer_set_enable(bool state, io_timer_channel_mode_t mode,
io_timer_channel_allocation_t masks);
__EXPORT uint16_t io_channel_get_ccr(unsigned channel);
__EXPORT int io_timer_set_ccr(unsigned channel, uint16_t value);
__EXPORT uint32_t io_timer_get_group(unsigned timer);
__EXPORT int io_timer_validate_channel_index(unsigned channel);
__EXPORT int io_timer_allocate_channel(unsigned channel, io_timer_channel_mode_t mode);
__EXPORT int io_timer_unallocate_channel(unsigned channel);
__EXPORT int io_timer_get_channel_mode(unsigned channel);
__EXPORT int io_timer_get_mode_channels(io_timer_channel_mode_t mode);
__EXPORT extern void io_timer_trigger(unsigned channels_mask);
__EXPORT void io_timer_update_dma_req(uint8_t timer, bool enable);
/**
* Reserve a timer
* @return 0 on success (if not used yet, or already set to the mode)
*/
__EXPORT int io_timer_allocate_timer(unsigned timer, io_timer_channel_mode_t mode);
__EXPORT int io_timer_unallocate_timer(unsigned timer);
__EXPORT extern int io_timer_set_dshot_mode(uint8_t timer, unsigned dshot_pwm_rate, uint8_t dma_burst_length);
/**
* Returns the pin configuration for a specific channel, to be used as GPIO output.
* 0 is returned if the channel is not valid.
*/
__EXPORT uint32_t io_timer_channel_get_gpio_output(unsigned channel);
/**
* Returns the pin configuration for a specific channel, to be used as PWM input.
* 0 is returned if the channel is not valid.
*/
__EXPORT uint32_t io_timer_channel_get_as_pwm_input(unsigned channel);
__END_DECLS
@@ -0,0 +1,170 @@
/****************************************************************************
*
* Copyright (C) 2019 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 PX4 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.
*
****************************************************************************/
#pragma once
#include <px4_arch/io_timer.h>
#include <px4_arch/hw_description.h>
#include <px4_platform_common/constexpr_util.h>
#include <px4_platform_common/px4_config.h>
#include <px4_platform/io_timer_init.h>
#include <esp32_tim.h>
#include <esp32_gpio.h>
// static inline constexpr timer_io_channels_t initIOTimerGPIOInOut(Timer::TimerChannel timer, GPIO::GPIOPin pin);
#define initIOTimerChannelCapture initIOTimerChannel // alias, used for param metadata generation
static inline constexpr timer_io_channels_t initIOTimerChannel(const io_timers_t io_timers_conf[MAX_IO_TIMERS],
Timer::TimerChannel timer, GPIO::GPIOPin pin)
{
timer_io_channels_t ret = {};
ret.gpio_out = getGPIOPin(pin.pin);
ret.timer_channel = timer.channel;
ret.timer_index = timer.timer;
bool nuttx_incorrect_mapping = false;
bool multiple_timers_configure = false;
bool timer_configured = false;
#if defined(CONFIG_ESP32_LEDC_TIM0_CHANNELS)
multiple_timers_configure = timer_configured;
timer_configured = true;
#endif
#if defined(CONFIG_ESP32_LEDC_TIM1_CHANNELS)
multiple_timers_configure = timer_configured;
timer_configured = true;
#endif
#if defined(CONFIG_ESP32_LEDC_TIM2_CHANNELS)
multiple_timers_configure = timer_configured;
timer_configured = true;
#endif
#if defined(CONFIG_ESP32_LEDC_TIM3_CHANNELS)
multiple_timers_configure = timer_configured;
timer_configured = true;
#endif
int channel = timer.channel;
switch (channel) {
case 0:
#if defined(CONFIG_ESP32_LEDC_CHANNEL0_PIN)
nuttx_incorrect_mapping = pin.pin == CONFIG_ESP32_LEDC_CHANNEL0_PIN;
#endif
break;
case 1:
#if defined(CONFIG_ESP32_LEDC_CHANNEL1_PIN)
nuttx_incorrect_mapping = pin.pin == CONFIG_ESP32_LEDC_CHANNEL1_PIN;
#endif
break;
case 2:
#if defined(CONFIG_ESP32_LEDC_CHANNEL2_PIN)
nuttx_incorrect_mapping = pin.pin == CONFIG_ESP32_LEDC_CHANNEL2_PIN;
#endif
break;
case 3:
#if defined(CONFIG_ESP32_LEDC_CHANNEL3_PIN)
nuttx_incorrect_mapping = pin.pin == CONFIG_ESP32_LEDC_CHANNEL3_PIN;
#endif
break;
default:
break;
}
constexpr_assert(nuttx_incorrect_mapping, "PX4 ChannelTimer Mapping different from Nuttx)");
constexpr_assert(!multiple_timers_configure, "Only a single timer can be configured in Nuttx");
return ret;
}
static inline constexpr timer_io_channels_t initIOTimerChannelOutputClear(const io_timers_t
io_timers_conf[MAX_IO_TIMERS], Timer::TimerChannel timer, GPIO::GPIOPin pin)
{
timer_io_channels_t ret = initIOTimerChannel(io_timers_conf, timer, pin);
ret.gpio_out |= 0;
return ret;
}
static inline constexpr io_timers_t initIOTimer(Timer::Timer timer)
{
bool nuttx_config_timer_enabled = false;
io_timers_t ret{};
switch (timer) {
case Timer::Timer0: // refers to MCPWM peripheral 1
ret.base = 0;
#if defined(CONFIG_ESP32_LEDC_TIM0)
nuttx_config_timer_enabled = true;
#endif
break;
case Timer::Timer1: // refers to MCPWM peripheral 2
ret.base = 1;
#if defined(CONFIG_ESP32_LEDC_TIM1)
nuttx_config_timer_enabled = true;
#endif
break;
case Timer::Timer2: // refers to MCPWM peripheral 2
ret.base = 2;
#if defined(CONFIG_ESP32_LEDC_TIM2)
nuttx_config_timer_enabled = true;
#endif
break;
case Timer::Timer3: // refers to MCPWM peripheral 2
ret.base = 4;
#if defined(CONFIG_ESP32_LEDC_TIM3)
nuttx_config_timer_enabled = true;
#endif
break;
default: break;
}
constexpr_assert(nuttx_config_timer_enabled,
"IO Timer requires NuttX timer config to be Enabled (CONFIG_ESP32_LEDC_TIMx)");
return ret;
}

Some files were not shown because too many files have changed in this diff Show More