STM32L467DISC port not working?

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
roland_vs
Posts: 89
Joined: Tue Dec 08, 2015 8:28 pm
Location: Netherlands
Contact:

STM32L476DISC port peculiarities?

Post by roland_vs » Mon May 29, 2017 11:27 pm

Dear,

I have compiled the latest of mpy and flashed it into the STM32L476DISC board.
I once had it working, Flash drive and all, but after erasing and updating again it did not work anymore.

There is some odd behaviour (not related to the version 1.9.4).

No connection to the microUSB and using the REPL via the ST-LINK UART shows the MPY 1.9.4. prompt.
If I connect the USB to the microUSB port too then the board starts to reset itself every few seconds.
No drive or CDC UART appear.

DFU uploading of firmware.dfu is without any problems so it seems to be a run time problem with the code.
Anyone seen this behaviour before?

Some thing that could be a cause and part of the search...:
Is it possible due to a Flash Erase that option bits are "lost"?
Is it behaviour that is related to the LSE (32768kHz)/HSI (4MHz)
Is it the watchdog in relation with LSE/LSI?
Stray interrupt/watchdog from USB code?

Any pointers?

shaoziyang
Posts: 363
Joined: Sun Apr 17, 2016 1:55 pm

Re: STM32L467DISC port not working?

Post by shaoziyang » Tue May 30, 2017 4:41 am

I think there are some configurature may not correctlly, do you change some configurature? I will test last version of uPy in STM32L476DISC soon.

User avatar
roland_vs
Posts: 89
Joined: Tue Dec 08, 2015 8:28 pm
Location: Netherlands
Contact:

Re: STM32L467DISC port not working?

Post by roland_vs » Tue May 30, 2017 1:50 pm

I have it working now.
It seems that the dfu-util/bootloader via USB experiences some problems.
It does load w/o any errors, but the code does not run as expected:
- constantly rebooting when USB cable attached
- when USB removed REPL via UART can be used, however no file system, crashes randomly when trying to use something from some libraries.

Eventually ended up using JTAG to flash the firmware.hex and it is working as expected.

Why not immediately used JTAG? Well, using the F405, F407, F439 in the same way all worked w/o a problem...

Lost a day, learned a lot.

chrismas9
Posts: 152
Joined: Wed Jun 25, 2014 10:07 am

Re: STM32L467DISC port not working?

Post by chrismas9 » Wed Jun 07, 2017 10:12 am

I just flashed mine, and there is something a bit wonky. I got the filesystem shown, but it showed on the host as a 17 Mb filesystem, which is obviously wrong.

The filesystem also only had boot.py on it. No main.py or other files that normally show up. It also had a label of 2821-0000 rather than PYBFLASH.
I am working withthe L476 now.

@dhylands I have tested my Discovery board with 1.9 and it works with internal and external flash with no code changes needed. The external flash is 128Mbit so 16Mbyte is correct. Internal gives about 500kbyte.

The initial external flash filesystem only has boot.py and wrong label as you reported. Resetting the filesystem fixes the problem. It might be due to whatever ST load into the flash.

I mapped LED3 (yellow) to the red led so you can see the boot sequence count when pressing USR. Releasing USR during 3 (gr + yel) resets the file system and it then pops up with the usual 4 files and PYBFLASH volume name. I copied a 3.5Mbyte file to it and could open it correctly. After resetting it once the filesystem has been reliable.

@roland_vs Have you had success with ST-LINK programming. There is a bug in the L4xx bootloader that will not program the flash properly unless the binary image is 8 byte aligned. Your symptoms could well be due to partial or corrupt flash programming.

User avatar
roland_vs
Posts: 89
Joined: Tue Dec 08, 2015 8:28 pm
Location: Netherlands
Contact:

Re: STM32L467DISC port not working?

Post by roland_vs » Wed Jun 07, 2017 10:25 am

It works, however using JTAG to program the image rather than dfu-util, the aforementioned "patch" combined with the randomness of dfu-util showed that it worked, but was not the root cause.

So if I have time I will check other "dfu" programs (like python version) to see at which side the problem resides....

User avatar
roland_vs
Posts: 89
Joined: Tue Dec 08, 2015 8:28 pm
Location: Netherlands
Contact:

Re: STM32L467DISC port not working?

Post by roland_vs » Tue Sep 26, 2017 9:18 pm

To be complete:

The difference between working and not working is entirely due to the 8-byte alignment of the generated code of the L476 port. If you use DFU-UTIL to program the firmware.dfu you may run into problems when the file is not padded to fulfil the mentioned need. AN2606 of STM for further info. Also on the forum site of STM you can find an utility HEX2DFU.exe that will do the padding. Then the programming via the USB interface works OK.

Note: The port is still not "complete" as the I2C is different (HAL) and the DAC also. Try this by enabling the Accelerometer and DAC modules in mpconfigboard.h. Also the RTC is not running (other post). On the wish list would be a LCD driver for the segmented display of the STM32L476DISCO.

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

Re: STM32L467DISC port not working?

Post by dhylands » Wed Sep 27, 2017 2:11 am

Try modifying tools/dfu.py. Around line 42 you should see:

Code: Select all

    for image in target:
      tdata += struct.pack('<2I',image['address'],len(image['data']))+image['data']
Add these 2 lines:

Code: Select all

      pad = (8 - len(image['data']) % 8) % 8
      image['data'] = image['data'] + bytes(bytearray(8)[0:pad])
to make it look like:

Code: Select all

    for image in target:
      pad = (8 - len(image['data']) % 8) % 8
      image['data'] = image['data'] + bytes(bytearray(8)[0:pad])
      tdata += struct.pack('<2I',image['address'],len(image['data']))+image['data']

Post Reply