2017-05-04 14:45:37 +03:00
|
|
|
/****************************************************************************
|
2019-08-19 15:16:08 +00:00
|
|
|
* boards/arm/stm32l4/nucleo-l452re/src/stm32_bringup.c
|
2017-05-04 14:45:37 +03:00
|
|
|
*
|
2018-05-15 17:17:20 -06:00
|
|
|
* Copyright (C) 2017-2018 Gregory Nutt. All rights reserved.
|
2017-05-04 14:45:37 +03:00
|
|
|
* 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 <sys/types.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
2018-05-15 06:55:21 -06:00
|
|
|
#include <nuttx/input/buttons.h>
|
2017-05-04 14:45:37 +03:00
|
|
|
#include <nuttx/i2c/i2c_master.h>
|
2018-05-15 06:55:21 -06:00
|
|
|
#include <nuttx/leds/userled.h>
|
|
|
|
#include <nuttx/board.h>
|
2021-02-15 16:08:51 +08:00
|
|
|
#include <nuttx/fs/fs.h>
|
2018-05-15 06:55:21 -06:00
|
|
|
|
2017-05-04 14:45:37 +03:00
|
|
|
#include "stm32l4_i2c.h"
|
|
|
|
#include "nucleo-l452re.h"
|
|
|
|
|
2018-05-15 17:17:20 -06:00
|
|
|
#include <arch/board/board.h>
|
|
|
|
|
2017-05-04 14:45:37 +03:00
|
|
|
/****************************************************************************
|
2017-08-25 07:02:21 -06:00
|
|
|
* Pre-processor Definitions
|
2017-05-04 14:45:37 +03:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#undef HAVE_I2C_DRIVER
|
|
|
|
#if defined(CONFIG_STM32L4_I2C1) && defined(CONFIG_I2C_DRIVER)
|
|
|
|
# define HAVE_I2C_DRIVER 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: stm32_bringup
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Perform architecture-specific initialization
|
|
|
|
*
|
2019-02-18 15:32:00 -06:00
|
|
|
* CONFIG_BOARD_LATE_INITIALIZE=y :
|
|
|
|
* Called from board_late_initialize().
|
2017-05-04 14:45:37 +03:00
|
|
|
*
|
2019-02-18 15:32:00 -06:00
|
|
|
* CONFIG_BOARD_LATE_INITIALIZE=n && CONFIG_LIB_BOARDCTL=y :
|
2017-05-04 14:45:37 +03:00
|
|
|
* Called from the NSH library
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int stm32_bringup(void)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_I2C_DRIVER
|
|
|
|
FAR struct i2c_master_s *i2c;
|
|
|
|
#endif
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
#ifdef CONFIG_FS_PROCFS
|
|
|
|
/* Mount the procfs file system */
|
|
|
|
|
2021-02-15 16:08:51 +08:00
|
|
|
ret = nx_mount(NULL, "/proc", "procfs", 0, NULL);
|
2017-05-04 14:45:37 +03:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
ferr("ERROR: Failed to mount procfs at /proc: %d\n", ret);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-05-15 06:55:21 -06:00
|
|
|
#ifdef CONFIG_BUTTONS
|
|
|
|
#ifdef CONFIG_BUTTONS_LOWER
|
|
|
|
iinfo("Initializing button driver\n");
|
|
|
|
|
|
|
|
/* Register the BUTTON driver */
|
|
|
|
|
|
|
|
ret = btn_lower_initialize("/dev/buttons");
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
ierr("ERROR: btn_lower_initialize() failed: %d\n", ret);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
/* Enable BUTTON support for some other purpose */
|
|
|
|
|
|
|
|
board_button_initialize();
|
|
|
|
#endif
|
|
|
|
#endif /* CONFIG_BUTTONS */
|
|
|
|
|
2017-05-04 14:45:37 +03:00
|
|
|
#ifdef HAVE_I2C_DRIVER
|
|
|
|
/* Get the I2C lower half instance */
|
|
|
|
|
|
|
|
i2c = stm32l4_i2cbus_initialize(1);
|
|
|
|
if (i2c == NULL)
|
|
|
|
{
|
|
|
|
i2cerr("ERROR: Initialize I2C1: %d\n", ret);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Register the I2C character driver */
|
|
|
|
|
|
|
|
ret = i2c_register(i2c, 1);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
i2cerr("ERROR: Failed to register I2C1 device: %d\n", ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-08-30 11:40:58 +03:00
|
|
|
#ifdef CONFIG_DAC
|
2017-08-30 07:05:30 -06:00
|
|
|
ainfo("Initializing DAC\n");
|
2017-08-30 11:40:58 +03:00
|
|
|
|
2020-01-02 10:49:34 -06:00
|
|
|
stm32l4_dac_setup();
|
2017-08-30 11:40:58 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_ADC
|
2017-08-30 07:05:30 -06:00
|
|
|
ainfo("Initializing ADC\n");
|
2017-08-30 11:40:58 +03:00
|
|
|
|
2020-01-02 10:49:34 -06:00
|
|
|
stm32l4_adc_setup();
|
2017-08-30 11:40:58 +03:00
|
|
|
#endif
|
|
|
|
|
2017-05-04 14:45:37 +03:00
|
|
|
UNUSED(ret);
|
|
|
|
return OK;
|
|
|
|
}
|