WeAct STM32F411CEU6 black pill

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
RDA
Posts: 9
Joined: Fri Oct 30, 2020 9:55 am

Re: WeAct STM32F411CEU6 black pill

Post by RDA » Wed Dec 09, 2020 11:41 am

Hello,

So managed to get my hands on one of these. I added a SPI flash, setup a virtual debian and managed to flash the board.

All was fine but ran into some issues that I believe are related to the the pin naming, I have been searching the internet for answers but cant get anywhere. So the issue is trying to use machine (most probably also everywhere else). So trying to toggle the internal led gets me nowhere using "machine" but "pyb" works, meaning:

Code: Select all

MicroPython v1.13-243-g032e09562 on 2020-12-09; WeAct F411CE with STM32F411CE
Type "help()" for more information.
>>> import pyb
>>> led = pyb.LED(1)
>>> led.on()
>>> led.off() 
This turns the lled on/off like it should. Then trying using "machine":

Code: Select all

MicroPython v1.13-243-g032e09562 on 2020-12-09; WeAct F411CE with STM32F411CE
Type "help()" for more information.
>>> import machine
>>> pin = machine.Pin(PC13, machine.Pin.OUT)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'PC13' isn't defined
>>> pin = machine.Pin(C13, machine.Pin.OUT)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'C13' isn't defined
>>> pin = machine.Pin(2, machine.Pin.OUT)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can't convert 'int' object to str implicitly
>>>
I cant figure out whats wrong, I assume its about the pin "name" PC13 is what it says in most documents, C13 can be found in mpconfigboard.h as the dfined blue led and "2" is referred as the physical number in most pin outs.

Maybe the pin numbers are derived from the X and Y from pyboard?

If someone could nudge me to the correct direction it would be most helpful.

User avatar
RobH
Posts: 56
Joined: Fri Mar 23, 2018 3:37 pm
Location: Netherlands
Contact:

Re: WeAct STM32F411CEU6 black pill

Post by RobH » Wed Dec 09, 2020 1:46 pm

The pin name should be specified as string, like:

pin = machine.Pin("C13", machine.Pin.OUT)

User avatar
dhylands
Posts: 3628
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: WeAct STM32F411CEU6 black pill

Post by dhylands » Wed Dec 09, 2020 6:14 pm

Without the quotes, you'd need to use something like machine.Pin.cpu.C13

You can find all of the defined pins by using:

Code: Select all

dir(machine.Pin.cpu)
or dir(machine.Pin.board)

The mapping is provided by the pins.csv file from your board definition file:
https://github.com/mcauser/WEACT_F411CE ... r/pins.csv

The first column contains board pin names and the second column contains the CPU names (the leading P is stripped off). The P is present because that's what's in the docs.

RDA
Posts: 9
Joined: Fri Oct 30, 2020 9:55 am

Re: WeAct STM32F411CEU6 black pill

Post by RDA » Wed Dec 09, 2020 7:17 pm

RobH wrote:
Wed Dec 09, 2020 1:46 pm
The pin name should be specified as string, like:

pin = machine.Pin("C13", machine.Pin.OUT)
dhylands wrote:
Wed Dec 09, 2020 6:14 pm
Without the quotes, you'd need to use something like machine.Pin.cpu.C13

You can find all of the defined pins by using:

Code: Select all

dir(machine.Pin.cpu)
or dir(machine.Pin.board)

The mapping is provided by the pins.csv file from your board definition file:
https://github.com/mcauser/WEACT_F411CE ... r/pins.csv

The first column contains board pin names and the second column contains the CPU names (the leading P is stripped off). The P is present because that's what's in the docs.
Thank you gentlemen! I assumed it was something simple and seems it was, this is nice

Code: Select all

dir(machine.Pin.cpu)
.
Again thanks for the help and mcauser for the project.

RDA
Posts: 9
Joined: Fri Oct 30, 2020 9:55 am

Re: WeAct STM32F411CEU6 black pill

Post by RDA » Fri Dec 11, 2020 8:10 pm

I have had just a small dive into uPython and I rellay like it.

So a combination of windows, blackpill as a "usb storage" and me fooling around got me to corrupt the files pretty quickly (based on google im not alone). For testing purposes it doesnt really matter much, as I can test the things I want to play with with Putty. BUT hopefully in the xmas holidays I will have some time to start trying to actually do something else than toggling leds and reading buttons, I want to do this "properly" using VScode.

So my question is, would it be possible to change the USB configuration (sorry for the wrong terminology). So I would like to keep the USB as a "REPL" only like an ESP (I undestand thats from a hardware limitation). Im hoping that this way I could avoid file corruptions?

Would the boardconfigs have a way to disable the USB, or someway to lock the filesystem? Sorry not really sure exactly what I am looking for but hopefully someone understands.

User avatar
mcauser
Posts: 492
Joined: Mon Jun 15, 2015 8:03 am

Re: WeAct STM32F411CEU6 black pill

Post by mcauser » Fri Dec 11, 2020 9:14 pm

You can switch off USB mass storage in boot.py
See: http://docs.micropython.org/en/latest/p ... mouse.html

I think littlefs also doesn’t work with USB mass storage, only fat, so you could try reformatting it. Anyone else able to confirm this?

ESP ports don’t have USB mass storage support, so they now default to littlefs.

RDA
Posts: 9
Joined: Fri Oct 30, 2020 9:55 am

Re: WeAct STM32F411CEU6 black pill

Post by RDA » Fri Dec 11, 2020 10:15 pm

mcauser wrote:
Fri Dec 11, 2020 9:14 pm
You can switch off USB mass storage in boot.py
See: http://docs.micropython.org/en/latest/p ... mouse.html

I think littlefs also doesn’t work with USB mass storage, only fat, so you could try reformatting it. Anyone else able to confirm this?

ESP ports don’t have USB mass storage support, so they now default to littlefs.
Ok, this is looking good. I assume I need to build the firmware to include littlefs?
If I do:

Code: Select all

import os
dir(os)
['__class__', '__name__', 'remove', 'sep', 'VfsFat', 'chdir', 'dupterm', 'getcwd', 'ilistdir', 'listdir', 'mkdir', 'mount', 'rename', 'rmdir', 'stat', 'statvfs'            , 'sync', 'umount', 'uname', 'unlink']
I see only VfsFat.

This:

Code: Select all

import pyb
pyb.usb_mode('VCP+HID') # act as a serial device and a mouse
did make the board as a serial device so I can work with this but somehow I think the littlefs would be the "correct" solution.

If anyone can nudge me to the correct direction Ill try and figure it out.

Ooh and running MicroPython v1.13-243-g032e09562 on 2020-12-09;

RDA
Posts: 9
Joined: Fri Oct 30, 2020 9:55 am

Re: WeAct STM32F411CEU6 black pill

Post by RDA » Tue Dec 15, 2020 8:36 am

If possible, could someone please help on where to look in building a firmware that includes LFS? Again not sure but the above

Code: Select all

dir(os)
should return also LFS if installed?

Looking at the build-WEACT_F411CEU6/extmod/ I can see LFS files. I assume I would need to edit the makefile or copy/move the LFS modules to the directory where the make pulls them from? This is still "far" from making it the default filesystem but would be nice to learn how to add custom mudules to the bin.

Does this have something to do with the formatting (from the makefile)?

Code: Select all

# We put several files into the first 16K section with the ISRs.
# If we compile these using -O0 then it won't fit. So if you really want these
# to be compiled with -O0, then edit boards/common.ld (in the .isr_vector section)
# and comment out the following lines.
$(BUILD)/$(OOFATFS_DIR)/ff.o: COPT += -Os
$(filter $(PY_BUILD)/../extmod/vfs_fat_%.o, $(PY_O)): COPT += -Os
$(PY_BUILD)/formatfloat.o: COPT += -Os
$(PY_BUILD)/parsenum.o: COPT += -Os
$(PY_BUILD)/mpprint.o: COPT += -Os
The HID+serial mode above wasnt a final solution as it started to pop up as a usb flash again while using vscode and pymkr.

EDIT:
So seems installing/flashing the LFS seems quite easy and can be done from REPL

Code: Select all

# STM32
import os, pyb
os.umount('/flash')
os.VfsLfs2.mkfs(pyb.Flash(start=0))
os.mount(pyb.Flash(start=0), '/flash')
os.chdir('/flash')
Would be nice though to flash it directly in the bin file, but even to try the above, I need to get LFS installed.

User avatar
dhylands
Posts: 3628
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: WeAct STM32F411CEU6 black pill

Post by dhylands » Tue Dec 15, 2020 3:57 pm

This dir command won't tell you what files exist on a filesystem. It's used for obtaining information about python objetcs.

Instead, use the

Code: Select all

os.listdir()
command. On my pyboard, I see something like this (with some files populated):

Code: Select all

>>> import os
>>> os.listdir()
['main.py', 'pybcdc.inf', 'README.txt', 'boot.py', 'unittest.py', 'bioloid', 'run_tests.py', 'tests', '.fseventsd']
>>> os.listdir('/')
['flash']
>>> os.listdir('/flash')
['main.py', 'pybcdc.inf', 'README.txt', 'boot.py', 'unittest.py', 'bioloid', 'run_tests.py', 'tests', '.fseventsd']
>>> os.listdir('/flash/bioloid')
['packet.py', 'dump_mem.py', 'device.py', 'bus.py', 'socket_port.py', 'serial_port.py', 'stm_usb_port.py', 'stm_uart_port.py', 'serial_bus.py']
>>> 
Using rshell you can use more unix like commands:

Code: Select all

/Users/davehylands/micropython> ls /flash
bioloid/     tests/       boot.py      main.py      run_tests.py unittest.py  README.txt   pybcdc.inf  
/Users/davehylands/micropython> ls -l /flash
   528 Sep 21 11:39 README.txt
     0 Dec 12 09:12 bioloid/
   302 Sep 21 11:39 boot.py
    34 Sep 21 11:39 main.py
  2786 Sep 21 11:39 pybcdc.inf
    64 Dec 12 10:55 run_tests.py
     0 Dec 12 09:15 tests/
  6064 Dec 12 10:16 unittest.py
/Users/davehylands/micropython> ls -l /flash/bioloid
  8936 Dec 12 10:52 bus.py
 10829 Dec 12 10:52 device.py
  2305 Dec 12 09:13 dump_mem.py
  8182 Dec 12 09:13 packet.py
  1580 Dec 12 10:53 serial_bus.py
  1622 Dec 12 10:52 serial_port.py
  1244 Dec 12 10:52 socket_port.py
  4379 Dec 12 10:53 stm_uart_port.py
  1538 Dec 12 10:52 stm_usb_port.py
/Users/davehylands/micropython> 

RDA
Posts: 9
Joined: Fri Oct 30, 2020 9:55 am

Re: WeAct STM32F411CEU6 black pill

Post by RDA » Tue Dec 15, 2020 7:16 pm

Sorry Im learning as I go and thank you for the message.

So I was not trying to look what files are in the file system but what modules can be used. As looking around the big ol internet, people say little file system is a lot more robust than fat, I was hoping to convert into using lfs or probably lfs2.

So I assumed dir(os) would list all possible modules under os and that lfs would show up too. As it did not I assumed its not in the binary, maybe I am mistaken? How would one go to verify all the modules in the baord?

Post Reply