2016-08-05 00:10:41 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2012-2016 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.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/**
|
2016-12-12 13:25:33 -10:00
|
|
|
* @file aerofc-v1_init.c
|
2016-08-05 00:10:41 +02:00
|
|
|
*
|
2016-12-12 13:25:33 -10:00
|
|
|
* aerofc-specific early startup code. This file implements the
|
|
|
|
|
* board_app_initialize() function that is called early by nsh during startup.
|
2016-08-05 00:10:41 +02:00
|
|
|
*
|
|
|
|
|
* Code here is run before the rcS script is invoked; it should start required
|
2016-12-12 13:25:33 -10:00
|
|
|
* subsystems and perform board-specific initialization.
|
2016-08-05 00:10:41 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Included Files
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2019-10-25 10:56:32 +02:00
|
|
|
#include <px4_platform_common/px4_config.h>
|
|
|
|
|
#include <px4_platform_common/tasks.h>
|
2016-08-05 00:10:41 +02:00
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
#include <stdio.h>
|
2016-12-12 13:25:33 -10:00
|
|
|
#include <string.h>
|
2016-08-05 00:10:41 +02:00
|
|
|
#include <debug.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
2016-12-12 13:25:33 -10:00
|
|
|
#include <nuttx/board.h>
|
2016-08-05 00:10:41 +02:00
|
|
|
#include <nuttx/analog/adc.h>
|
|
|
|
|
|
|
|
|
|
#include "board_config.h"
|
|
|
|
|
#include "stm32_uart.h"
|
|
|
|
|
|
|
|
|
|
#include <arch/board/board.h>
|
|
|
|
|
|
|
|
|
|
#include <drivers/drv_hrt.h>
|
2017-02-24 09:58:39 +01:00
|
|
|
#include <drivers/drv_board_led.h>
|
2016-08-05 00:10:41 +02:00
|
|
|
|
2017-03-08 15:39:40 -08:00
|
|
|
#include <dataman/dataman.h>
|
|
|
|
|
|
2016-12-12 13:25:33 -10:00
|
|
|
#include <systemlib/px4_macros.h>
|
2019-10-25 10:56:32 +02:00
|
|
|
#include <px4_platform_common/init.h>
|
2016-08-05 00:10:41 +02:00
|
|
|
|
|
|
|
|
# if defined(FLASH_BASED_PARAMS)
|
2018-04-11 15:10:51 -04:00
|
|
|
# include <parameters/flashparams/flashfs.h>
|
2016-08-05 00:10:41 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Pre-Processor Definitions
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Ideally we'd be able to get these from up_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
|
|
|
|
|
|
2017-07-24 14:15:44 -07:00
|
|
|
/****************************************************************************
|
|
|
|
|
* Private Functions
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2017-07-31 16:33:31 -10:00
|
|
|
static int _bootloader_force_pin_callback(int irq, void *context, void *args)
|
2017-07-24 14:15:44 -07:00
|
|
|
{
|
|
|
|
|
if (stm32_gpioread(GPIO_FORCE_BOOTLOADER)) {
|
|
|
|
|
board_reset(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-05 00:10:41 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
* Protected Functions
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Public Functions
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/************************************************************************************
|
|
|
|
|
* Name: stm32_boardinitialize
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* All STM32 architectures must provide the following entry point. This entry point
|
2017-07-24 14:15:44 -07:00
|
|
|
* is called early in the initialization -- after all memory has been configured
|
2016-08-05 00:10:41 +02:00
|
|
|
* and mapped but before any devices have been initialized.
|
|
|
|
|
*
|
|
|
|
|
************************************************************************************/
|
|
|
|
|
|
|
|
|
|
__EXPORT void stm32_boardinitialize(void)
|
|
|
|
|
{
|
2017-07-24 14:15:44 -07:00
|
|
|
stm32_configgpio(GPIO_FORCE_BOOTLOADER);
|
2017-07-31 16:33:31 -10:00
|
|
|
_bootloader_force_pin_callback(0, NULL, NULL);
|
2016-12-12 13:25:33 -10:00
|
|
|
|
2017-07-24 14:15:44 -07:00
|
|
|
/* configure LEDs */
|
2016-12-12 13:25:33 -10:00
|
|
|
board_autoled_initialize();
|
|
|
|
|
|
2016-09-08 19:52:43 -03:00
|
|
|
/* turn sensors on */
|
2016-12-09 16:32:19 -08:00
|
|
|
stm32_configgpio(GPIO_VDD_5V_SENSORS_EN);
|
2016-08-05 00:10:41 +02:00
|
|
|
|
|
|
|
|
/* configure SPI interfaces */
|
|
|
|
|
stm32_spiinitialize();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
2016-12-12 13:25:33 -10:00
|
|
|
* Name: board_app_initialize
|
2016-08-05 00:10:41 +02:00
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* Perform architecture specific initialization
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2016-12-12 13:25:33 -10:00
|
|
|
__EXPORT int board_app_initialize(uintptr_t arg)
|
2016-08-05 00:10:41 +02:00
|
|
|
{
|
|
|
|
|
int result;
|
|
|
|
|
|
2017-07-24 14:15:44 -07:00
|
|
|
/* the interruption subsystem is not initialized when stm32_boardinitialize() is called */
|
2017-07-31 16:33:31 -10:00
|
|
|
stm32_gpiosetevent(GPIO_FORCE_BOOTLOADER, true, false, false, _bootloader_force_pin_callback, NULL);
|
2017-07-24 14:15:44 -07:00
|
|
|
|
2019-01-22 14:13:20 -05:00
|
|
|
px4_platform_init();
|
2016-08-05 00:10:41 +02:00
|
|
|
|
|
|
|
|
/* set up the serial DMA polling */
|
|
|
|
|
static struct hrt_call serial_dma_call;
|
|
|
|
|
struct timespec ts;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Poll at 1ms intervals for received bytes that have not triggered
|
|
|
|
|
* a DMA event.
|
|
|
|
|
*/
|
|
|
|
|
ts.tv_sec = 0;
|
|
|
|
|
ts.tv_nsec = 1000000;
|
|
|
|
|
|
|
|
|
|
hrt_call_every(&serial_dma_call,
|
|
|
|
|
ts_to_abstime(&ts),
|
|
|
|
|
ts_to_abstime(&ts),
|
|
|
|
|
(hrt_callout)stm32_serial_dma_poll,
|
|
|
|
|
NULL);
|
|
|
|
|
|
2016-12-12 13:25:33 -10:00
|
|
|
|
2016-08-05 00:10:41 +02:00
|
|
|
/* initial LED state */
|
|
|
|
|
drv_led_start();
|
|
|
|
|
led_off(LED_AMBER);
|
|
|
|
|
led_off(LED_BLUE);
|
|
|
|
|
|
2016-10-27 18:59:13 -02:00
|
|
|
/*
|
2016-11-24 17:55:36 -02:00
|
|
|
* Bootloader(sector 0):
|
2016-10-27 18:59:13 -02:00
|
|
|
* start: 0x08000000, len: 16K, end: 0x08003E80
|
|
|
|
|
*
|
2016-11-24 17:55:36 -02:00
|
|
|
* FlashFS(sector 1 and 2):
|
2017-03-08 15:39:40 -08:00
|
|
|
* start: 0x08004000, len: 32K, end: 0x0800BFFF
|
2016-10-27 18:59:13 -02:00
|
|
|
*
|
2016-11-24 17:55:36 -02:00
|
|
|
* Firmware(sector 3 to 11):
|
2017-03-08 15:39:40 -08:00
|
|
|
* start: 0x0800C000, len: 976K, end: 0x080FFFFF
|
2016-10-27 18:59:13 -02:00
|
|
|
*
|
2017-03-08 15:39:40 -08:00
|
|
|
* Dataman(sector 23):
|
|
|
|
|
* start: 0x081E0000, len: 128K, end: 0x08200000
|
|
|
|
|
*
|
|
|
|
|
* First 1MB memory bank complete assigned.
|
|
|
|
|
* Second 1MB memory bank is mostly empty.
|
2016-10-27 18:59:13 -02:00
|
|
|
*/
|
2017-03-08 15:39:40 -08:00
|
|
|
|
|
|
|
|
#if defined(FLASH_BASED_PARAMS)
|
|
|
|
|
static sector_descriptor_t params_sector_map[] = {
|
2016-08-05 00:10:41 +02:00
|
|
|
{1, 16 * 1024, 0x08004000},
|
|
|
|
|
{2, 16 * 1024, 0x08008000},
|
|
|
|
|
{0, 0, 0},
|
|
|
|
|
};
|
|
|
|
|
|
2016-10-27 18:59:13 -02:00
|
|
|
/* Initialize the flashfs layer to use heap allocated memory */
|
2017-03-08 15:39:40 -08:00
|
|
|
result = parameter_flashfs_init(params_sector_map, NULL, 0);
|
2016-08-05 00:10:41 +02:00
|
|
|
|
|
|
|
|
if (result != OK) {
|
2019-01-22 11:23:29 -05:00
|
|
|
syslog(LOG_ERR, "[boot] FAILED to init params in FLASH %d\n", result);
|
2016-12-12 13:25:33 -10:00
|
|
|
led_on(LED_AMBER);
|
2016-08-05 00:10:41 +02:00
|
|
|
return -ENODEV;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-03-08 15:39:40 -08:00
|
|
|
#if defined(FLASH_BASED_DATAMAN)
|
|
|
|
|
static dm_sector_descriptor_t dm_sector_map = {23, 128 * 1024, 0x081E0000};
|
|
|
|
|
dm_flash_sector_description_set(&dm_sector_map);
|
|
|
|
|
#endif
|
|
|
|
|
|
2016-08-05 00:10:41 +02:00
|
|
|
return OK;
|
|
|
|
|
}
|