Junbo-Zheng commented on code in PR #21541: URL: https://github.com/apache/nuttx/pull/21541#discussion_r4509601070
########## boards/xtensa/esp32/esp32-m5-stickc-plus/src/esp32_bm8563.c: ########## @@ -0,0 +1,98 @@ +/**************************************************************************** + * boards/xtensa/esp32/esp32-m5-stickc-plus/src/esp32_bm8563.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * 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 <errno.h> +#include <syslog.h> + +#include <nuttx/arch.h> +#include <nuttx/clock.h> +#include <nuttx/i2c/i2c_master.h> +#include <nuttx/timers/pcf8563.h> + +#include "esp32_i2c.h" +#include "esp32-m5-stickc-plus.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: up_rtc_initialize + * + * Description: + * clock_initialize() always calls up_rtc_initialize() when CONFIG_RTC is + * set. On ESP32 that function only exists in the internal RTC driver, + * which is not built when the system time comes from the external BM8563 + * instead. There is no internal RTC hardware to set up in that case; the + * BM8563 itself is brought up later from board_bm8563_initialize(), once + * the I2C bus is available. + * + ****************************************************************************/ + +#ifndef CONFIG_RTC_DRIVER +int up_rtc_initialize(void) Review Comment: > why not enable RTC late initialization The RTC is in fact initialized late: board_bm8563_initialize() runs from esp32_bringup(), i.e. from board_late_initialize() (CONFIG_BOARD_LATE_INITIALIZE is default y, so it does not appear in the defconfig). At that point the I2C bus is up; it binds the PCF8563 driver and calls clock_synchronize() to pull the system time from the battery-backed BM8563. The up_rtc_initialize() stub exists only to satisfy clock_initialize(), which calls it unconditionally during early boot whenever CONFIG_RTC=y — long before the I2C bus exists, so there is nothing it could do at that point. ESP32 has no always-built implementation of this symbol: esp_rtc.c is only compiled under CONFIG_RTC_DRIVER=y, which cannot be enabled here since it would collide with the PCF8563 driver (both define up_rtc_settime()). This is the established pattern for an external RTC with no internal one — boards/arm/stm32u5/nucleo-u5a5zj-q/src/stm32_bringup.c ships the same stub, with a comment noting the clock_initialize() logic that still calls up_rtc_initialize() in this combination. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
