[STM32F401CE] [pyb] import stm -- Where is stm module source? [found]

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
User avatar
jgriessen
Posts: 191
Joined: Mon Sep 29, 2014 4:20 pm
Contact:

[STM32F401CE] [pyb] import stm -- Where is stm module source? [found]

Post by jgriessen » Thu Nov 30, 2017 7:52 pm

Where is stm module source?

grep -r stm.GPIO

docs/pyboard/tutorial/assembler.rst: movwt(r0, stm.GPIOA)
does not find any that look like a file full of constants...

./stmhal/build-G30TH/genhdr/modstm_const.h is like it.
says: // Automatically generated from cmsis/stm32f401xe.h by make-stmconst.py

and here are the GPIO registers:

{ MP_OBJ_NEW_QSTR(MP_QSTR_GPIO_IDR), MP_OBJ_NEW_SMALL_INT(0x10) }, // 32-bits, GPIO port input data register
{ MP_OBJ_NEW_QSTR(MP_QSTR_GPIO_ODR), MP_OBJ_NEW_SMALL_INT(0x14) }, // 32-bits, GPIO port output data register
{ MP_OBJ_NEW_QSTR(MP_QSTR_GPIO_BSRRL), MP_OBJ_NEW_SMALL_INT(0x18) }, // 16-bits, GPIO port bit set/reset low register
{ MP_OBJ_NEW_QSTR(MP_QSTR_GPIO_BSRRH), MP_OBJ_NEW_SMALL_INT(0x1a) }, // 16-bits, GPIO port bit set/reset high register
{ MP_OBJ_NEW_QSTR(MP_QSTR_GPIO_LCKR), MP_OBJ_NEW_SMALL_INT(0x1c) }, // 32-bits, GPIO port configuration lock register
{ MP_OBJ_NEW_QSTR(MP_QSTR_GPIO_AFR0), MP_OBJ_NEW_SMALL_INT(0x20) }, // 32-bits, GPIO alternate function registers
{ MP_OBJ_NEW_QSTR(MP_QSTR_GPIO_AFR1), MP_OBJ_NEW_SMALL_INT(0x24) }, // 32-bits, GPIO alternate function registers

cmsis/stm32f401xe.h seems to come from ST, so that is my question answered with a lot of cross references.
John Griessen blog.kitmatic.com

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

Re: [STM32F401CE] [pyb] import stm -- Where is stm module source? [found]

Post by dhylands » Thu Nov 30, 2017 9:18 pm

The stm module originates from modstm.c:
https://github.com/micropython/micropyt ... 2/modstm.c
and you'll see that it has the following line:

Code: Select all

#include "genhdr/modstm_const.h"
This is a generated file. The rules to make it can be found in the Makefile:
https://github.com/micropython/micropyt ... #L468-L470
It basically scans the MCU file from the CMSIS library (for the f405 this would be lib/stm32lib/CMSIS/STM32F4xx/Include/stm32f405xx.h
From that it extracts a bunch of constants.

SpotlightKid
Posts: 463
Joined: Wed Apr 08, 2015 5:19 am

Re: [STM32F401CE] [pyb] import stm -- Where is stm module source? [found]

Post by SpotlightKid » Thu Nov 30, 2017 10:12 pm

And to make the constants from that module actually usable to access the MCUs memory, it uses 'extmod/machine_mem.c/.h'

User avatar
jgriessen
Posts: 191
Joined: Mon Sep 29, 2014 4:20 pm
Contact:

Re: [STM32F401CE] [pyb] import stm -- Where is stm module source? [found]

Post by jgriessen » Fri Dec 01, 2017 12:07 am

I'm still mystified about why the G30_TH board definition has
//#define MICROPY_HW_USB_VBUS_DETECT_PIN (pin_A9)
//#define MICROPY_HW_USB_OTG_ID_PIN (pin_A10)

They are commented out.

Since above, I found a ref to it from 2015 github where you all noticed it was always A9 pin on STM32F4, so put it off till needed change.

What is status of newer hardware definition API?

Is that anything to use on a STM32F401 new platform with a QFN chip that has need to delete some pins compared to G30TH?
John Griessen blog.kitmatic.com

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

Re: [STM32F401CE] [pyb] import stm -- Where is stm module source? [found]

Post by dhylands » Fri Dec 01, 2017 4:56 am

If you look at the schematics for the G30 TH board: http://old.ghielectronics.com/downloads ... TH_SCH.pdf

Pin A9 does NOT connect to VBUS, so it can't be used to detect if VBUS is present. Similarly pin PA10 is NOT connected to the USB connector's ID pin, so it can't be used to negotiate the ID for OTG purposes.

If you look at the pyboard schematics you'll see that PA9 is connected to VBUS and PA10 is connected to the ID pin. So these defines should be set match your actual hardware setup. It has nothing to do with the processor, but rather how the G30TH board was wired up.

In the case of VBUS detect, PA9 is the only pin that can be used, and similarly PA10 is the only pin that can be used for the ID pin.

User avatar
jgriessen
Posts: 191
Joined: Mon Sep 29, 2014 4:20 pm
Contact:

Re: [STM32F401CE] [pyb] import stm -- Where is stm module source? [found]

Post by jgriessen » Sun Dec 03, 2017 2:01 am

Pin A9 does NOT connect to VBUS, so it can't be used to detect if VBUS is present. Similarly pin PA10 is NOT connected to the USB connector's ID pin, so it can't be used to negotiate the ID for OTG purposes.
Thanks for clarifying Dave.
John Griessen blog.kitmatic.com

Post Reply