nxp_ucans32k146:Add Can Bootloader build

nxp_ucans32k146:Relocation for Bootloader

nxp_ucans32k146:can_boot enable CAN

nxp_ucans32k146:Save Space use Non Optimize memcpy

nxp_ucans32k146:Increase to 24K

nxp/ucans32k146:Canbootloader LED Driver

nxp_ucans32k146:Can bootloader shut down CAN

nxp_ucans32k146:Use NVMEEPROM for Paramaters

nxp_ucans32k146:Use bootloader AppDescriptor

px4 mtd:Support onchip emulated eeprom
This commit is contained in:
David Sidrane 2021-02-17 06:57:28 -08:00 committed by Lorenz Meier
parent 62c0c96749
commit dd3c3098f2
18 changed files with 921 additions and 63 deletions

View File

@ -30,14 +30,16 @@ sercon
#
ver all
#
# Set the parameter file if mtd starts successfully.
#
if mtd start
if mft query -q -k MTD -s MTD_PARAMETERS -v /fs/mtd_params
then
set PARAM_FILE /fs/mtd_params
fi
if mft query -q -k MTD -s MTD_PARAMETERS -v /dev/eeeprom0
then
set PARAM_FILE /dev/eeeprom0
fi
#
# Load parameters.
#

View File

@ -0,0 +1,13 @@
include (${CMAKE_CURRENT_LIST_DIR}/uavcan_board_identity)
px4_add_board(
PLATFORM nuttx
VENDOR nxp
MODEL ucans32k146
LABEL canbootloader
TOOLCHAIN arm-none-eabi
ARCHITECTURE cortex-m4
CONSTRAINED_MEMORY
DRIVERS
bootloaders
)

View File

@ -1,22 +1,4 @@
# UAVCAN boot loadable Module ID
set(uavcanblid_sw_version_major 0)
set(uavcanblid_sw_version_minor 1)
add_definitions(
-DAPP_VERSION_MAJOR=${uavcanblid_sw_version_major}
-DAPP_VERSION_MINOR=${uavcanblid_sw_version_minor}
)
set(uavcanblid_hw_version_major 1)
set(uavcanblid_hw_version_minor 0)
set(uavcanblid_name "\"org.nxp.ucans32k146\"")
add_definitions(
-DHW_UAVCAN_NAME=${uavcanblid_name}
-DHW_VERSION_MAJOR=${uavcanblid_hw_version_major}
-DHW_VERSION_MINOR=${uavcanblid_hw_version_minor}
)
include (${CMAKE_CURRENT_LIST_DIR}/uavcan_board_identity)
px4_add_board(
PLATFORM nuttx
@ -33,7 +15,7 @@ px4_add_board(
DRIVERS
#adc/board_adc
#barometer # all available barometer drivers
#bootloaders
bootloaders
#differential_pressure # all available differential pressure drivers
#distance_sensor # all available distance sensor drivers
#dshot
@ -63,10 +45,12 @@ px4_add_board(
i2cdetect
led_control
mixer
mtd
mft
#motor_ramp
#motor_test
#nshterm
#param
param
#perf
pwm
reboot

View File

@ -1,5 +1,5 @@
{
"board_id": 10000,
"board_id": 34,
"magic": "PX4FWv1",
"description": "Firmware for the ucans32k146 board",
"image": "",

View File

@ -0,0 +1,73 @@
#
# 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_ARCH_LOWPUTC is not set
# CONFIG_DEV_CONSOLE is not set
# CONFIG_SERIAL is not set
CONFIG_ARCH="arm"
CONFIG_ARCH_BOARD_CUSTOM=y
CONFIG_ARCH_BOARD_CUSTOM_DIR="../nuttx-config"
CONFIG_ARCH_BOARD_CUSTOM_DIR_RELPATH=y
CONFIG_ARCH_BOARD_CUSTOM_NAME="px4"
CONFIG_ARCH_CHIP="s32k1xx"
CONFIG_ARCH_CHIP_S32K146=y
CONFIG_ARCH_CHIP_S32K14X=y
CONFIG_ARCH_CHIP_S32K1XX=y
CONFIG_ARCH_INTERRUPTSTACK=4096
CONFIG_ARCH_SIZET_LONG=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_ARMV7M_USEBASEPRI=y
CONFIG_BINFMT_DISABLE=y
CONFIG_BOARDCTL_RESET=y
CONFIG_BOARD_LOOPSPERMSEC=3997
CONFIG_C99_BOOL8=y
CONFIG_CLOCK_MONOTONIC=y
CONFIG_DEBUG_FULLOPT=y
CONFIG_DEBUG_HARDFAULT_ALERT=y
CONFIG_DEBUG_SYMBOLS=y
CONFIG_DEFAULT_SMALL=y
CONFIG_DISABLE_MOUNTPOINT=y
CONFIG_DISABLE_MQUEUE=y
CONFIG_DISABLE_PTHREAD=y
CONFIG_EXPERIMENTAL=y
CONFIG_FDCLONE_DISABLE=y
CONFIG_FDCLONE_STDIO=y
CONFIG_HAVE_CXX=y
CONFIG_HAVE_CXXINITIALIZE=y
CONFIG_IDLETHREAD_STACKSIZE=4096
CONFIG_LIBC_FLOATINGPOINT=y
CONFIG_LIBC_LONG_LONG=y
CONFIG_LIBC_STRERROR=y
CONFIG_LIB_BOARDCTL=y
CONFIG_MAX_TASKS=0
CONFIG_NAME_MAX=0
CONFIG_NUNGET_CHARS=0
CONFIG_NXFONTS_DISABLE_16BPP=y
CONFIG_NXFONTS_DISABLE_1BPP=y
CONFIG_NXFONTS_DISABLE_24BPP=y
CONFIG_NXFONTS_DISABLE_2BPP=y
CONFIG_NXFONTS_DISABLE_32BPP=y
CONFIG_NXFONTS_DISABLE_4BPP=y
CONFIG_NXFONTS_DISABLE_8BPP=y
CONFIG_PREALLOC_TIMERS=0
CONFIG_PTHREAD_STACK_MIN=512
CONFIG_RAM_SIZE=126976
CONFIG_RAM_START=0x1fff0000
CONFIG_RAW_BINARY=y
CONFIG_SDCLONE_DISABLE=y
CONFIG_SIG_DEFAULT=y
CONFIG_SIG_SIGALRM_ACTION=y
CONFIG_SIG_SIGUSR1_ACTION=y
CONFIG_SIG_SIGUSR2_ACTION=y
CONFIG_STACK_COLORATION=y
CONFIG_START_DAY=30
CONFIG_START_MONTH=11
CONFIG_STDIO_DISABLE_BUFFERING=y
CONFIG_SYSLOG_DEFAULT=y
CONFIG_TASK_NAME_SIZE=0
CONFIG_USEC_PER_TICK=1000
CONFIG_USERMAIN_STACKSIZE=4096

View File

@ -54,6 +54,9 @@ CONFIG_LPUART1_SERIAL_CONSOLE=y
CONFIG_LPUART1_TXBUFSIZE=128
CONFIG_MAX_TASKS=16
CONFIG_MOTOROLA_SREC=y
CONFIG_MTD=y
CONFIG_MTD_PARTITION=y
CONFIG_MTD_PARTITION_NAMES=y
CONFIG_NET=y
CONFIG_NETDEV_IFINDEX=y
CONFIG_NET_CAN=y
@ -80,8 +83,7 @@ CONFIG_RAM_START=0x1fff0000
CONFIG_RAW_BINARY=y
CONFIG_RR_INTERVAL=200
CONFIG_RTC=y
# CONFIG_RTC_FREQUENCY=32768
# CONFIG_RTC_HIRES=y
CONFIG_S32K1XX_EEEPROM=y
CONFIG_S32K1XX_FLEXCAN0=y
CONFIG_S32K1XX_FLEXCAN1=y
CONFIG_S32K1XX_LPI2C0=y

View File

@ -0,0 +1,158 @@
/****************************************************************************
* nuttx-config/scripts/canbootloader_script.ld
*
* Copyright (C) 2021 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.
*
****************************************************************************/
/* The S32K146 has 1Mb of FLASH beginning at address 0x0000:0000 and
* 124Kb of SRAM beginning at address 0x1fff:0000 (plus 4Kb of FlexRAM)
*
* The on-chip RAM is split in two regions: SRAM_L and SRAM_U. The RAM is
* implemented such that the SRAM_L and SRAM_U ranges form a contiguous
* block in the memory map
*
* SRAM_L 1fff0000 - 1fffffff 64Kb
* SRAM_U 20000000 - 2000efff 60Kb
*/
/* 6 4Kib Sectors 24 Kib for the bootloader
* paramater storace is in eeprom (dflash)
*/
MEMORY
{
vflash (rx) : ORIGIN = 0x00000000, LENGTH = 1K
pflash (rx) : ORIGIN = 0x00000400, LENGTH = 16
pflash1 (rx) : ORIGIN = 0x00000410, LENGTH = 24K-(1K + 16)
dflash (rx) : ORIGIN = 0x10000000, LENGTH = 64K
sram (rwx) : ORIGIN = 0x1fff0000, LENGTH = 124K
}
OUTPUT_ARCH(arm)
EXTERN(_vectors)
EXTERN(g_flashcfg)
ENTRY(_stext)
SECTIONS
{
.vectors :
{
_stext = ABSOLUTE(.);
*(.vectors)
} > vflash
.flashcfg :
{
*(.flashcfg)
} > pflash
.text :
{
*(.text .text.*)
*(.fixup)
*(.gnu.warning)
*(.rodata .rodata.*)
*(.gnu.linkonce.t.*)
*(.glue_7)
*(.glue_7t)
*(.got)
*(.gcc_except_table)
*(.gnu.linkonce.r.*)
_etext = ABSOLUTE(.);
} > pflash1
.init_section :
{
_sinit = ABSOLUTE(.);
KEEP(*(.init_array .init_array.*))
_einit = ABSOLUTE(.);
} > pflash1
.ARM.extab :
{
*(.ARM.extab*)
} >pflash1
.ARM.exidx :
{
__exidx_start = ABSOLUTE(.);
*(.ARM.exidx*)
__exidx_end = ABSOLUTE(.);
} >pflash1
.data :
{
_sdata = ABSOLUTE(.);
*(.data .data.*)
*(.gnu.linkonce.d.*)
CONSTRUCTORS
. = ALIGN(4);
_edata = ABSOLUTE(.);
} > sram AT > pflash1
_eronly = LOADADDR(.data);
.ramfunc ALIGN(4):
{
_sramfuncs = ABSOLUTE(.);
*(.ramfunc .ramfunc.*)
_eramfuncs = ABSOLUTE(.);
} > sram AT > pflash1
_framfuncs = LOADADDR(.ramfunc);
.bss :
{
_sbss = ABSOLUTE(.);
*(.bss .bss.*)
*(.gnu.linkonce.b.*)
*(COMMON)
. = ALIGN(4);
_ebss = ABSOLUTE(.);
} > sram
/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_info 0 : { *(.debug_info) }
.debug_line 0 : { *(.debug_line) }
.debug_pubnames 0 : { *(.debug_pubnames) }
.debug_aranges 0 : { *(.debug_aranges) }
}

View File

@ -44,17 +44,24 @@
* SRAM_U 20000000 - 2000efff 60Kb
*/
/* 6 4Kib Sectors 24 Kib for the bootloader
* paramater storace is in eeprom (dflash)
*/
MEMORY
{
vflash (rx) : ORIGIN = 0x00000000, LENGTH = 1K
pflash (rx) : ORIGIN = 0x00000400, LENGTH = 16
dflash (rx) : ORIGIN = 0x00000410, LENGTH = 1023K-16
sram (rwx) : ORIGIN = 0x1fff0000, LENGTH = 124K
vflash (rx) : ORIGIN = 0x00006000, LENGTH = 1K
pflash (rx) : ORIGIN = 0x00006400, LENGTH = 16
pflash1 (rx) : ORIGIN = 0x00006410, LENGTH = 1024K-(24K + 1K + 16)
dflash (rx) : ORIGIN = 0x10000000, LENGTH = 64K
sram (rwx) : ORIGIN = 0x1fff0000, LENGTH = 124K
}
OUTPUT_ARCH(arm)
EXTERN(_vectors)
EXTERN(g_flashcfg)
EXTERN(board_get_manifest)
ENTRY(_stext)
SECTIONS
@ -62,7 +69,7 @@ SECTIONS
.vectors :
{
_stext = ABSOLUTE(.);
*(.vectors)
KEEP(*(.vectors))
} > vflash
.flashcfg :
@ -72,6 +79,15 @@ SECTIONS
.text :
{
. = ALIGN(8);
/*
* This section positions the app_descriptor_t used
* by the make_can_boot_descriptor.py tool to set
* the application image's descriptor so that the
* uavcan bootloader has the ability to validate the
* image crc, size etc
*/
KEEP(*(.app_descriptor))
*(.text .text.*)
*(.fixup)
*(.gnu.warning)
@ -83,27 +99,29 @@ SECTIONS
*(.gcc_except_table)
*(.gnu.linkonce.r.*)
_etext = ABSOLUTE(.);
} > dflash
. = ALIGN(8);
FILL(0xff)
. += 8;
} > pflash1 = 0xff
.init_section :
{
_sinit = ABSOLUTE(.);
KEEP(*(.init_array .init_array.*))
_einit = ABSOLUTE(.);
} > dflash
} > pflash1
.ARM.extab :
{
*(.ARM.extab*)
} >dflash
} >pflash1
.ARM.exidx :
{
__exidx_start = ABSOLUTE(.);
*(.ARM.exidx*)
__exidx_end = ABSOLUTE(.);
} >dflash
} >pflash1
.data :
{
@ -113,7 +131,10 @@ SECTIONS
CONSTRUCTORS
. = ALIGN(4);
_edata = ABSOLUTE(.);
} > sram AT > dflash
. = ALIGN(8);
FILL(0xff)
. += 8;
} > sram AT > pflash1 = 0xff
_eronly = LOADADDR(.data);
@ -122,7 +143,10 @@ SECTIONS
_sramfuncs = ABSOLUTE(.);
*(.ramfunc .ramfunc.*)
_eramfuncs = ABSOLUTE(.);
} > sram AT > dflash
. = ALIGN(8);
FILL(0xff)
. += 8;
} > sram AT > pflash1 = 0xff
_framfuncs = LOADADDR(.ramfunc);

View File

@ -30,26 +30,49 @@
# POSSIBILITY OF SUCH DAMAGE.
#
############################################################################
if("${PX4_BOARD_LABEL}" STREQUAL "canbootloader")
add_library(drivers_board
autoleds.c
boot.c
bringup.c
buttons.c
clockconfig.c
# i2c.cpp # TODO
init.c
periphclocks.c
spi.c
timer_config.cpp
userleds.c
)
target_link_libraries(drivers_board
PRIVATE
nuttx_arch # sdio
nuttx_drivers # sdio
drivers__led # drv_led_start
px4_layer
arch_io_pins
add_library(drivers_board
can_boot.c
led.cpp
clockconfig.c
periphclocks.c
timer_config.cpp
)
target_link_libraries(drivers_board
PRIVATE
nuttx_arch
nuttx_drivers
canbootloader
arch_io_pins
arch_led_pwm
)
target_include_directories(drivers_board PRIVATE ${PX4_SOURCE_DIR}/platforms/nuttx/src/canbootloader)
else()
add_library(drivers_board
autoleds.c
boot.c
bringup.c
buttons.c
clockconfig.c
# i2c.cpp # TODO
init.c
mtd.cpp
periphclocks.c
spi.c
timer_config.cpp
userleds.c
)
target_link_libraries(drivers_board
PRIVATE
nuttx_arch # sdio
nuttx_drivers # sdio
drivers__led # drv_led_start
px4_layer
arch_io_pins
)
endif()

View File

@ -0,0 +1,128 @@
/****************************************************************************
*
* 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 boot_config.h
*
* bootloader definitions that configures the behavior and options
* of the Boot loader
* This file is relies on the parent folder's boot_config.h file and defines
* different usages of the hardware for bootloading
*/
#pragma once
/************************************************************************************
* Included Files
************************************************************************************/
/* Bring in the board_config.h definitions
* todo:make this be pulled in from a targed's build
* files in nuttx*/
#include "board_config.h"
#include "uavcan.h"
#include <nuttx/compiler.h>
#include <stdint.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define OPT_PREFERRED_NODE_ID ANY_NODE_ID
//todo:wrap OPT_x in in ifdefs for command line definitions
#define OPT_TBOOT_MS 5000
#define OPT_NODE_STATUS_RATE_MS 800
#define OPT_NODE_INFO_RATE_MS 50
#define OPT_BL_NUMBER_TIMERS 7
#undef S_RGB_LED_DMA // use the poled one
/*
* This Option set is set to 1 ensure a provider of firmware has an
* opportunity update the node's firmware.
* This Option is the default policy and can be overridden by
* a jumper
* When this Policy is set, the node will ignore tboot and
* wait indefinitely for a GetNodeInfo request before booting.
*
* OPT_WAIT_FOR_GETNODEINFO_JUMPER_GPIO_INVERT is used to allow
* the polarity of the jumper to be True Active
*
* wait OPT_WAIT_FOR_GETNODEINFO OPT_WAIT_FOR_GETNODEINFO_JUMPER_GPIO
* Jumper
* yes 1 0 x
* yes 1 1 Active
* no 1 1 Not Active
* no 0 0 X
* yes 0 1 Active
* no 0 1 Not Active
*
*/
#define OPT_WAIT_FOR_GETNODEINFO 0
#define OPT_WAIT_FOR_GETNODEINFO_JUMPER_GPIO 1
#define OPT_WAIT_FOR_GETNODEINFO_JUMPER_GPIO_INVERT 0
#define OPT_ENABLE_WD 1
#define OPT_RESTART_TIMEOUT_MS 20000
/* Reserved for the Booloader */
#define OPT_BOOTLOADER_SIZE_IN_K (24 * 1024)
/* Reserved for the application out of the total
* system flash minus the BOOTLOADER_SIZE_IN_K
*/
#define OPT_APPLICATION_RESERVER_IN_K (0)
#define OPT_APPLICATION_IMAGE_OFFSET OPT_BOOTLOADER_SIZE_IN_K
#define OPT_APPLICATION_IMAGE_LENGTH (FLASH_SIZE-(OPT_BOOTLOADER_SIZE_IN_K + OPT_APPLICATION_RESERVER_IN_K))
#define FLASH_BASE 0
#define FLASH_SIZE (1024*1024)
#define APPLICATION_LOAD_ADDRESS (FLASH_BASE + OPT_APPLICATION_IMAGE_OFFSET)
#define APPLICATION_SIZE (FLASH_SIZE-OPT_APPLICATION_IMAGE_OFFSET)
#define APPLICATION_LAST_8BIT_ADDRRESS ((uint8_t *)((APPLICATION_LOAD_ADDRESS+APPLICATION_SIZE)-sizeof(uint8_t)))
#define APPLICATION_LAST_32BIT_ADDRRESS ((uint32_t *)((APPLICATION_LOAD_ADDRESS+APPLICATION_SIZE)-sizeof(uint32_t)))
#define APPLICATION_LAST_64BIT_ADDRRESS ((uint64_t *)((APPLICATION_LOAD_ADDRESS+APPLICATION_SIZE)-sizeof(uint64_t)))
#define OPT_USE_YIELD
#define OPT_LATER_FLAHSED_WORDS 2
/* Bootloader Option*****************************************************************
*
*/
#define GPIO_GETNODEINFO_JUMPER (PIN_PTC14)

View File

@ -57,6 +57,10 @@
# include "s32k1xx_lpi2c.h"
#endif
#ifdef CONFIG_S32K1XX_EEEPROM
# include "s32k1xx_eeeprom.h"
#endif
#include "board_config.h"
/****************************************************************************
@ -114,6 +118,12 @@ int s32k1xx_bringup(void)
#endif
#ifdef CONFIG_S32K1XX_EEEPROM
/* Register EEEPROM block device */
s32k1xx_eeeprom_register(0, 4096);
#endif
#ifdef CONFIG_S32K1XX_LPSPI
/* Configure SPI chip selects if 1) SPI is not disabled, and 2) the weak
* function s32k1xx_spidev_initialize() has been brought into the link.
@ -141,6 +151,5 @@ int s32k1xx_bringup(void)
#endif
#endif
return ret;
}

View File

@ -0,0 +1,214 @@
/****************************************************************************
*
* Copyright (c) 2021 PX4 Development Team. All rights reserved.
* Author: David Sidrane <david.sidrane@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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <px4_config.h>
#include <stdint.h>
#include "boot_config.h"
#include "board.h"
#include "led.h"
#include <debug.h>
#include <string.h>
#include <arch/board/board.h>
#include <nuttx/board.h>
#include "s32k1xx_periphclocks.h"
#include "s32k1xx_flexcan.h"
/************************************************************************************
* Name: stm32_boardinitialize
*
* Description:
* All STM32 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 s32k1xx_board_initialize(void)
{
struct peripheral_clock_config_s c;
c.clkname = FLEXCAN0_CLK,
c.clkgate = true,
// CAN clocking
s32k1xx_periphclocks(1, &c);
// Can GPIO
s32k1xx_pinconfig(PIN_CAN0_TX);
s32k1xx_pinconfig(PIN_CAN0_RX);
s32k1xx_pinconfig(PIN_CAN0_ENABLE | GPIO_OUTPUT_ZERO);
//s32k1xx_gpiowrite
#if defined(OPT_WAIT_FOR_GETNODEINFO_JUMPER_GPIO)
s32k1xx_pinconfig(GPIO_GETNODEINFO_JUMPER);
#endif
ucans32k_timer_initialize();
}
/************************************************************************************
* Name: stm32_boarddeinitialize
*
* Description:
* This function is called by the bootloader code prior to booting
* the application. Is should place the HW into an benign initialized state.
*
************************************************************************************/
void stm32_boarddeinitialize(void)
{
uint32_t regval = getreg32(S32K1XX_CAN0_MCR);
regval |= CAN_MCR_MDIS;
putreg32(regval, S32K1XX_CAN0_MCR);
do {
regval = getreg32(S32K1XX_CAN0_MCR);
up_udelay(10);
} while ((regval & CAN_MCR_LPMACK) == 0);
s32k1xx_pinconfig(PIN_CAN0_ENABLE | GPIO_OUTPUT_ONE);
}
/****************************************************************************
* Name: board_get_product_name
*
* Description:
* Called to retrieve the product name. The returned value is a assumed
* to be written to a pascal style string that will be length prefixed
* and not null terminated
*
* Input Parameters:
* product_name - A pointer to a buffer to write the name.
* maxlen - The maximum number of charter that can be written
*
* Returned Value:
* The length of characters written to the buffer.
*
****************************************************************************/
uint8_t board_get_product_name(uint8_t *product_name, size_t maxlen)
{
DEBUGASSERT(maxlen > UAVCAN_STRLEN(HW_UAVCAN_NAME));
memcpy(product_name, HW_UAVCAN_NAME, UAVCAN_STRLEN(HW_UAVCAN_NAME));
return UAVCAN_STRLEN(HW_UAVCAN_NAME);
}
/****************************************************************************
* Name: board_get_hardware_version
*
* Description:
* Called to retrieve the hardware version information. The function
* will first initialize the the callers struct to all zeros.
*
* Input Parameters:
* hw_version - A pointer to a uavcan_hardwareversion_t.
*
* Returned Value:
* Length of the unique_id
*
****************************************************************************/
size_t board_get_hardware_version(uavcan_HardwareVersion_t *hw_version)
{
memset(hw_version, 0, sizeof(uavcan_HardwareVersion_t));
hw_version->major = HW_VERSION_MAJOR;
hw_version->minor = HW_VERSION_MINOR;
return board_get_mfguid(*(mfguid_t *) hw_version->unique_id);
}
/****************************************************************************
* Name: board_indicate
*
* Description:
* Provides User feedback to indicate the state of the bootloader
* on board specific hardware.
*
* Input Parameters:
* indication - A member of the uiindication_t
*
* Returned Value:
* None
*
****************************************************************************/
#define led(n, code, r , g , b, h) {.red = (r),.green = (g), .blue = (b),.hz = (h)}
typedef begin_packed_struct struct led_t {
uint16_t red : 5;
uint16_t green : 6;
uint16_t blue : 5;
uint8_t hz;
} end_packed_struct led_t;
static const led_t i2l[] = {
led(0, off, 0, 0, 0, 0),
led(1, reset, 10, 63, 31, 255),
led(2, autobaud_start, 0, 63, 0, 1),
led(3, autobaud_end, 0, 63, 0, 2),
led(4, allocation_start, 0, 0, 31, 2),
led(5, allocation_end, 0, 63, 31, 3),
led(6, fw_update_start, 15, 63, 31, 3),
led(7, fw_update_erase_fail, 15, 63, 15, 3),
led(8, fw_update_invalid_response, 31, 0, 0, 1),
led(9, fw_update_timeout, 31, 0, 0, 2),
led(a, fw_update_invalid_crc, 31, 0, 0, 4),
led(b, jump_to_app, 0, 63, 0, 10),
};
void board_indicate(uiindication_t indication)
{
rgb_led(i2l[indication].red << 3,
i2l[indication].green << 2,
i2l[indication].blue << 3,
i2l[indication].hz);
}
#include <drivers/drv_watchdog.h>
// Stubs
void watchdog_init(void)
{
}
void watchdog_pet(void)
{
}

View File

@ -0,0 +1,94 @@
/****************************************************************************
*
* Copyright (C) 2021 PX4 Development Team. All rights reserved.
* 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.
*
****************************************************************************/
#include <px4_config.h>
#include <stdint.h>
#include <stdbool.h>
#include <arch/board/board.h>
#include "led.h"
#include <drivers/drv_pwm_output.h>
#include <px4_arch/io_timer.h>
#include "s32k1xx_pin.h"
#include "hardware/s32k1xx_ftm.h"
#define REG(offset) (*(volatile uint32_t *)(S32K1XX_FTM0_BASE + (offset)))
#define rSC() REG(S32K1XX_FTM_SC_OFFSET)
#define rCNT() REG(S32K1XX_FTM_CNT_OFFSET)
#define rMOD() REG(S32K1XX_FTM_MOD_OFFSET)
#define FTM_SRC_CLOCK_FREQ 8000000
#define LED_PWM_FREQ 1000000
extern int led_pwm_servo_set(unsigned channel, uint8_t value);
extern int led_pwm_servo_init(void);
void rgb_led(int r, int g, int b, int freqs)
{
long fosc = FTM_SRC_CLOCK_FREQ;
long prescale = 128;
long p1s = fosc / prescale;
long p0p5s = p1s / 2;
long p = freqs == 0 ? p1s : p1s / freqs;
static bool once = false;
if (!once) {
once = true;
led_pwm_servo_init();
}
irqstate_t flags = px4_enter_critical_section();
uint32_t save = rSC();
rSC() = save & ~(FTM_SC_CLKS_MASK);
rMOD() = p;
rSC() = save | FTP_SC_PS_DIV128;
px4_leave_critical_section(flags);
p = freqs == 0 ? p1s + 1 : p0p5s / freqs;
led_pwm_servo_set(0, r * p);
led_pwm_servo_set(1, g * p);
led_pwm_servo_set(2, b * p);
if (freqs == 0) {
rSC() |= FTM_SC_CLKS_DIS;
} else {
rSC() &= ~FTM_SC_CLKS_DIS;
}
}

View File

@ -0,0 +1,37 @@
/****************************************************************************
*
* Copyright (C) 2021 PX4 Development Team. All rights reserved.
* 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.
*
****************************************************************************/
__BEGIN_DECLS
void rgb_led(int r, int g, int b, int freqs);
__END_DECLS

View File

@ -0,0 +1,75 @@
/****************************************************************************
*
* 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 <nuttx/spi/spi.h>
#include <px4_platform_common/px4_manifest.h>
// KiB BS nB
static const px4_mft_device_t eerom = { // Emulated EEPROB 4K
.bus_type = px4_mft_device_t::ONCHIP,
};
static const px4_mtd_entry_t fmum_eeprom = {
.device = &eerom,
.npart = 1,
.partd = {
{
.type = MTD_PARAMETERS,
.path = "/dev/eeeprom0",
.nblocks = 1
}
},
};
static const px4_mtd_manifest_t board_mtd_config = {
.nconfigs = 1,
.entries = {
&fmum_eeprom
}
};
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;
}

View File

@ -0,0 +1,17 @@
# UAVCAN boot loadable Module ID
set(uavcanblid_sw_version_major 0)
set(uavcanblid_sw_version_minor 1)
add_definitions(
-DAPP_VERSION_MAJOR=${uavcanblid_sw_version_major}
-DAPP_VERSION_MINOR=${uavcanblid_sw_version_minor}
)
set(uavcanblid_hw_version_major 0)
set(uavcanblid_hw_version_minor 34)
set(uavcanblid_name "\"org.nxp.ucans32k146\"")
add_definitions(
-DHW_UAVCAN_NAME=${uavcanblid_name}
-DHW_VERSION_MAJOR=${uavcanblid_hw_version_major}
-DHW_VERSION_MINOR=${uavcanblid_hw_version_minor}
)

View File

@ -48,6 +48,7 @@ typedef struct {
enum px4_bus_type {
I2C = 0,
SPI = 1,
ONCHIP = 2,
} bus_type;
uint32_t devid;

View File

@ -334,8 +334,12 @@ memoryout:
if (mtd_list->entries[i]->device->bus_type == px4_mft_device_t::I2C) {
rv = at24xxx_attach(instances[i]);
} else {
} else if (mtd_list->entries[i]->device->bus_type == px4_mft_device_t::SPI) {
rv = ramtron_attach(instances[i]);
} else if (mtd_list->entries[i]->device->bus_type == px4_mft_device_t::ONCHIP) {
instances[i].n_partitions_current++;
return 0;
}
if (rv != 0) {