Porting micropython to STM32Nucleo-F4

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.
cnoviello
Posts: 5
Joined: Thu May 28, 2015 5:54 am

Porting micropython to STM32Nucleo-F4

Post by cnoviello » Thu May 28, 2015 6:14 am

Hi,
I've successfully ported micropython on a STM32Nucleo-F401RE board. I can access to REPL console and interacting with led on board.

I've defined a new board following the code of already existing board definitions. But, I've a problem related with port pin generation and I suspect that is related to pins.csv file that I've copied from STM32F4DISC board. When i compile miropython, the following error is generated:

Code: Select all

CC pin.c
In file included from ../py/mpstate.h:34:0,
                 from ../py/runtime.h:29,
                 from pin.c:32:
build-STM32F4NUCLEO/genhdr/pins_af_const.h:14:65: error: 'GPIO_AF5_SPI3' undeclared here (not in a function)
     { MP_OBJ_NEW_QSTR(MP_QSTR_AF5_SPI3),   MP_OBJ_NEW_SMALL_INT(GPIO_AF5_SPI3) },
                                                                 ^
../py/obj.h:79:66: note: in definition of macro 'MP_OBJ_NEW_SMALL_INT'
 #define MP_OBJ_NEW_SMALL_INT(small_int) ((mp_obj_t)((((mp_int_t)(small_int)) << 1) | 1))
                                                                  ^
make: *** [build-STM32F4NUCLEO/pin.o] Error 1
make: *** Waiting for unfinished jobs....
Looking in STM32Cube-F4 HAL library, that alternate function is not defined for F401RE chip, and it's obviously that the error is raised. If I simply delete that line from pins_af_const.h file, all compiles great. But, I want to make all things working smooth :D

Any hints?

Carmine
Last edited by cnoviello on Thu Jun 04, 2015 4:12 am, edited 1 time in total.

Damien
Site Admin
Posts: 605
Joined: Mon Dec 09, 2013 5:02 pm

Re: Trying to understand pins.csv format

Post by Damien » Thu May 28, 2015 6:30 am

Did you edit mpconfigboard.mk (it has 2 lines in it) and change both lines from 405 to 401?

cnoviello
Posts: 5
Joined: Thu May 28, 2015 5:54 am

Re: Trying to understand pins.csv format

Post by cnoviello » Thu May 28, 2015 7:41 am

Yes. I already did it. You can check the whole board configuration here:

https://github.com/cnoviello/micropytho ... 32F4NUCLEO

cnoviello
Posts: 5
Joined: Thu May 28, 2015 5:54 am

Re: Trying to understand pins.csv format

Post by cnoviello » Thu May 28, 2015 2:26 pm

Ok. Forget this post. Populating the file pins.csv with the right pins resolve the issue. ;)

lchindeko
Posts: 4
Joined: Wed May 27, 2015 1:12 am

Re: Trying to understand pins.csv format

Post by lchindeko » Fri May 29, 2015 3:03 am

Hi cnoviello,
Could you please update the pin.csv file on your github repo, thanks

Best regards
lchindeko

cnoviello
Posts: 5
Joined: Thu May 28, 2015 5:54 am

Re: Trying to understand pins.csv format

Post by cnoviello » Fri May 29, 2015 6:23 am

Hi lchindeko,
I've updated the repo right now. The board definition is almost complete.

cnoviello
Posts: 5
Joined: Thu May 28, 2015 5:54 am

Re: Trying to understand pins.csv format

Post by cnoviello » Wed Jun 03, 2015 1:44 pm

Hi guys,
for those interested in using uPython on STM32Nucleo board, I've written a small post on my blog with all instructions.

http://www.carminenoviello.com/en/2015/ ... nucleo-f4/

I've also added to uPython a way to upload files to internal Nucleo flash. It's really bare-bone, but it works.

Hope it helps.

Carmine

mike38
Posts: 3
Joined: Tue Aug 25, 2015 4:09 pm

Re: Porting micropython to STM32Nucleo-F4

Post by mike38 » Tue Aug 25, 2015 4:13 pm

Hi,

I managed to install micropython to a nucleo F401 and it works pretty well! Thanks for the job.
I managed to drive two stepper motors in a very nice way.

Yet I encounter an issue, I have some output which should be set with an
internal Pull-up, and it does not work, the output remains low even if
there is nothing connected to. (if I put an external pull up it works, but I would have to redesign all my circuit...)

Are you aware of this issue? Is it a bug or a work in progress of the port or a nucleo
limitation?

Thanks for help!

Mike

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

Re: Porting micropython to STM32Nucleo-F4

Post by dhylands » Tue Aug 25, 2015 5:40 pm

Having the internal pull-up enabled will only be significant for when the pin is configured as an Input or in OUT_OD (Open Drain) mode.

When the pin is configured in OUT_PP mode (push-pull) then the output value of the pin overrides the pull-up. You should use something like:

Code: Select all

pin = pyb.Pin('X1', pyb.Pin.OUT_PP);
pin.value(1);
to set the pin high.

mike38
Posts: 3
Joined: Tue Aug 25, 2015 4:09 pm

Re: Porting micropython to STM32Nucleo-F4

Post by mike38 » Wed Aug 26, 2015 10:11 pm

I manage to scramble input and output after many tries :oops:
Thanks for help, now it nearly works.

I still have an issue on pin D8 or PA9

Code: Select all

g = pyb.Pin('PA9', pyb.Pin.IN, pull=1);
g.value()
returns 0 even if the pin is not connected and nothing is on the board? I can change it to 1 if I connect to 3.3V, so I check the good pin.
Is it possible to check the configuration of the pin in micropython and see if pullup resistor is enabled? May it be a hardware error?

thanks for help

Mike

Post Reply