[STM32F401CE]new board definition mpconfigboard.h

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.
User avatar
jgriessen
Posts: 191
Joined: Mon Sep 29, 2014 4:20 pm
Contact:

[STM32F401CE]new board definition mpconfigboard.h

Post by jgriessen » Sat Dec 02, 2017 3:44 pm

OTG_FS_DM and OTG_FS_DP only show up in the ports/stm32/boards/stm32f401_af.csv file.

They are not present in any board definitions. Is there no way to ever change the USB pins used from defaults?

I see in the Alt Functions table there is no other set of pins the USB shows on, so I guess that is why.

Not having a 1 to 1 correspondence between lines in mpconfigboard.h and pins available in a MCU package makes
checking for correctness harder. Would it be OK to find the underlying lines similar to
#define MICROPY_HW_USB_OTG_ID_PIN (pin_A10)
and include them in mpconfigboard.h?

Lines about OTG_FS_DM, OTG_FS_DP, OTG_FS_SOF?

Where are they?

Also JTAG -- it only shows in the stm32f401_af.csv file, and then that name does not match what is in STM32 AF table.
When I grep for matches three seems to be disagreement between stm32f4xx_af.csv files on those names:

Code: Select all

john@toolbench64 [micropython]grep -r SWDIO
ports/stm32/boards/stm32f439_af.csv:PortA,PA13,JTMS-SWDIO,,,,,,,,,,,,,,,EVENTOUT,
ports/stm32/boards/stm32f411_af.csv:PortA,PA13,JTMS-SWDIO,,,,,,,,,,,,,,,EVENTOUT,
ports/stm32/boards/stm32f429_af.csv:PortA,PA13,JTMS-SWDIO,,,,,,,,,,,,,,,EVENTOUT,
ports/stm32/boards/stm32l476_af.csv:PortA,PA13,JTMS-SWDIO,IR_OUT,,,,,,,,,OTG_FS_NOE,,,,,EVENTOUT,,
ports/stm32/boards/stm32f746_af.csv:PortA,PA13,JTMS,SWDIO,,,,,,,,,,,,,,EVENTOUT
ports/stm32/boards/stm32f767_af.csv:PortA,PA13,JTMS,SWDIO,,,,,,,,,,,,,,EVENTOUT
ports/stm32/boards/stm32f401_af.csv:PortA,PA13,JTMS_SWDIO,,,,,,,,,,,,,,,EVENTOUT,
Some lines have two fields: JTMS,SWDIO
some have a dash: JTMS-SWDIO
The F401 file, tested on G30_TH platform has JTMS_SWDIO, which is same as in STM32 datasheet table 9 of AltFunctions -- AF.

Is this mismatching a mistake?
Last edited by jgriessen on Wed Apr 11, 2018 2:55 pm, edited 1 time in total.
John Griessen blog.kitmatic.com

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

Re: new board definition mpconfigboard.h

Post by dhylands » Sun Dec 03, 2017 5:29 am

The ones that are JTMS,SWDIO are probably correct. There are 2 signals here, JTMS for JTAG and SWDIO for SWD. The convention used in the _af.csv file is that if there are multiple distinct signals assigned to an alternate function then they should be separated by slashes. So the ones that use a dash or underscore should really be JTMS/SWDIO since JTMS is one signal, and SWDIO is another.

Currently, the script which generates pin definitions ignores JTMS and SWDIO so the fact that they're JTSM_SWDIO or JTMS-SWDIO is more or less inconsequential, but they really should be JTMS/SWDIO.

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

Re: new board definition mpconfigboard.h

Post by jgriessen » Sun Dec 03, 2017 4:35 pm

The ones that are JTMS,SWDIO are probably correct.
It looks to me like the commas are about which AF is being chosen in one field, so going to two fields for a signal such as these that are in one field in the datasheet is probably wrong:

Datasheet spellings of AF0 column of table 9. Alternate function mapping:
JTMS_SWDIO, JTCK_SWCLK, JTDI, JTDO-SWO, JTRST

Currently, the script which generates pin definitions ignores JTMS and SWDIO
Then is nothing needed to use JTAG besides a stm.mem32 register write or three?

Can this be added to micropython board definitions easily now? Maybe now is the time to create a
MICROPY_HW_HAS_JTAG and a script jtag.c, and maybe a MICROPY_HW_HAS_SWD and a script swd.c

The ARM debug connector docs have different names than STM chose, and that is OK by me. I would just leave the names as in the STM datasheet and ref manual for F401.
John Griessen blog.kitmatic.com

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

Re: new board definition mpconfigboard.h

Post by dhylands » Mon Dec 04, 2017 6:49 pm

I don't think that anything is required in order to use JTAG for basic debugging. Some code would need to be written if you were trying to support semi-hosting or something along those lines. But all of the debug functionality should work "out of the box".

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

Re: new board definition mpconfigboard.h

Post by jgriessen » Sat Dec 09, 2017 10:28 pm

I don't think that anything is required in order to use JTAG for basic debugging.
I'm thinking of boundary scan tests.
More than the pins used for SWD.

Are pins PA13 JTMS_SWDIO, PA14 JTCK, PA15 JTDI, PB3 JTDO_SWO, PB4 NJTRST, all initialized?

Searching for clues shows:

grep -r JTMS

ports/stm32/boards/stm32f401_af.csv:PortA,PA13,JTMS_SWDIO,,,,,,,,,,,,,,,EVENTOUT,

Searching for lower case yields nothing and the other pin names show up only in the stm32f4xx_af.csv files. The real setup code must be in a library out of the micropython tree...
John Griessen blog.kitmatic.com

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

Re: new board definition mpconfigboard.h

Post by dhylands » Tue Dec 12, 2017 4:18 pm

My understanding is that the JTAG and SWD functions are initialised by the MCU when it comes out of RESET, which is why you won't find any code to do it.

plunk
Posts: 11
Joined: Thu Oct 05, 2017 1:54 pm

Re: new board definition mpconfigboard.h

Post by plunk » Tue Dec 12, 2017 6:10 pm

I would also like to know how to remap the USB pins. I am using the STM32F429DISC micropython port on a custom board and would like to use PA11/PA12 as D-/D+ instead of PB14/PB15.

The only reference I can find to these pins is a comment in mpconfigboard.h: "THE HS USB uses B14 & B15 for D- and D+".
https://github.com/micropython/micropyt ... oard.h#L39

I apologize if this is an ignorant question, the custom board design is not mine and I am inexperienced with much of this.

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

Re: new board definition mpconfigboard.h

Post by dhylands » Wed Dec 13, 2017 3:10 pm

The 429 has OTG_HS_DM & DP on PB13/14 and has OTG_FS_DM & DP on PA11/12.

These pins don't have any alternate mappings, so you need to use the functionality on those pins. So what I'm saying is that you can't move the OTG_HS pins to anywhere other than PB13 & 14. However, you can change which USB (HS versus FS) is used (which is what I think you're really asking).

If you look in ports/stm32/boards/STM32F429DISC/stm32f4xx_hal_conf.h you'll find:

Code: Select all

#define USE_USB_HS
#define USE_USB_HS_IN_FS
If you look in the same file for the PYBV11, you'll see:

Code: Select all

#define USE_USB_FS
So you should be able to change between HS & FS by swapping out those defines for each other.

plunk
Posts: 11
Joined: Thu Oct 05, 2017 1:54 pm

Re: new board definition mpconfigboard.h

Post by plunk » Mon Dec 18, 2017 10:24 pm

Dave,

Thank you for your response. To try to clarify, the board I am developing on uses a F427 (running the F429DISC port) and two USB PHYs:
  1. a USB type-B PHY that currently is only supplying power to the board, but has its DM/DP pins connected to the F427's PA11/PA12
  2. a micro-USB PHY that has its DM/DP pins connected to the F427's PB14/PB15 pins, through which I can access the REPL
I would like to access the REPL via the USB type-B PHY (1) instead of the micro-USB PHY (2).

Changing my stm4fxx_hal_conf.h file to the following does not work:

Code: Select all

//#define USE_USB_HS
//#define USE_USB_HS_IN_FS
#define USE_USB_FS
After flashing the board with that change, the result is that the COM port (COM5) associated with PHY 2 disappears from Device Manager, so I cannot access the REPL any longer. A new COM port is not added for PHY 1, which is what I would like to accomplish.
Last edited by plunk on Tue Jan 02, 2018 10:29 pm, edited 1 time in total.

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

Re: new board definition mpconfigboard.h

Post by dhylands » Tue Dec 19, 2017 1:55 am

DFU should work on PA11 and PA12. Does this show up when you boot the MCU up in DFU mode?

Make sure you didn't swap DM and DP.

What does your board definition file (mpconfigboard.h) have for MICROPY_HW_USB_VBUS_DETECT_PIN ? If its set and VBUS isn't connected to pin A9, then it won't enable USB.

Post Reply