From 82104ac4cce33fa64bef7f5a32e4e92bc878a21f Mon Sep 17 00:00:00 2001 From: Peter Hinch Date: Tue, 11 Feb 2020 17:07:22 +0000 Subject: [PATCH] Add delay after Pyboard D 3V3 enable - docs and test scripts. --- eeprom/i2c/I2C.md | 1 + eeprom/i2c/eep_i2c.py | 2 ++ eeprom/spi/SPI.md | 1 + eeprom/spi/eep_spi.py | 2 ++ flash/FLASH.md | 1 + flash/flash_spi.py | 17 ++++++++--------- flash/flash_test.py | 8 +++++--- fram/FRAM.md | 1 + fram/fram_test.py | 2 ++ 9 files changed, 23 insertions(+), 12 deletions(-) diff --git a/eeprom/i2c/I2C.md b/eeprom/i2c/I2C.md index e65b9a2..c56d502 100644 --- a/eeprom/i2c/I2C.md +++ b/eeprom/i2c/I2C.md @@ -68,6 +68,7 @@ If you use a Pyboard D and power the EEPROMs from the 3V3 output you will need to enable the voltage rail by issuing: ```python machine.Pin.board.EN_3V3.value(1) +time.sleep(0.1) # Allow decouplers to charge ``` Other platforms may vary. diff --git a/eeprom/i2c/eep_i2c.py b/eeprom/i2c/eep_i2c.py index 20854c7..1a177d6 100644 --- a/eeprom/i2c/eep_i2c.py +++ b/eeprom/i2c/eep_i2c.py @@ -4,6 +4,7 @@ # Copyright (c) 2019 Peter Hinch import uos +import time from machine import I2C, Pin from eeprom_i2c import EEPROM, T24C512 @@ -12,6 +13,7 @@ from eeprom_i2c import EEPROM, T24C512 def get_eep(): if uos.uname().machine.split(' ')[0][:4] == 'PYBD': Pin.board.EN_3V3.value(1) + time.sleep(0.1) # Allow decouplers to charge eep = EEPROM(I2C(2), T24C512) print('Instantiated EEPROM') return eep diff --git a/eeprom/spi/SPI.md b/eeprom/spi/SPI.md index 35c0c64..a4c339f 100644 --- a/eeprom/spi/SPI.md +++ b/eeprom/spi/SPI.md @@ -55,6 +55,7 @@ If you use a Pyboard D and power the EEPROMs from the 3V3 output you will need to enable the voltage rail by issuing: ```python machine.Pin.board.EN_3V3.value(1) +time.sleep(0.1) # Allow decouplers to charge ``` Other platforms may vary. diff --git a/eeprom/spi/eep_spi.py b/eeprom/spi/eep_spi.py index 0cfdbff..f553b09 100644 --- a/eeprom/spi/eep_spi.py +++ b/eeprom/spi/eep_spi.py @@ -4,6 +4,7 @@ # Copyright (c) 2019 Peter Hinch import uos +import time from machine import SPI, Pin from eeprom_spi import EEPROM # Add extra pins if using multiple chips @@ -13,6 +14,7 @@ cspins = (Pin(Pin.board.Y5, Pin.OUT, value=1), Pin(Pin.board.Y4, Pin.OUT, value= def get_eep(stm): if uos.uname().machine.split(' ')[0][:4] == 'PYBD': Pin.board.EN_3V3.value(1) + time.sleep(0.1) # Allow decouplers to charge if stm: eep = EEPROM(SPI(2, baudrate=5_000_000), cspins, 256) else: diff --git a/flash/FLASH.md b/flash/FLASH.md index 2e83e92..021d72b 100644 --- a/flash/FLASH.md +++ b/flash/FLASH.md @@ -59,6 +59,7 @@ If you use a Pyboard D and power the chips from the 3V3 output you will need to enable the voltage rail by issuing: ```python machine.Pin.board.EN_3V3.value(1) +time.sleep(0.1) # Allow decouplers to charge ``` Other platforms may vary but the Cypress chips require a 3.3V supply. diff --git a/flash/flash_spi.py b/flash/flash_spi.py index 226e6ef..1f8f3d0 100644 --- a/flash/flash_spi.py +++ b/flash/flash_spi.py @@ -1,7 +1,7 @@ # flash_spi.py MicroPython driver for SPI NOR flash devices. # Released under the MIT License (MIT). See LICENSE. -# Copyright (c) 2019 Peter Hinch +# Copyright (c) 2019-2020 Peter Hinch import time from micropython import const @@ -17,7 +17,6 @@ _CMDS4BA = b'\x13\x12\x21' # No address _WREN = const(6) # Write enable _RDSR1 = const(5) # Read status register 1 -_RDSR2 = const(7) # Read status register 2 _RDID = const(0x9f) # Read manufacturer ID _CE = const(0xc7) # Chip erase (takes minutes) @@ -27,18 +26,19 @@ _SEC_SIZE = const(4096) # Flash sector size 0x1000 class FLASH(FlashDevice): def __init__(self, spi, cspins, size=None, verbose=True, sec_size=_SEC_SIZE, block_size=9): - # args: virtual block size in bits, no. of chips, bytes in each chip self._spi = spi self._cspins = cspins self._ccs = None # Chip select Pin object for current chip self._bufp = bytearray(6) # instruction + 4 byte address + 1 byte value self._mvp = memoryview(self._bufp) # cost-free slicing self._page_size = 256 # Write uses 256 byte pages. - for cs in cspins: # Ensure all chips are deselected + # Defensive code: application should have done the following. + # Pyboard D 3V3 output may just have been switched on. + for cs in cspins: # Deselect all chips cs(1) - time.sleep_ms(1) # Found necessary on fast hosts + time.sleep_ms(1) # Meet Tpu 300μs - size = self.scan(verbose, size) + size = self.scan(verbose, size) # KiB super().__init__(block_size, len(cspins), size * 1024, sec_size) # Select the correct command set @@ -52,7 +52,7 @@ class FLASH(FlashDevice): self.initialise() # Initially cache sector 0 # **** API SPECIAL METHODS **** - # Scan: read manf ID + # Scan: return chip size in KiB as read from ID. def scan(self, verbose, size): mvp = self._mvp for n, cs in enumerate(self._cspins): @@ -62,7 +62,7 @@ class FLASH(FlashDevice): self._spi.write_readinto(mvp[:4], mvp[:4]) cs(1) scansize = 1 << (mvp[3] - 10) - if not size: + if size is None: size = scansize if size != scansize: raise ValueError('Flash size mismatch: expected {}KiB, found {}KiB'.format(size, scansize)) @@ -125,7 +125,6 @@ class FLASH(FlashDevice): self._spi.write(mvp[:self._cmdlen]) self._spi.readinto(mvb[start : start + npage]) cs(1) -# print('addr {} npage {} data {}'.format(addr, npage, mvb[start])) nbytes -= npage start += npage addr += npage diff --git a/flash/flash_test.py b/flash/flash_test.py index fdd9731..f47d17d 100644 --- a/flash/flash_test.py +++ b/flash/flash_test.py @@ -4,19 +4,21 @@ # Copyright (c) 2019 Peter Hinch import uos +import time from machine import SPI, Pin from flash_spi import FLASH # **** ADAPT THIS FUNCTION **** -# Return an EEPROM array. Adapt for platforms other than Pyboard, chip size and -# baudrate. +# Return an EEPROM array. Adapt for platforms other than Pyboard. +# May want to set chip size and baudrate. def get_device(): if uos.uname().machine.split(' ')[0][:4] == 'PYBD': Pin.board.EN_3V3.value(1) + time.sleep(0.1) # Adjust to suit number of chips and their wiring. cspins = (Pin(Pin.board.Y5, Pin.OUT, value=1), Pin(Pin.board.Y4, Pin.OUT, value=1)) - flash = FLASH(SPI(2, baudrate=20_000_000), cspins, size=32768) + flash = FLASH(SPI(2, baudrate=20_000_000), cspins) print('Instantiated Flash') return flash diff --git a/fram/FRAM.md b/fram/FRAM.md index 60a582d..50a391b 100644 --- a/fram/FRAM.md +++ b/fram/FRAM.md @@ -66,6 +66,7 @@ If you use a Pyboard D and power the FRAMs from the 3V3 output you will need to enable the voltage rail by issuing: ```python machine.Pin.board.EN_3V3.value(1) +time.sleep(0.1) # Allow decouplers to charge ``` Other platforms may vary. diff --git a/fram/fram_test.py b/fram/fram_test.py index deb7318..a71c842 100644 --- a/fram/fram_test.py +++ b/fram/fram_test.py @@ -4,6 +4,7 @@ # Copyright (c) 2019 Peter Hinch import uos +import time from machine import I2C, Pin from fram_i2c import FRAM @@ -11,6 +12,7 @@ from fram_i2c import FRAM def get_fram(): if uos.uname().machine.split(' ')[0][:4] == 'PYBD': Pin.board.EN_3V3.value(1) + time.sleep(0.1) # Allow decouplers to charge fram = FRAM(I2C(2)) print('Instantiated FRAM') return fram