You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ja...@apache.org on 2020/05/11 10:53:45 UTC

[mynewt-core] branch master updated: hw/bsp/pinetime: Make drivers optional and disable for bootloader

This is an automated email from the ASF dual-hosted git repository.

janc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
     new ef1427c  hw/bsp/pinetime: Make drivers optional and disable for bootloader
ef1427c is described below

commit ef1427c0e8df1be87d05a16731feadca718b4280
Author: Casper Meijn <ca...@meijn.net>
AuthorDate: Thu May 7 10:18:34 2020 +0200

    hw/bsp/pinetime: Make drivers optional and disable for bootloader
    
    This adds a syscfg for the battery and charger drivers. These options
    are not available for bootloader builds. This reduces the size of the
    bootloader significantly. The build failed before and now fits easily.
    
    $ newt size boot-pinetime
    Size of Application Image: app
      FLASH     RAM
         28     222 *fill*
       1152       0 @apache-mynewt-core_crypto_mbedtls.a
        382     444 @apache-mynewt-core_hw_bsp_pinetime.a
         40       0 @apache-mynewt-core_hw_cmsis-core.a
        594       1 @apache-mynewt-core_hw_hal.a
       2112      32 @apache-mynewt-core_hw_mcu_nordic_nrf52xxx.a
        310      24 @apache-mynewt-core_kernel_os.a
        168       0 @apache-mynewt-core_libc_baselibc.a
        654     128 @apache-mynewt-core_sys_flash_map.a
        518      29 @apache-mynewt-core_sys_mfg.a
          6       4 @apache-mynewt-core_sys_sysinit.a
       4398    5996 @mcuboot_boot_bootutil.a
         62       0 @mcuboot_boot_mynewt.a
         16       0 @mcuboot_boot_mynewt_flash_map_backend.a
         72       0 boot-pinetime-sysinit-app.a
    
    objsize
       text    data     bss     dec     hex filename
      10512      28    6420   16960    4240 bin/targets/boot-pinetime/app/@mcuboot/boot/mynewt/mynewt.elf
---
 hw/bsp/pinetime/pkg.yml       |  4 ++++
 hw/bsp/pinetime/src/hal_bsp.c | 31 +++++++++++++++++++++++++------
 hw/bsp/pinetime/syscfg.yml    | 17 ++++++++++++++---
 3 files changed, 43 insertions(+), 9 deletions(-)

diff --git a/hw/bsp/pinetime/pkg.yml b/hw/bsp/pinetime/pkg.yml
index 656f688..f119444 100644
--- a/hw/bsp/pinetime/pkg.yml
+++ b/hw/bsp/pinetime/pkg.yml
@@ -35,6 +35,10 @@ pkg.deps:
     - '@apache-mynewt-core/hw/mcu/nordic/nrf52xxx'
     - '@apache-mynewt-core/kernel/os'
     - '@apache-mynewt-core/libc/baselibc'
+
+pkg.deps.BSP_CHARGER:
     - '@apache-mynewt-core/hw/drivers/chg_ctrl/sgm4056'
+
+pkg.deps.BSP_BATTERY:
     - '@apache-mynewt-core/hw/battery'
     - '@apache-mynewt-core/hw/drivers/adc'
diff --git a/hw/bsp/pinetime/src/hal_bsp.c b/hw/bsp/pinetime/src/hal_bsp.c
index 1a2e537..0ff8c68 100644
--- a/hw/bsp/pinetime/src/hal_bsp.c
+++ b/hw/bsp/pinetime/src/hal_bsp.c
@@ -29,10 +29,14 @@
 #include "bsp/bsp.h"
 #include "mcu/nrf52_hal.h"
 #include "mcu/nrf52_periph.h"
+#if MYNEWT_VAL(BSP_CHARGER)
 #include "sgm4056/sgm4056.h"
+#endif
+#if MYNEWT_VAL(BSP_BATTERY)
 #include "battery/battery_adc.h"
 #include "adc_nrf52/adc_nrf52.h"
 #include <nrf_saadc.h>
+#endif
 
 /** What memory to include in coredump. */
 static const struct hal_bsp_mem_dump dump_cfg[] = {
@@ -92,6 +96,7 @@ hal_bsp_get_nvic_priority(int irq_num, uint32_t pri)
     return cfg_pri;
 }
 
+#if MYNEWT_VAL(BSP_BATTERY)
 static struct adc_dev_cfg hal_bsp_adc_dev_config = {
     .resolution = ADC_RESOLUTION_10BIT,
     .oversample = ADC_OVERSAMPLE_DISABLED,
@@ -136,29 +141,43 @@ hal_bsp_battery_init(void)
                        battery_adc_init, &hal_bsp_battery_config);
     assert(rc == 0);
 }
+#endif
 
+#if MYNEWT_VAL(BSP_CHARGER)
 static struct sgm4056_dev os_bsp_charger;
 static struct sgm4056_dev_config os_bsp_charger_config = {
     .power_presence_pin = CHARGER_POWER_PRESENCE_PIN,
     .charge_indicator_pin = CHARGER_CHARGE_PIN,
 };
 
-void
-hal_bsp_init(void)
+static void
+hal_bsp_charger_init(void)
 {
     int rc;
 
+    rc = os_dev_create(&os_bsp_charger.dev, "charger",
+                       OS_DEV_INIT_KERNEL, OS_DEV_INIT_PRIO_DEFAULT,
+                       sgm4056_dev_init, &os_bsp_charger_config);
+    assert(rc == 0);
+}
+#endif
+
+void
+hal_bsp_init(void)
+{
     /* Make sure system clocks have started. */
     hal_system_clock_start();
 
     /* Create all available nRF52840 peripherals */
     nrf52_periph_create();
 
+    #if MYNEWT_VAL(BSP_CHARGER)
     /* Create charge controller */
-    rc = os_dev_create(&os_bsp_charger.dev, "charger",
-                       OS_DEV_INIT_KERNEL, OS_DEV_INIT_PRIO_DEFAULT,
-                       sgm4056_dev_init, &os_bsp_charger_config);
-    assert(rc == 0);
+    hal_bsp_charger_init();
+    #endif
 
+    #if MYNEWT_VAL(BSP_BATTERY)
+    /* Create adc and battery driver */
     hal_bsp_battery_init();
+    #endif
 }
diff --git a/hw/bsp/pinetime/syscfg.yml b/hw/bsp/pinetime/syscfg.yml
index f49815e..f274677 100644
--- a/hw/bsp/pinetime/syscfg.yml
+++ b/hw/bsp/pinetime/syscfg.yml
@@ -22,6 +22,16 @@ syscfg.defs:
     BSP_NRF52:
         description: 'Set to indicate that BSP has NRF52'
         value: 1
+    BSP_BATTERY:
+        description: 'Setup battery driver in the BSP'
+        value: 1
+    BSP_CHARGER:
+        description: 'Setup charger driver in the BSP'
+        value: 1
+
+syscfg.vals.BOOT_LOADER:
+    BSP_BATTERY: 0
+    BSP_CHARGER: 0
 
 # Settings this BSP overrides.
 syscfg.vals:
@@ -56,15 +66,16 @@ syscfg.vals:
     # Configure NFC pins as GPIO P0.09, P0.10
     NFC_PINS_AS_GPIO: 1
 
-    # ADC needed for battery voltage
-    ADC_0: 1
-
     # Define flash areas
     CONFIG_FCB_FLASH_AREA: FLASH_AREA_NFFS
     REBOOT_LOG_FLASH_AREA: FLASH_AREA_REBOOT_LOG
     NFFS_FLASH_AREA: FLASH_AREA_NFFS
     COREDUMP_FLASH_AREA: FLASH_AREA_IMAGE_1
 
+syscfg.vals.BSP_BATTERY:
+    # ADC needed for battery voltage
+    ADC_0: 1
+
 syscfg.vals.BLE_CONTROLLER:
     TIMER_0: 0
     TIMER_5: 1