nuttx/boards/arm/stm32/olimex-stm32-h407/src/stm32_bringup.c
Xiang Xiao c628529e2d arch/arm: Remove FAR and CODE from board folder(3)
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-05-03 16:50:52 +03:00

172 lines
4.3 KiB
C

/****************************************************************************
* boards/arm/stm32/olimex-stm32-h407/src/stm32_bringup.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 <stdio.h>
#include <syslog.h>
#include <errno.h>
#include <nuttx/board.h>
#ifdef CONFIG_USBMONITOR
# include <nuttx/usb/usbmonitor.h>
#endif
#ifdef CONFIG_STM32_OTGFS
# include "stm32_usbhost.h"
#endif
#include "stm32.h"
#include "olimex-stm32-h407.h"
/* Conditional logic in olimex-stm32-h407.h will determine if certain
* features are supported.
* Tests for these features need to be made after including
* olimex-stm32-h407.h.
*/
#ifdef HAVE_RTC_DRIVER
# include <nuttx/timers/rtc.h>
# include "stm32_rtc.h"
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: stm32_bringup
*
* Description:
* Perform architecture specific initialization
*
* CONFIG_BOARDCTL=y:
* If CONFIG_NSH_ARCHINITIALIZE=y:
* Called from the NSH library (or other application)
* Otherse, assumed to be called from some other application.
*
* Otherwise CONFIG_BOARD_LATE_INITIALIZE=y:
* Called from board_late_initialize().
*
* Otherwise, bad news: Never called
*
****************************************************************************/
int stm32_bringup(void)
{
#ifdef HAVE_RTC_DRIVER
struct rtc_lowerhalf_s *lower;
#endif
int ret;
#ifdef CONFIG_STM32_CAN_CHARDRIVER
/* Initialize CAN and register the CAN driver. */
ret = stm32_can_setup();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: stm32_can_setup failed: %d\n", ret);
}
#endif
#ifdef CONFIG_ADC
/* Initialize ADC and register the ADC driver. */
ret = stm32_adc_setup();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: stm32_adc_setup failed: %d\n", ret);
}
#endif
#ifdef HAVE_SDIO
/* Initialize the SDIO block driver */
ret = stm32_sdio_initialize();
if (ret != OK)
{
syslog(LOG_ERR,
"ERROR: Failed to initialize MMC/SD driver: %d\n",
ret);
}
#endif
#ifdef HAVE_USBHOST
/* Initialize USB host operation.
* stm32_usbhost_initialize() starts a thread will monitor for USB
* connection and disconnection events.
*/
ret = stm32_usbhost_initialize();
if (ret != OK)
{
syslog(LOG_ERR,
"ERROR: Failed to initialize USB host: %d\n",
ret);
}
#endif
#ifdef HAVE_USBMONITOR
/* Start the USB Monitor */
ret = usbmonitor_start();
if (ret != OK)
{
syslog(LOG_ERR,
"ERROR: Failed to start USB monitor: %d\n",
ret);
}
#endif
#ifdef HAVE_RTC_DRIVER
/* Instantiate the STM32 lower-half RTC driver */
lower = stm32_rtc_lowerhalf();
if (!lower)
{
syslog(LOG_ERR,
"ERROR: Failed to instantiate the RTC lower-half driver\n");
}
else
{
/* Bind the lower half driver and register the combined RTC driver
* as /dev/rtc0
*/
ret = rtc_initialize(0, lower);
if (ret < 0)
{
syslog(LOG_ERR,
"ERROR: Failed to bind/register the RTC driver: %d\n",
ret);
}
}
#endif
UNUSED(ret);
return OK;
}