Porting to STM32F429, where to increase code size?

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.
lbattraw
Posts: 21
Joined: Sun May 10, 2015 11:35 am

Re: Porting to STM32F429, where to increase code size?

Post by lbattraw » Fri Nov 20, 2015 4:16 am

Brilliant! Great work, badi. I can confirm it works as well, both for the CDC device and mass storage.

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

Re: Porting to STM32F429, where to increase code size?

Post by dhylands » Fri Nov 20, 2015 4:36 am

I found this:

https://my.st.com/public/STe2ecommuniti ... tviews=600

The second to the last post in that thread points to a couple of bits and says that we need to

1 - Clear OTGHSULPILPEN bit in the AHB1LPENR register
2 - Set OTGHSLPEN bit in the AHB1LPENR register

and then the USB HS clock stays enabled when entering WFI sleep mode.

User avatar
badi
Posts: 50
Joined: Mon Aug 10, 2015 2:18 pm
Location: Bern, Switzerland

Re: Porting to STM32F429, where to increase code size?

Post by badi » Fri Nov 20, 2015 8:20 am

I propose following next steps which I will do:
1. Finalize testing for proper function.
2. Implement sensors on board including python access.
3. Shift flash for scripts to the second flash bank
4. ..?
Then i would like to push it to micropython main Repo.
badi

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

Re: Porting to STM32F429, where to increase code size?

Post by dhylands » Fri Nov 20, 2015 8:26 am

I would be happy to see an initial commit that just had the USB serial working (with or without MSC).

Then do additional PRs with the extra functionality. I would probably do one PR per sensor, and do the second flash bank thing as a separate PR.

Once we get SDRAM working, then we could use any of the flash sectors as part of the flash drive.

User avatar
neilh20
Posts: 37
Joined: Fri Sep 18, 2015 11:24 pm
Location: N California

Re: Porting to STM32F429, where to increase code size?

Post by neilh20 » Fri Nov 20, 2015 11:02 pm

I'm working on the STM32F429 USB_HS CDC as well.
I have a modified STM32Cube_FW_F4_V1.9.0\Projects\STM32F429I-Discovery\Demonstrations\SW4STM32, and got it working with USB_HS HOST CDC.

I am currently working at porting it back into pybV10 - story so far, so this is fantastic to see this conversation stream.

What is the best port to check - https://github.com/tobbad/micropython?

My STM32F429I-Disco setup is serial port Uart1-A10/A9 to FTDI USB cable and 5V power to CN3. I've found I need the external 5V power for serial CDC device.

I've found microPython is only defined for managing one USB at a time - either USB_FS or USB_HS .
I'd like to propose to make it work with both USB ports, since this series of hardware (F40x F42x F43x F7?? ) supports two physical UsbFullSpeed ports. Then enable code for what ever physical port is required with "USB_USB_FS " and "USE_USB_HS".
The changes I've found so far are

stm32_it.c

Code: Select all

extern PCD_HandleTypeDef pcd_fs_handle;
extern PCD_HandleTypeDef pcd_hs_handle;
....
#if defined(USE_USB_FS)
//#define OTG_XX_IRQHandler      OTG_FS_IRQHandler
//#define OTG_XX_WKUP_IRQHandler OTG_FS_WKUP_IRQHandler
//void OTG_XX_IRQHandler(void) {
void OTG_FS_IRQHandler(void) {
    HAL_PCD_IRQHandler(&pcd_fs_handle);
}
#endif
#if defined(USE_USB_HS)
//#define OTG_XX_IRQHandler      OTG_HS_IRQHandler
//#define OTG_XX_WKUP_IRQHandler OTG_HS_WKUP_IRQHandler
//void OTG_XX_IRQHandler(void) {
void OTG_HS_IRQHandler(void) {
    HAL_PCD_IRQHandler(&pcd_hs_handle);
}

#if defined(USE_USB_FS)
void OTG_FS_WKUP_IRQHandler(void) {

  if ((&pcd_fs_handle)->Init.low_power_enable) {
.....
//#ifdef USE_USB_FS
  /* Clear EXTI pending Bit*/
  __HAL_USB_FS_EXTI_CLEAR_FLAG();
//#elif defined(USE_USB_HS)
    /* Clear EXTI pending Bit*/
//  __HAL_USB_HS_EXTI_CLEAR_FLAG();
//#endif

}
#endif

<<<then repeat above for void OTG_HS_WKUP_IRQHandler>>

#endif
then in usbd_conf.c

Code: Select all

#ifdef USE_USB_FS
PCD_HandleTypeDef pcd_fs_handle;
#endif 
#ifdef USE_USB_HS
PCD_HandleTypeDef pcd_hs_handle;
#endif

<<< USBD_LL_Init changes for above>>
I've compiled the above, but not run tested it yet.

User avatar
badi
Posts: 50
Joined: Mon Aug 10, 2015 2:18 pm
Location: Bern, Switzerland

Re: Porting to STM32F429, where to increase code size?

Post by badi » Sun Nov 22, 2015 3:55 pm

What is the best port to check - https://github.com/tobbad/micropython?
Just use the stm32f429_integration branch. I will push that further till I get to a version which I will push back to micropythons main repo.
badi

User avatar
neilh20
Posts: 37
Joined: Fri Sep 18, 2015 11:24 pm
Location: N California

Re: Porting to STM32F429, where to increase code size?

Post by neilh20 » Tue Nov 24, 2015 2:03 am

Yup that worked for me.
I pulled your stm32f429_integration on to ubuntu, built it with
make BOARD=STM32F429DISC
I have a miniUSB connected to the F429DISCO STLink
I have a microUSB connected to the F429Disco USB_HS port
Then started the ST-Link Utility/Windows8,
From Target.Connect connected to the ST-Link,
Target.Program - selected over my network to
micropython_tobbad\stmhal\build-STM32F429DISC\Firmware.hex
(Start address fixed at 0x0800 0000) - then Start - and it flashed it in 10secs.

Connected with TeraTerm/Win8 - selected the new comPort that appeared,
Hey presto
"MicroPython v1.4.5-492-gbc1f632 on 2015-11-23; F429I-DISCO with STM32F429
Type "help()" for more information.
>>>
"
Thats great it show the USB_HS port with the FS phy code init is good, and that little WIFI issue :D .

I am looking to have both USB phy running at the same time - which of course doesn't work for the F429I-DISCO but can do for the PYB10.
I'm using a USB A receptacle/cable on the PYB10 board to provide a host with power connection.
I have the F429DISCO demo modified that can do the supplied MSC and CDC working, (but not OTG). So I'll switch to my thread for that discussion. :)
http://forum.micropython.org/viewtopic. ... 2&start=20

lbattraw
Posts: 21
Joined: Sun May 10, 2015 11:35 am

Re: Porting to STM32F429, where to increase code size?

Post by lbattraw » Thu Nov 26, 2015 12:26 pm

Hi, I went to pull any updates from badi's repo and it appears that the changes have been removed (The entire integration branch) and rolled into the main MicroPython repo. That would be fine but something got broken along the way and it no longer boots with USB CDC/mass storage support. I haven't gotten around to connecting the serial port up to see if there are any errors being reported, just wanted to let people know. Badi, have you or anyone else been able to test the code now it's in the main repo?

Thanks!
Larry

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

Re: Porting to STM32F429, where to increase code size?

Post by dhylands » Thu Nov 26, 2015 4:19 pm

I just built using the latest master (364bb61df339c5012fb2d5c4f05af4c57347aa09) and it seems to work for me.

To build:

Code: Select all

make BOARD=STM32F429DISC
To flash and wipe the filesystem:

Code: Select all

arm-none-eabi-objcopy -O binary -j .isr_vector -j .text -j .data build-STM32F429DISC/firmware.elf build-STM32F429DISC/firmware.bin
st-flash --reset write build-STM32F429DISC/firmware.bin 0x08000000
To flash and preserve the filesystem:

Code: Select all

arm-none-eabi-objcopy -O binary -j .isr_vector build-STM32F429DISC/firmware.elf build-STM32F429DISC/firmware0.bin
arm-none-eabi-objcopy -O binary -j .text -j .data build-STM32F429DISC/firmware.elf build-STM32F429DISC/firmware1.bin
st-flash write build-STM32F429DISC/firmware0.bin 0x08000000
st-flash --reset write build-STM32F429DISC/firmware1.bin 0x08020000
CDC and MSC both seem to be working.

Code: Select all

MicroPython v1.5.1-24-g364bb61 on 2015-11-26; F429I-DISCO with STM32F429
Type "help()" for more information.
>>> 
I use a GNUmakefile to automate my flashing steps. My GNUmakefile (note the lowercase m in makefile) looks like this:

Code: Select all

$(info Executing GNUmakefile)

#BOARD = STM32F7DISC
BOARD = STM32F429DISC
#BOARD = PYBV10

$(info BOARD = $(BOARD))

#DFU_UTIL = dfu-util -s :leave
#USE_PYDFU = 1

include Makefile

.PHONY: stlink

stlink-erase-fs: $(BUILD)/firmware.elf
	$(ECHO) "Writing flash"
	$(Q)$(OBJCOPY) -O binary -j .isr_vector -j .text -j .data $^ $(BUILD)/firmware.bin
	$(Q)st-flash --reset write $(BUILD)/firmware.bin 0x08000000

stlink: $(BUILD)/firmware.elf
	$(ECHO) "Writing flash"
	$(Q)$(OBJCOPY) -O binary -j .isr_vector $^ $(BUILD)/firmware0.bin
	$(Q)st-flash write $(BUILD)/firmware0.bin 0x08000000
	$(Q)$(OBJCOPY) -O binary -j .text -j .data $^ $(BUILD)/firmware1.bin
	$(Q)st-flash --reset write $(BUILD)/firmware1.bin 0x08020000
	
show-board:
	$(ECHO) "BOARD = ${BOARD}"
and with that you can use:

Code: Select all

make BOARD=STM32F429DISC stlink-erase-fs
or

Code: Select all

make BOARD=STM32F429DISC stlink
If you build primarily for the STM32F429DISC, then setup the BOARD appropriately near the top of the file and you no longer have to pass in the BOARD=STM32F429DISC on the command line.

I'll take the above and put it on the Wiki page for the 429.

I also managed to screw things up by flashing the regular pyboard image (by forgetting to pass in the BOARD=STM32F429DISC) instead of the 429 image, so I'll put down my recovery steps on the wiki as well.

lbattraw
Posts: 21
Joined: Sun May 10, 2015 11:35 am

Re: Porting to STM32F429, where to increase code size?

Post by lbattraw » Fri Nov 27, 2015 5:40 am

Hi Dave,

Thanks for the makefile and instructions. I still ended up having problems with the firmware that was generated and so I decided to try and build it in another tree I keep around for situations like this (That hasn't been modified at all). That build worked, so I suppose I did something wrong in the original repo to cause the issues. It seems like this has happened in other git repos I've used before, making it fail to build or corrupting the tree, requiring a fresh clone to get it working again. Git is powerful but it's way too easy to get it (Or me) confused at times.

Thanks again for the help!
Larry

Post Reply