Skip to content

Commit

Permalink
Add support for the new SPI flash memory chip (BY25Q32).
Browse files Browse the repository at this point in the history
PineStore notified the community that the SPI flash memory chip (XTX XT25F32B) used in the PineTime was EoL (End-Of-Life) and will be replaced by another chip (BY25Q32).

Since we want to provide a new version of the firmware (bootloader + application) in a short time frame to avoid the production of the next batch of PineTime being delayed, we did our best to add support for the new chip by doing the smallest and less risky changes possible.

The version of MyNewt this project is based on (1.8.0) do not support any of the memory chips out of the box. The current version defines the JEDEC IDs in the [NRF52 "BSP"](hw/bsp/nrf52/syscfg.yml). The downside of this way of specifying the IDs of the chip is that you can only define a single chip. Newer versions of MyNewt allow to ignore the ID, but this is not available in our version.

These changes patches the spiflash driver of MyNewt to add support for both memory chip, and enable them so that the system checks for both IDs at startup.
  • Loading branch information
JF002 committed Sep 4, 2024
1 parent 14a6db8 commit 2c75463
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 5 deletions.
11 changes: 6 additions & 5 deletions hw/bsp/nrf52/syscfg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,18 @@ syscfg.vals:

###########################################################################
# SPI Flash
# XTX XT25F32B 32 Mb (4 MB) SPI NOR Flash (similar to QuadSPI SPI NOR Flash like Macronix 32 Mb (4 MB) MX25L3233F)
# manufacturer (0x0b), device (0x15), memory type (0x40), density (0x16)
# - XTX XT25F32B 32 Mb (4 MB) SPI NOR Flash (similar to QuadSPI SPI NOR Flash like Macronix 32 Mb (4 MB) MX25L3233F)
# manufacturer (0x0b), device (0x15), memory type (0x40), density (0x16)
# - BY25Q32 : manufacturer (0x68), memory type (0x40), density (0x16)
# Settings below are documented at https://github.com/apache/mynewt-core/blob/master/hw/drivers/flash/spiflash/syscfg.yml

SPIFLASH: 1 # Enable SPI Flash
SPIFLASH_SPI_NUM: 0 # SPI Interface 0
SPIFLASH_SPI_CS_PIN: 5 # SPI interface CS pin: P0.05/AIN3, SPI-CE# (SPI-NOR)
SPIFLASH_BAUDRATE: 8000 # Requested baudrate, 8000 is the fastest baudrate supported by nRF52832
SPIFLASH_MANUFACTURER: 0x0B # Expected SpiFlash manufacturer as read by Read JEDEC ID command 9FH
SPIFLASH_MEMORY_TYPE: 0x40 # Expected SpiFlash memory type as read by Read JEDEC ID command 9FH
SPIFLASH_MEMORY_CAPACITY: 0x16 # Expected SpiFlash memory capactity as read by Read JEDEC ID command 9FH (2 ^ 0x16 = 32 Mb)
SPIFLASH_MANUFACTURER: 0 # Expected SpiFlash manufacturer as read by Read JEDEC ID command 9FH. Set to 0 to support multiple chips at once
SPIFLASH_MEMORY_TYPE: 0 # Expected SpiFlash memory type as read by Read JEDEC ID command 9FH. Set to 0 to support multiple chips at once
SPIFLASH_MEMORY_CAPACITY: 0 # Expected SpiFlash memory capactity as read by Read JEDEC ID command 9FH (2 ^ 0x16 = 32 Mb). Set to 0 to support multiple chips at once
SPIFLASH_SECTOR_COUNT: 1024 # Number of sectors: 1024 sectors of 4 KB each
SPIFLASH_SECTOR_SIZE: 4096 # TODO Number of bytes that can be erased at a time: 4 KB sector size
SPIFLASH_PAGE_SIZE: 256 # TODO Number of bytes that can be written at a time
Expand Down
42 changes: 42 additions & 0 deletions libs/pinetime_boot/patches/01-spiflash.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Subject: [PATCH] spi chip update
---
Index: hw/drivers/flash/spiflash/chips/syscfg.yml
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/hw/drivers/flash/spiflash/chips/syscfg.yml b/hw/drivers/flash/spiflash/chips/syscfg.yml
--- a/hw/drivers/flash/spiflash/chips/syscfg.yml
+++ b/hw/drivers/flash/spiflash/chips/syscfg.yml
@@ -491,3 +491,9 @@
SPIFLASH_EON2580B:
description: Add support for EON2580B
value: 0
+ SPIFLASH_XTX25F32B:
+ description: Add support for XTX25F32B
+ value: 1
+ SPIFLASH_BY25Q32:
+ description: Add support for BY25Q32
+ value: 1
Index: hw/drivers/flash/spiflash/src/spiflash.c
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/hw/drivers/flash/spiflash/src/spiflash.c b/hw/drivers/flash/spiflash/src/spiflash.c
--- a/hw/drivers/flash/spiflash/src/spiflash.c
+++ b/hw/drivers/flash/spiflash/src/spiflash.c
@@ -565,7 +565,12 @@
#if MYNEWT_VAL(SPIFLASH_EON2580B)
EON_CHIP(EN80B, 0x30, FLASH_CAPACITY_8MBIT),
#endif
-
+#if MYNEWT_VAL(SPIFLASH_XTX25F32B)
+ STD_FLASH_CHIP("", 0x0b, 0x40, 0x16, spiflash_release_power_down_generic),
+#endif
+#if MYNEWT_VAL(SPIFLASH_BY25Q32)
+ STD_FLASH_CHIP("", 0x16, 0x40, 0x16, spiflash_release_power_down_generic),
+#endif
{ {0} },
};

14 changes: 14 additions & 0 deletions scripts/nrf52/build-boot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ source paths.bash
# Show the Arm Toolchain version.
arm-none-eabi-gcc --version

# Apply patches
set +e
patch -uN -p1 --dry-run --silent -d repos/apache-mynewt-core/ < libs/pinetime_boot/patches/01-spiflash.patch 2>/dev/null

#If the patch has not been applied then the $? which is the exit status
#for last command would have a success status code = 0
if [ $? -eq 0 ];
then
#apply the patch
patch -uN -p1 -d repos/apache-mynewt-core/ < libs/pinetime_boot/patches/01-spiflash.patch
fi
set -e


# Build the bootloader.
newt build nrf52_boot

Expand Down

0 comments on commit 2c75463

Please sign in to comment.