MicroPython with HSI and no HSE?

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.
Post Reply
mwm
Posts: 36
Joined: Wed Aug 09, 2017 3:52 pm

MicroPython with HSI and no HSE?

Post by mwm » Tue Sep 05, 2017 11:13 am

I'd like to get micropython working on a NUCLE-F411RE with the ST-LINK removed. On current versions the ST-LINK is the source for the HSE clock. Seems there are a number of options to fix this on the board, but the only two that don't clash with my reason for removing the ST-LINK are to buy an appropriate crystal (the one recommended by ST is no longer available, and any that match their specs are back-ordered on my favorite sites). A suggestion from their forums was to get micropython to use the HSI in lieu of the HSE. Searching the forums here seems like that's a problem - people report having problems that seem to be solved by getting an HSE.

Am I correct in assuming that getting micropython to work without an HSE isn't a solved issue, and I should keep looking for crystals?

Thanks,
Mike

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

Re: MicroPython with HSI and no HSE?

Post by chrismas9 » Tue Sep 05, 2017 3:04 pm

With two 20pF load caps (10pF in series) plus about 5pF stray you want a crystal with 15pF load spec. Any crystal with Cl=18pF should work. eg Digi-Key 535-9062-ND.

PYBv10 uses an 18pF crystal.

mwm
Posts: 36
Joined: Wed Aug 09, 2017 3:52 pm

Re: MicroPython with HSI and no HSE?

Post by mwm » Tue Sep 05, 2017 5:05 pm

Actually, they give me the specs for the crystal: 8MHz, 16pf, 20ppm.

But also needs 4 SMD parts added to the board - a pair of 20pf caps and a pair of resistors of unknown value. The schematics in the user manual just say "N/A", presumably because they aren't there ;-(.

Thanks.

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

Re: MicroPython with HSI and no HSE?

Post by chrismas9 » Wed Sep 06, 2017 1:00 am

18pF crystal will work fine. A slight mismatch will cause a very slight frequency error. You don't need 20ppm either unless you are doing very accurate frequency measurement or other timing critical stuff like high speed Ethernet. You can probably solder through hole caps onto the back of the crystal pads if that's easier and the other end to the ground plane.

mwm
Posts: 36
Joined: Wed Aug 09, 2017 3:52 pm

Re: MicroPython with HSI and no HSE?

Post by mwm » Wed Sep 06, 2017 6:22 am

I've been told that using solder bridges may work for the resistors, in that it'll either work with slightly reduced accuracy, or it'll simply fail to work at all. I'm not up to installing SMD caps, so I'd thought about using the through hole version as you said, but that sounds a bit fragile. The board is going into a robot as a control board, so that is a concern (it doesn't quite fit with the ST-LINK, which is why I want to remove the link).

I'm thinking about using an oscillator instead of just a crystal as I'd think that would be more robust. I'm going to try modding the ST-LINK I removed to provide a clock signal and configure the de-linked Nucleo for an external clock source. If that works, replacing the ST-LINK with a proper oscillator should be straightforward. On the other hand, that might still fit and has certain advantages.

The folks on the ST forum seem to think that changing the software to use the internal clock should be straightforward, but I'm not familiar with CMSIS (normally use libopencm3 or mbed) so don't really know. I'd be interested in an answer to the question about getting micropython to work using the internal clock.

mwm
Posts: 36
Joined: Wed Aug 09, 2017 3:52 pm

Post by mwm » Wed Sep 06, 2017 2:51 pm

I got a micropython repl using HSI not HSE. I found https://community.st.com/thread/28273 asking if he had it right, and used his changes.

But it's not right as is. The repl is flaky - it drops characters, and gets error characters at times. So some clock or another isn't right. pyb.freq() reports the same values as it does on a stock build.

I'm also confused by modmachine.h. It init's the HSE, but I don't need to change it there. Things work if just change the RCC init in system_stm32.f. Changing it both places doesn't help with the UART issues.

Anyone have hints as to what I need to change to get the UART working properly?

UPDATE: Well, it doesn't quite work. If I unplug the ST-LINK (which is connected to the morpho pins on the NUCLEO via it's SWD header) from the card, I no longer get a repl. Odd.
Last edited by mwm on Wed Sep 06, 2017 4:10 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: MicroPython with HSI and no HSE?

Post by dhylands » Wed Sep 06, 2017 3:24 pm

Using the HSI will lead to UART clock instability. The problem is that the HSI isn't very stable and the frequency drifts with temperature.

Looking at the datahseet, the factory calibration on the HSI is only 4%. It looks like you can get that down to 1% by calibrating it yourself using the RCC_CR register.

From the datasheet, the UART needs between 1.8% and 4.3% accuracy depending on how its configured.

Post Reply