Skip to content

Commit e58e0a1

Browse files
Merge e61a36b into 2f02a37
2 parents 2f02a37 + e61a36b commit e58e0a1

File tree

9 files changed

+112
-30
lines changed

9 files changed

+112
-30
lines changed

.flake8

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ exclude =
4141
# example testing folder before going live
4242
thinking
4343
# custom scripts, not being part of the distribution
44-
libs_external
4544
sdist_upip.py
4645
setup.py
4746

.github/workflows/test.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ on:
1313
branches-ignore:
1414
- 'main'
1515
- 'develop'
16+
pull_request:
17+
branches:
18+
- 'main'
19+
- 'develop'
1620

1721
permissions:
1822
contents: read
@@ -52,3 +56,11 @@ jobs:
5256
- name: Test built package
5357
run: |
5458
twine check dist/*
59+
- name: Validate mip package file
60+
run: |
61+
upy-package \
62+
--setup_file setup.py \
63+
--package_changelog_file changelog.md \
64+
--package_file package.json \
65+
--validate \
66+
--ignore-version

README.md

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ MicroPython library to interact with Winbond W25Q Flash chips
1616
<!-- MarkdownTOC -->
1717

1818
- [Installation](#installation)
19-
- [Install required tools](#install-required-tools)
19+
- [Install required tools](#install-required-tools)
2020
- [Stetup](#stetup)
21-
- [Install package with upip](#install-package-with-upip)
22-
- [General](#general)
23-
- [Specific version](#specific-version)
24-
- [Test version](#test-version)
25-
- [Manually](#manually)
26-
- [Upload files to board](#upload-files-to-board)
21+
- [Install package](#install-package)
22+
- [General](#general)
23+
- [Specific version](#specific-version)
24+
- [Test version](#test-version)
25+
- [Manually](#manually)
26+
- [Upload files to board](#upload-files-to-board)
2727
- [Usage](#usage)
2828
- [Credits](#credits)
2929

@@ -62,13 +62,14 @@ rshell --help
6262

6363
## Stetup
6464

65-
### Install package with upip
65+
### Install package
6666

67-
Connect your MicroPython board to a network
67+
Connect the MicroPython device to a network (if possible)
6868

6969
```python
7070
import network
7171
station = network.WLAN(network.STA_IF)
72+
station.active(True)
7273
station.connect('SSID', 'PASSWORD')
7374
station.isconnected()
7475
```
@@ -101,7 +102,8 @@ mip.install("github:brainelectronics/micropython-winbond", version="feature/add-
101102
mip.install("github:brainelectronics/micropython-winbond", version="0.4.0")
102103
```
103104

104-
For MicroPython versions below 1.19.1 use the `upip` package instead of `mip`
105+
For MicroPython versions below 1.19.1 use the `upip` package instead of `mip`.
106+
With `upip` always the latest available version will be installed.
105107

106108
```python
107109
import upip
@@ -120,7 +122,8 @@ import mip
120122
mip.install("github:brainelectronics/micropython-winbond", version="0.4.0-rc2.dev4")
121123
```
122124

123-
For MicroPython versions below 1.19.1 use the `upip` package instead of `mip`
125+
For MicroPython versions below 1.19.1 use the `upip` package instead of `mip`.
126+
With `upip` always the latest available version will be installed.
124127

125128
```python
126129
import upip
@@ -153,7 +156,7 @@ folders to the device
153156
mkdir /pyboard/lib
154157
mkdir /pyboard/lib/winbond
155158

156-
cp winbond.py /pyboard/lib/winbond
159+
cp winbond/* /pyboard/lib/winbond
157160
cp main.py /pyboard/lib/winbond
158161
cp boot.py /pyboard/lib/winbond
159162
```
@@ -166,6 +169,7 @@ import os
166169
from winbond import W25QFlash
167170

168171
# the used SPI and CS pin is setup specific, change accordingly
172+
# check the boot.py file of this repo for further boards
169173
flash = W25QFlash(spi=SPI(2), cs=Pin(5), baud=2000000, software_reset=True)
170174

171175
flash_mount_point = '/external'
@@ -207,10 +211,5 @@ his [post to use Winbond flash chips][ref-upy-forum-winbond-driver]
207211
[ref-rtd-micropython-winbond]: https://micropython-winbond.readthedocs.io/en/latest/
208212
[ref-remote-upy-shell]: https://github.com/dhylands/rshell
209213
[ref-brainelectronics-test-pypiserver]: https://github.com/brainelectronics/test-pypiserver
210-
[ref-be32]: https://github.com/brainelectronics/BE32-01/
211-
[ref-pfalcon-picoweb-sdist-upip]: https://github.com/pfalcon/picoweb/blob/b74428ebdde97ed1795338c13a3bdf05d71366a0/sdist_upip.py
212-
[ref-test-pypi]: https://test.pypi.org/
213-
[ref-pypi]: https://pypi.org/
214-
[ref-invalid-auth-test-pypi]: https://test.pypi.org/help/#invalid-auth
215214
[ref-crizeo]: https://forum.micropython.org/memberlist.php?mode=viewprofile&u=3067
216215
[ref-upy-forum-winbond-driver]: https://forum.micropython.org/viewtopic.php?f=16&t=3899&start=10

boot.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@
3333
# mosi 13 23
3434
# miso 12 19
3535
# cs x, here 5 x, here 5
36-
CS_PIN = Pin(5)
37-
spi = SPI(2)
36+
if 'esp32s3' in os_info.machine.lower():
37+
CS_PIN = Pin(10)
38+
spi = SPI(2, 2000000, sck=Pin(12), mosi=Pin(11), miso=Pin(13))
39+
else:
40+
CS_PIN = Pin(5)
41+
spi = SPI(2)
3842
elif 'rp2' in os_info:
3943
# https://docs.micropython.org/en/latest/rp2/quickref.html#hardware-spi-bus
4044
# Pin id=0 id=1
@@ -57,6 +61,12 @@
5761

5862
flash = W25QFlash(spi=spi, cs=CS_PIN, baud=2000000, software_reset=True)
5963

64+
# get Flash infos/properties
65+
print("Flash manufacturer ID: 0x{0:02x}".format(flash.manufacturer))
66+
print("Flash Memory Type: {}".format(flash.mem_type))
67+
print("Flash Device Type: 0x{0:02x}".format(flash.device))
68+
print("Flash size: {} bytes".format(flash.capacity))
69+
6070
flash_mount_point = '/external'
6171

6272
try:

changelog.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
### Removed
1313
### Fixed
1414
-->
15+
## [0.5.0] - 2023-05-14
16+
### Added
17+
- Properties for `manufacturer`, `mem_type`, `device`, `capacity`
18+
- BE-ESP32-01 specific pin and SPI definition in `boot.py`
19+
- Validate `package.json` file with every test workflow run but without version validation
20+
21+
### Removed
22+
- Verbose print statements
23+
1524
## [0.4.0] - 2023-03-24
1625
### Added
1726
- `package.json` for `mip` installation with MicroPython v1.19.1 or newer
@@ -72,8 +81,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7281
without hardware reset pins, extended documentation and PEP8 fixes
7382

7483
<!-- Links -->
75-
[Unreleased]: https://github.com/brainelectronics/micropython-winbond/compare/0.4.0...main
84+
[Unreleased]: https://github.com/brainelectronics/micropython-winbond/compare/0.5.0...main
7685

86+
[0.5.0]: https://github.com/brainelectronics/micropython-winbond/tree/0.5.0
7787
[0.4.0]: https://github.com/brainelectronics/micropython-winbond/tree/0.4.0
7888
[0.3.0]: https://github.com/brainelectronics/micropython-winbond/tree/0.3.0
7989
[0.2.0]: https://github.com/brainelectronics/micropython-winbond/tree/0.2.0

docs/EXAMPLES.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,17 @@ from winbond import W25QFlash
2323
# check the docs of your device for further details and pin infos
2424
CS_PIN = Pin(5)
2525
spi = SPI(0)
26+
# for the BE-ESP32-01 use
27+
# CS_PIN = Pin(10)
28+
# spi = SPI(2, 2000000, sck=Pin(12), mosi=Pin(11), miso=Pin(13))
2629

2730
flash = W25QFlash(spi=spi, cs=CS_PIN, baud=2000000, software_reset=True)
31+
32+
# get Flash infos/properties
33+
print("Flash manufacturer ID: 0x{0:02x}".format(flash.manufacturer))
34+
print("Flash Memory Type: {}".format(flash.mem_type))
35+
print("Flash Device Type: 0x{0:02x}".format(flash.device))
36+
print("Flash size: {} bytes".format(flash.capacity))
2837
# manufacturer: 0xef
2938
# mem_type: 64
3039
# device: 0x4016

requirements-test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ flake8>=5.0.0,<6
44
coverage>=6.4.2,<7
55
nose2>=0.12.0,<1
66
yamllint>=1.29,<2
7+
setup2upypackage>=0.2.0,<1

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
'Development Status :: 4 - Beta',
2727
'Intended Audience :: Developers',
2828
'License :: OSI Approved :: MIT License',
29+
'Programming Language :: Python :: Implementation :: MicroPython',
2930
],
3031
keywords='micropython, winbond, library',
3132
project_urls={

winbond/winbond.py

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ def __init__(self,
3535
:param software_reset: Flag to use software reset
3636
:type software_reset: bool
3737
"""
38+
self._manufacturer = 0x0
39+
self._mem_type = 0
40+
self._device_type = 0x0
41+
self._capacity = 0
42+
3843
self.cs = cs
3944
self.spi = spi
4045
self.cs.init(self.cs.OUT, value=1)
@@ -58,12 +63,51 @@ def __init__(self,
5863
# setup address mode:
5964
if self._ADR_LEN == 4:
6065
if not self._read_status_reg(nr=16): # not in 4-byte mode
61-
print("entering 4-byte address mode")
6266
self._await()
6367
self.cs(0)
6468
self.spi.write(b'\xB7') # 'Enter 4-Byte Address Mode'
6569
self.cs(1)
6670

71+
@property
72+
def capacity(self) -> int:
73+
"""
74+
Get the storage capacity of the flash
75+
76+
:returns: Capacity of the flash in bytes
77+
:rtype: int
78+
"""
79+
return self._capacity
80+
81+
@property
82+
def device(self) -> int:
83+
"""
84+
Get the flash device type
85+
86+
:returns: Flash device type
87+
:rtype: int
88+
"""
89+
return self._device_type
90+
91+
@property
92+
def manufacturer(self) -> int:
93+
"""
94+
Get the manufacturer ID of the flash
95+
96+
:returns: Manufacturer ID of the flash
97+
:rtype: int
98+
"""
99+
return self._manufacturer
100+
101+
@property
102+
def mem_type(self) -> int:
103+
"""
104+
Get the memory type of the flash
105+
106+
:returns: Memory type of the flash
107+
:rtype: int
108+
"""
109+
return self._mem_type
110+
67111
def reset(self) -> None:
68112
"""
69113
Reset the Winbond flash if the device has no hardware reset pin.
@@ -103,7 +147,6 @@ def reset(self) -> None:
103147
self.cs(1)
104148
time.sleep_us(30)
105149
self._busy = False
106-
# print('Reset performed')
107150

108151
def identify(self) -> None:
109152
"""
@@ -132,10 +175,11 @@ def identify(self) -> None:
132175
raise OSError("manufacturer ({}) or memory type ({}) unsupported".
133176
format(hex(mf), hex(mem_type)))
134177

135-
print("manufacturer: {}".format(hex(mf))) # 0xef
136-
print("mem_type: {}".format(mem_type))
137-
print("device: {}".format(hex(mem_type << 8 | cap))) # 0x4016
138-
print("capacity: {} bytes".format(self._CAPACITY)) # 4194304 bytes
178+
self._manufacturer = hex(mf)
179+
self._mem_type = mem_type
180+
self._device_type = hex(mem_type << 8 | cap)
181+
self._capacity = self._CAPACITY
182+
139183
# return self._CAPACITY # calculate number of bytes
140184

141185
def get_size(self) -> int:
@@ -224,7 +268,6 @@ def _read(self, buf: list, addr: int) -> None:
224268
assert addr + len(buf) <= self._CAPACITY, \
225269
"memory not addressable at %s with range %d (max.: %s)" % \
226270
(hex(addr), len(buf), hex(self._CAPACITY - 1))
227-
# print("read {} bytes starting at {}".format(len(buf), hex(addr)))
228271

229272
self._await()
230273
self.cs(0)
@@ -268,7 +311,6 @@ def _write(self, buf: list, addr: int) -> None:
268311
assert addr + len(buf) <= self._CAPACITY, \
269312
("memory not addressable at {} with range {} (max.: {})".
270313
format(hex(addr), len(buf), hex(self._CAPACITY - 1)))
271-
# print("write buf[{}] to {} ({})".format(len(buf), hex(addr), addr))
272314

273315
for i in range(0, len(buf), self.PAGE_SIZE):
274316
self._wren()
@@ -296,7 +338,6 @@ def _writeblock(self, blocknum: int, buf: list) -> None:
296338
"""
297339
assert len(buf) == self.BLOCK_SIZE, \
298340
"invalid block length: {}".format(len(buf))
299-
# print("writeblock({}, buf[{}])".format(blocknum, len(buf)))
300341

301342
sector_nr = blocknum // 8
302343
sector_addr = sector_nr * self.SECTOR_SIZE

0 commit comments

Comments
 (0)