You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ut...@apache.org on 2020/08/10 00:00:34 UTC

[mynewt-core] branch master updated (585bc6c -> 9360deb)

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

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


    from 585bc6c  docs: sysinit and sysdown
     new 91b54ee  hw/bsp/pinetime: Use spi flash for the second image
     new 9360deb  hw/bsp/pinetime: Use bus driver for flash and display

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 hw/bsp/pinetime/boot-pinetime.ld |  2 +-
 hw/bsp/pinetime/bsp.yml          | 29 ++++++++++-------
 hw/bsp/pinetime/pinetime.ld      |  2 +-
 hw/bsp/pinetime/pkg.yml          |  1 +
 hw/bsp/pinetime/src/hal_bsp.c    | 69 ++++++++++++++++++++++++++++++++++++----
 hw/bsp/pinetime/syscfg.yml       | 34 ++++++++++++++++++++
 6 files changed, 117 insertions(+), 20 deletions(-)


[mynewt-core] 02/02: hw/bsp/pinetime: Use bus driver for flash and display

Posted by ut...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 9360debc22b961ca7abbdbab697c61480f8ae15d
Author: Casper Meijn <ca...@meijn.net>
AuthorDate: Sat Aug 8 10:48:09 2020 +0200

    hw/bsp/pinetime: Use bus driver for flash and display
    
    Use the bus driver for the SPI flash, so that the SPI display can be
    operated in parallel.
---
 hw/bsp/pinetime/src/hal_bsp.c | 48 +++++++++++++++++++++++++++++++++++++++++++
 hw/bsp/pinetime/syscfg.yml    |  8 ++++++++
 2 files changed, 56 insertions(+)

diff --git a/hw/bsp/pinetime/src/hal_bsp.c b/hw/bsp/pinetime/src/hal_bsp.c
index 307282d..d7dcb46 100644
--- a/hw/bsp/pinetime/src/hal_bsp.c
+++ b/hw/bsp/pinetime/src/hal_bsp.c
@@ -56,6 +56,18 @@ hal_bsp_core_dump(int *area_cnt)
     return dump_cfg;
 }
 
+#if MYNEWT_VAL(SPIFLASH)
+#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+struct bus_spi_node_cfg flash_spi_cfg = {
+    .node_cfg.bus_name = MYNEWT_VAL(BSP_FLASH_SPI_BUS),
+    .pin_cs = MYNEWT_VAL(SPIFLASH_SPI_CS_PIN),
+    .mode = BUS_SPI_MODE_3,
+    .data_order = HAL_SPI_MSB_FIRST,
+    .freq = MYNEWT_VAL(SPIFLASH_BAUDRATE),
+};
+#endif
+#endif
+
 static const struct hal_flash *flash_devs[] = {
     /* MCU internal flash. */
     [0] = &nrf52k_flash_dev,
@@ -169,15 +181,51 @@ hal_bsp_charger_init(void)
 }
 #endif
 
+#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+static struct bus_spi_node hal_bsp_display_spi;
+struct bus_spi_node_cfg hal_bsp_display_spi_cfg = {
+    .node_cfg.bus_name = MYNEWT_VAL(BSP_FLASH_SPI_BUS),
+    .pin_cs = LCD_CHIP_SELECT_PIN,
+    .mode = BUS_SPI_MODE_3,
+    .data_order = HAL_SPI_MSB_FIRST,
+    .freq = 8000,
+};
+
+static void
+hal_bsp_display_spi_init(void)
+{
+    int rc;
+
+    rc = bus_spi_node_create("spidisplay", &hal_bsp_display_spi, &hal_bsp_display_spi_cfg, NULL);
+    assert(rc == 0);
+}
+#endif
+
 void
 hal_bsp_init(void)
 {
+    int rc;
+
+    (void)rc;
+
     /* Make sure system clocks have started. */
     hal_system_clock_start();
 
     /* Create all available nRF52840 peripherals */
     nrf52_periph_create();
 
+    #if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+    /* Create display spi node */
+    hal_bsp_display_spi_init();
+
+    #if MYNEWT_VAL(SPIFLASH)
+    /* Create external flash dev */
+    rc = spiflash_create_spi_dev(&spiflash_dev.dev,
+                                 MYNEWT_VAL(BSP_FLASH_SPI_NAME), &flash_spi_cfg);
+    assert(rc == 0);
+    #endif
+    #endif
+
     #if MYNEWT_VAL(BSP_CHARGER)
     /* Create charge controller */
     hal_bsp_charger_init();
diff --git a/hw/bsp/pinetime/syscfg.yml b/hw/bsp/pinetime/syscfg.yml
index bcb6e8d..97edf0e 100644
--- a/hw/bsp/pinetime/syscfg.yml
+++ b/hw/bsp/pinetime/syscfg.yml
@@ -29,6 +29,14 @@ syscfg.defs:
         description: 'Setup charger driver in the BSP'
         value: 1
 
+syscfg.defs.BUS_DRIVER_PRESENT:
+    BSP_FLASH_SPI_NAME:
+        description: 'SPIFLASH device name'
+        value: '"spiflash0"'
+    BSP_FLASH_SPI_BUS:
+        description: 'bus name SPIFLASH is connected to'
+        value: '"spi0"'
+
 syscfg.vals.BOOT_LOADER:
     BSP_BATTERY: 0
     BSP_CHARGER: 0


[mynewt-core] 01/02: hw/bsp/pinetime: Use spi flash for the second image

Posted by ut...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 91b54ee661d52bac09eb66bbb58ff08fb440276a
Author: Casper Meijn <ca...@meijn.net>
AuthorDate: Sun Aug 2 16:17:40 2020 +0200

    hw/bsp/pinetime: Use spi flash for the second image
    
    This makes it possible to double the size of the image.
    To be compatible with other community firmwares the bootloader size is
    increased. This causes the reboot log to shrink.
    An extra SPI flash area is assigned for bootloader assets (for example
    a boot logo).
    The image could be increased by another 12kB, but I want to wait for
    other firmwares to do that as well.
---
 hw/bsp/pinetime/boot-pinetime.ld |  2 +-
 hw/bsp/pinetime/bsp.yml          | 29 ++++++++++++++++++-----------
 hw/bsp/pinetime/pinetime.ld      |  2 +-
 hw/bsp/pinetime/pkg.yml          |  1 +
 hw/bsp/pinetime/src/hal_bsp.c    | 21 ++++++++++++++-------
 hw/bsp/pinetime/syscfg.yml       | 26 ++++++++++++++++++++++++++
 6 files changed, 61 insertions(+), 20 deletions(-)

diff --git a/hw/bsp/pinetime/boot-pinetime.ld b/hw/bsp/pinetime/boot-pinetime.ld
index d1f1b99..85cd035 100644
--- a/hw/bsp/pinetime/boot-pinetime.ld
+++ b/hw/bsp/pinetime/boot-pinetime.ld
@@ -17,7 +17,7 @@
  */
 MEMORY
 {
-  FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x4000
+  FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x6000
   RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x10000
 }
 
diff --git a/hw/bsp/pinetime/bsp.yml b/hw/bsp/pinetime/bsp.yml
index c89953d..ed9ccee 100644
--- a/hw/bsp/pinetime/bsp.yml
+++ b/hw/bsp/pinetime/bsp.yml
@@ -29,34 +29,41 @@ bsp.part2linkerscript: "hw/bsp/pinetime/split-pinetime.ld"
 bsp.downloadscript: "hw/bsp/pinetime/pinetime_download.sh"
 bsp.debugscript: "hw/bsp/pinetime/pinetime_debug.sh"
 
+# This flash layout is compatible with other community firmwares. It is based on: https://lupyuen.github.io/pinetime-rust-mynewt/articles/mcuboot
+#TODO: The image size could be increased by 12kB. This space is already reserved, but not yet used. This is to be compatible with other firmwares that use the image size of 464kB.
 bsp.flash_map:
     areas:
         # System areas.
         FLASH_AREA_BOOTLOADER:
             device: 0
             offset: 0x00000000
-            size: 16kB
+            size: 24kB
         FLASH_AREA_IMAGE_0:
             device: 0
             offset: 0x00008000
-            size: 232kB
+            size: 464kB
         FLASH_AREA_IMAGE_1:
-            device: 0
-            offset: 0x00042000
-            size: 232kB
+            device: 1
+            offset: 0x00040000
+            size: 464kB
         FLASH_AREA_IMAGE_SCRATCH:
             device: 0
-            offset: 0x0007c000
+            offset: 0x0007f000
             size: 4kB
 
         # User areas.
         FLASH_AREA_REBOOT_LOG:
             user_id: 0
             device: 0
-            offset: 0x00004000
-            size: 16kB
+            offset: 0x00006000
+            size: 8kB
         FLASH_AREA_NFFS:
             user_id: 1
-            device: 0
-            offset: 0x0007d000
-            size: 12kB
+            device: 1
+            offset: 0x000b7000
+            size: 3364kB
+        FLASH_AREA_BOOTLOADER_ASSETS:
+            user_id: 2
+            device: 1
+            offset: 0x00000000
+            size: 256kB
diff --git a/hw/bsp/pinetime/pinetime.ld b/hw/bsp/pinetime/pinetime.ld
index 53baaed..b82bfcb 100644
--- a/hw/bsp/pinetime/pinetime.ld
+++ b/hw/bsp/pinetime/pinetime.ld
@@ -19,7 +19,7 @@
 
 MEMORY
 {
-  FLASH (rx) : ORIGIN = 0x00008000, LENGTH = 0x3a000
+  FLASH (rx) : ORIGIN = 0x00008000, LENGTH = 0x74000
   RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x10000
 }
 
diff --git a/hw/bsp/pinetime/pkg.yml b/hw/bsp/pinetime/pkg.yml
index f119444..1423b61 100644
--- a/hw/bsp/pinetime/pkg.yml
+++ b/hw/bsp/pinetime/pkg.yml
@@ -35,6 +35,7 @@ pkg.deps:
     - '@apache-mynewt-core/hw/mcu/nordic/nrf52xxx'
     - '@apache-mynewt-core/kernel/os'
     - '@apache-mynewt-core/libc/baselibc'
+    - "@apache-mynewt-core/hw/drivers/flash/spiflash"
 
 pkg.deps.BSP_CHARGER:
     - '@apache-mynewt-core/hw/drivers/chg_ctrl/sgm4056'
diff --git a/hw/bsp/pinetime/src/hal_bsp.c b/hw/bsp/pinetime/src/hal_bsp.c
index 0ff8c68..307282d 100644
--- a/hw/bsp/pinetime/src/hal_bsp.c
+++ b/hw/bsp/pinetime/src/hal_bsp.c
@@ -37,6 +37,9 @@
 #include "adc_nrf52/adc_nrf52.h"
 #include <nrf_saadc.h>
 #endif
+#if MYNEWT_VAL(SPIFLASH)
+#include <spiflash/spiflash.h>
+#endif
 
 /** What memory to include in coredump. */
 static const struct hal_bsp_mem_dump dump_cfg[] = {
@@ -53,6 +56,15 @@ hal_bsp_core_dump(int *area_cnt)
     return dump_cfg;
 }
 
+static const struct hal_flash *flash_devs[] = {
+    /* MCU internal flash. */
+    [0] = &nrf52k_flash_dev,
+#if MYNEWT_VAL(SPIFLASH)
+    /* External SPI Flash. */
+    [1] = &spiflash_dev.hal,
+#endif
+};
+
 /**
  * Retrieves the flash device with the specified ID.  Returns NULL if no such
  * device exists.
@@ -60,15 +72,10 @@ hal_bsp_core_dump(int *area_cnt)
 const struct hal_flash *
 hal_bsp_flash_dev(uint8_t id)
 {
-    switch (id) {
-    case 0:
-        /* MCU internal flash. */
-        return &nrf52k_flash_dev;
-
-    default:
-        /* External flash.  Assume not present in this BSP. */
+    if (id >= ARRAY_SIZE(flash_devs)) {
         return NULL;
     }
+    return flash_devs[id];
 }
 
 /**
diff --git a/hw/bsp/pinetime/syscfg.yml b/hw/bsp/pinetime/syscfg.yml
index f274677..bcb6e8d 100644
--- a/hw/bsp/pinetime/syscfg.yml
+++ b/hw/bsp/pinetime/syscfg.yml
@@ -48,6 +48,7 @@ syscfg.vals:
     # Default Pins for Peripherals
 
     # SPI port 0 connected to ST7789 display
+    SPI_0_MASTER: 1
     SPI_0_MASTER_PIN_SCK:  2  # P0.02: SPI-SCK, LCD_SCK
     SPI_0_MASTER_PIN_MOSI: 3  # P0.03: SPI-MOSI, LCD_SDI
     SPI_0_MASTER_PIN_MISO: 4  # P0.04: SPI-MISO
@@ -72,6 +73,31 @@ syscfg.vals:
     NFFS_FLASH_AREA: FLASH_AREA_NFFS
     COREDUMP_FLASH_AREA: FLASH_AREA_IMAGE_1
 
+    # SPI Flash
+    SPIFLASH:               1
+    SPIFLASH_SPI_NUM:       0
+    SPIFLASH_SPI_CS_PIN:    5 # P0.05 SPI-CE#(SPI-NOR)
+    SPIFLASH_BAUDRATE:      8000
+    SPIFLASH_MANUFACTURER:  0x0B
+    SPIFLASH_MEMORY_TYPE:   0x40
+    SPIFLASH_MEMORY_CAPACITY: 0x16
+    SPIFLASH_SECTOR_COUNT:  1024
+    SPIFLASH_SECTOR_SIZE:   4096
+    SPIFLASH_PAGE_SIZE:     256
+
+    SPIFLASH_TBP1_TYPICAL:  20      # Byte program time (first byte) (us)
+    SPIFLASH_TBP1_MAXIMUM:  50      # Maximum byte program time (first byte) (us)
+    SPIFLASH_TPP_TYPICAL:   700     # Page program time (us)
+    SPIFLASH_TPP_MAXIMUM:   3000    # Maximum page program time (us)
+    SPIFLASH_TSE_TYPICAL:   30000   # Sector erase time (4KB) (us)
+    SPIFLASH_TSE_MAXIMUM:   400000  # Maximum sector erase time (us)
+    SPIFLASH_TBE1_TYPICAL:  120000  # Block erase time (32KB) (us)
+    SPIFLASH_TBE1_MAXIMUM:  800000  # Maximum block erase time (32KB) (us)
+    SPIFLASH_TBE2_TYPICAL:  150000  # Block erase time (64KB) (us)
+    SPIFLASH_TBE2_MAXIMUM:  1000000 # Maximum block erase time (64KB) (us)
+    SPIFLASH_TCE_TYPICAL:   3000000 # Chip erase time (us)
+    SPIFLASH_TCE_MAXIMUM:   10000000 # Maximum chip erase time (us)
+
 syscfg.vals.BSP_BATTERY:
     # ADC needed for battery voltage
     ADC_0: 1