[STM32L432 - NUCLEO 32]

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.
neoclassic
Posts: 8
Joined: Wed Aug 30, 2017 8:58 am

Re: [STM32L432 - NUCLEO 32]

Post by neoclassic » Tue Dec 11, 2018 5:05 pm

Excellent job! I´ve installed micropython in a couple of boards and works great but I`ve seen an issue. I need to use pins PC14 and PC15 so I unsordered junpers SB5 and SB7 an set #define MICROPY_HW_ENABLE_RTC (0) in the mpconfigboard.h but with this change the REPL no longers works (I can not connect with the board), I dont know how to fix it , any hint please?.
I also wonder if exists any way to load a simple python file (main.py to execute at boot) as ampy does not work as it doesn´t support internal flash storage (it is a 256K part).
Thank you very much.
nucleo32.png
nucleo32.png (36.07 KiB) Viewed 5542 times

OutoftheBOTS_
Posts: 847
Joined: Mon Nov 20, 2017 10:18 am

Re: [STM32L432 - NUCLEO 32]

Post by OutoftheBOTS_ » Tue Dec 11, 2018 8:04 pm

boochow wrote:
Tue Nov 27, 2018 5:22 pm
This tiny board is cute. I got one for me today and have been trying to port uPy.
I made board configuration files and tried to build it then found that STM32L432 lacks some commonly used peripherals TIM3 and SPI2 so it seems that we have to modify some stm32 port sources.
If u like smal little boards I saw this 1 the other day https://www.aliexpress.com/item/NEW-Lic ... 1ac79279a1

It is the size of a SD card with an ARM 926ej-s CPU running at 900MHz and has 44 pin 1.27mm pitch header and 20 pin 2.54mm pitch header as well as SD card slot and parallel LCD interface and 16Mb flash and 32Mb RAM
Linux-Board-SD-Card-Size.jpg
Linux-Board-SD-Card-Size.jpg (96.34 KiB) Viewed 5533 times

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

Re: [STM32L432 - NUCLEO 32]

Post by dhylands » Tue Dec 11, 2018 8:48 pm

I made the following changes to system_stm32.c in order to get it to boot with SB5 & SB7 removed

Code: Select all

index e0e27cef0..4d119e16b 100644
--- a/ports/stm32/system_stm32.c
+++ b/ports/stm32/system_stm32.c
@@ -419,8 +419,8 @@ void SystemClock_Config(void)
     #endif
     RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
     #elif defined(STM32L4)
-    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE|RCC_OSCILLATORTYPE_MSI;
-    RCC_OscInitStruct.LSEState = RCC_LSE_ON;
+    RCC_OscInitStruct.OscillatorType = /*RCC_OSCILLATORTYPE_LSE|*/RCC_OSCILLATORTYPE_MSI;
+    RCC_OscInitStruct.LSEState = RCC_LSE_OFF;
     RCC_OscInitStruct.MSIState = RCC_MSI_ON;
     RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;
     RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_6;
@@ -574,7 +574,7 @@ void SystemClock_Config(void)
     PeriphClkInitStruct.Sai1ClockSelection = RCC_SAI1CLKSOURCE_PLLSAI1;
     PeriphClkInitStruct.AdcClockSelection = RCC_ADCCLKSOURCE_PLLSAI1;
     PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_PLLSAI1;
-    PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
+    // PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
     PeriphClkInitStruct.RngClockSelection = RCC_RNGCLKSOURCE_PLLSAI1;
     PeriphClkInitStruct.PLLSAI1.PLLSAI1Source = RCC_PLLSOURCE_MSI;
     PeriphClkInitStruct.PLLSAI1.PLLSAI1M = 1;
to summarize, inside the SystemClock_Config function, around line 422,
https://github.com/micropython/micropyt ... m32.c#L422
I removed RCC_OSCILLATORTYPE_LSE and changed the next line from RCC_LSE_ON to RCC_LSE_OFF
and then on this line:
https://github.com/micropython/micropyt ... m32.c#L577
I changed RCC_RTCCLKSOURCE_LSE to RCC_RTCCLKSOURCE_LSI

To get main.py to come from a frozen file, I removed all of the files out of the modules directory and added my main.py (or a symlink to your main.py). I also had to modify main.c: around this line:
https://github.com/micropython/micropyt ... ain.c#L718

Code: Select all

diff --git a/ports/stm32/main.c b/ports/stm32/main.c
index 62cba5434..723a6a919 100644
--- a/ports/stm32/main.c
+++ b/ports/stm32/main.c
@@ -715,6 +715,9 @@ soft_reset:
         } else {
             main_py = mp_obj_str_get_str(MP_STATE_PORT(pyb_config_main));
         }
+#if 1
+       pyexec_frozen_module(main_py);
+#else
         mp_import_stat_t stat = mp_import_stat(main_py);
         if (stat == MP_IMPORT_STAT_FILE) {
             int ret = pyexec_file(main_py);
@@ -725,6 +728,7 @@ soft_reset:
                 flash_error(3);
             }
         }
+#endif
     }
 
     // Main script is finished, so now go into REPL mode.
I discovered a bug in st-flash where it gets a verification failure at the 128K mark. I had to do an

Code: Select all

st-flash erase
before doing:

Code: Select all

make BOARD=NUCLEO_L432KC deploy-stlink
in order to get the verification to pass. I'm planning on reporting this on the stlink repository.

I also found a bug in the making of frozen modules that if my main.py was too simple:

Code: Select all

print('Executing main.py')
then the frozen_mpy.c file would fail to compile. If I changed it to make a qstr, like this:

Code: Select all

file = 'main.py'
print('Executing', file)
then it compiled fine.

neoclassic
Posts: 8
Joined: Wed Aug 30, 2017 8:58 am

Re: [STM32L432 - NUCLEO 32]

Post by neoclassic » Wed Dec 12, 2018 11:23 am

Hi Dave, I really appreciate your help, thank you very much. I've tried your solutions to both issues and your proposal to launch a main.py at startup works great thanks, but the other one to spare pins PC14 and PC15 I afraid not, with your changes the REPL keeps working but I have no control over those pins , so I can not set or clear them, what do you think?

Thank you very much again.

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

Re: [STM32L432 - NUCLEO 32]

Post by dhylands » Wed Dec 12, 2018 5:04 pm

How are you testing?

D7 & D8 are connected to PC14/PC15 but they require SB6 and SB8 to be connected. On my board these were both open.

With SB6 and SB8 both closed, I was able to do:

Code: Select all

>>> import pyb
>>> pin = pyb.Pin('C14', pyb.Pin.OUT_PP)
>>> pin.value(0)
>>> pin.value(1)
>>> pin.value(0)
>>> pin = pyb.Pin('C15', pyb.Pin.OUT_PP)
>>> pin.value(0)
>>> pin.value(1)
>>> pin.value(0)
and get a LED on the appropriate pin to toggle.

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

Re: [STM32L432 - NUCLEO 32]

Post by dhylands » Wed Dec 12, 2018 5:10 pm

Something else isn't quite right.

If I flash micropython and connect to the serial right away, then everything is fine. However, if I unplug and replug the USB cable, then the baud rate comes up weird.

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

Re: [STM32L432 - NUCLEO 32]

Post by dhylands » Wed Dec 12, 2018 6:34 pm

If I choose a lower baud rate (i.e. 9600 instead of 115200) then everything is fine. This is because the clock is being derived from MSI (I think). I'm not exactly sure what the flashing process does to get the clocks to work.

To get a more accurate clock, you'd need to connect the MCO (8MHz) from the stlink processor to the STM32L432 thru either pin PA0 or PA14 and make appropriate configuration changes in the clock initialization.

neoclassic
Posts: 8
Joined: Wed Aug 30, 2017 8:58 am

Re: [STM32L432 - NUCLEO 32]

Post by neoclassic » Thu Dec 13, 2018 11:49 am

Hello Dave, I finally have working it!! , I was confused when I read :
"- PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
+ // PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;"

I understood just commenting the line and I miss your comment:
"I changed RCC_RTCCLKSOURCE_LSE to RCC_RTCCLKSOURCE_LSI"

When I changed to LSI everytihng worked fine, thank you very much and sorry for the mistake.

Regarding your issues with the baudrate I have no problems. I flashed the board using ST Visual Prograrmmer and tried with Putty and MobaXterm under windows 10. In my case I´ve compiled the port to run the micro at 80Mhz.

Thanks again.

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

Re: [STM32L432 - NUCLEO 32]

Post by dhylands » Fri Dec 14, 2018 9:52 pm

I posted a bug https://github.com/texane/stlink/issues/750 against stlink and then also posted a PR https://github.com/texane/stlink/pull/751 which fixes the problem.

If you build your own version of st-flash from the latest master, then you'll no longer need to use `st-flash erase` before flashing images larger than 128K onto the STM32L432.

Post Reply