Page 1 of 2

[STM32L496] Building firmware for a new board

Posted: Thu Aug 17, 2017 2:40 pm
by Guenther78
Hello forum,

I have a STM32L496 discovery board and I want to build the firmware. First I copied the content of the folder "STM32L476DISC" to a new folder named "STM32L496". Then I made changes to the files (adding pins to pins.csv and adapting pin names in mpconfigboard.h and board_init.c).
First try with make BOARD=STM32L496DISC and an error appears: pin_H4 is undeckared. With a look to build-STM32L496DISC\genhdr\pins.h I saw that the new added pins doesn't appear. I commented them in mpconfigboard.h and the building was successful. But there were only one I2C and only one SPI bus, no SD-Card and no LCD.

I forgot to adapt the makefile!
I changed the names from L476 to L496. And I tried "make" again:
"Please select first the target STM32L4xx device used in your application (in stm32l4xx.h file)"
I saw that in the folder stmhal/boards there were no files with L496...
I will try to create them with and I will keep You informed...

Best regards,

Re: [STM32L496] Building firmware for a new board

Posted: Thu Aug 24, 2017 2:21 pm
by Guenther78
I wasn't very successful till yet...
But I found a few seconds ago this topic: viewtopic.php?f=3&t=258&p=1180&

It is about the file "". To recap the content:

The input files:
  • stmhal/boards/stm32F4xx_af.csv
  • stmhal/boards/stm32f4xx_prefix.c
  • stmhal/boards/BOARDNAME/pins.csv
The output files:
  • build-BOARDNAME/pins_BOARDNAME.c,
  • build-BOARDNAME/genhdr/pins.h
  • build-BOARDNAME/pins_qstr.h
  • build-BOARDNAME/genhdr/pins_af_const.h
My first conclusion: The file "stm32l496_af.csv" won't be build by, I have to build it myself.
But now, back to building the firmware....

Re: [STM32L496] Building firmware for a new board

Posted: Thu Aug 24, 2017 4:35 pm
by dhylands
My first conclusion: The file "stm32l496_af.csv" won't be build by, I have to build it myself.
But now, back to building the firmware....
That is correct. The xxx_af.csv file is an input to

My method of creating these is to copy/paste the data from the datasheet as a PDF opened in Acrobat, I then normally paste into a text editor and use a bunch of search/replace to clean it up and create a csv file.

I took a quick look at the datasheets for the L476 and the L496 and the AF layout looks to be very similar. You can probably just copy the 476 one and look for differences. This will almost certainly be faster than creating one from scratch. When a pin has multiple functions for the same AF, then the convention is to put them in the same cell and separtate by a slash. For example, PA13 has JTMS and SWDIO so this would go into the csv as JTMS/SWDIO. The L496 doesn't seem to have many of those.

Re: [STM32L496] Building firmware for a new board

Posted: Wed Aug 30, 2017 4:06 pm
by Guenther78
I built the file stm32l496_af.csv. Then I tried to make the firmware again. But it failed with this error message:

Code: Select all

adc.c:101:2: error: #error Unsupported processor
Then I added the processor in stmhal/adc.c:

Code: Select all

#elif defined(STM32L476xx) || defined(STM32L496xx)
#define VBAT_DIV (3)
#error Unsupported processor
(What does VBAT_DIV (3) mean? That VBAT is the input channel of the adc?)

Okay, this error is fixed. But some new appeared (in stm32_it.c).
Some unknown types and some implicit declared functions:

Code: Select all

stm32_it.c:90:8: error: unknown type name 'PCD_HandleTypeDef'
 extern PCD_HandleTypeDef pcd_fs_handle;
stm32_it.c:91:8: error: unknown type name 'PCD_HandleTypeDef'
 extern PCD_HandleTypeDef pcd_hs_handle;
stm32_it.c: In function 'OTG_FS_IRQHandler':
stm32_it.c:346:5: error: implicit declaration of function 'HAL_PCD_IRQHandler' [-Werror=implicit-function-declaration]
stm32_it.c: At top level:
stm32_it.c:364:34: error: unknown type name 'PCD_HandleTypeDef'
 STATIC void OTG_CMD_WKUP_Handler(PCD_HandleTypeDef *pcd_handle) {
stm32_it.c: In function 'OTG_FS_WKUP_IRQHandler':
stm32_it.c:408:3: error: implicit declaration of function 'OTG_CMD_WKUP_Handler' [-Werror=implicit-function-declaration]
In file included from hal/l4/inc/stm32l4xx_hal_def.h:49:0,
                 from hal/l4/inc/stm32l4xx_hal_rcc.h:47,
                 from boards/STM32L496DISC/stm32l4xx_hal_conf.h:194,
                 from hal/l4/inc/stm32l4xx_hal.h:48,
                 from stm32_it.c:71:
hal/l4/inc/Legacy/stm32_hal_legacy.h:2847:60: error: implicit declaration of function '__HAL_USB_OTG_FS_WAKEUP_EXTI_CLEAR_FLAG' [-Werror=implicit-function-declaration]
stm32_it.c:411:3: note: in expansion of macro '__HAL_USB_FS_EXTI_CLEAR_FLAG'
cc1.exe: all warnings being treated as errors
make: *** [../py/ build-STM32L496DISC/stm32_it.o] Fehler 1
I have no idea...

Re: [STM32L496] Building firmware for a new board

Posted: Wed Aug 30, 2017 10:10 pm
by dhylands
VBAT_DIV is the value that the VBAT voltage is divided by before being fed to the ADC signal. This varies across the STM32 mcirocontroller line. For the STM32L4x6 (which includes the STM32L496) the correct value is 3. This is from the reference manual.

You can see it mentioned in section 16.3.32 titled "VBAT supply monitoring".

As for the HAL PCD stuff, you probably need to enable the PCD module in your stm32l4xx_hal_conf.h file (from the boards directory). Make sure HAL_PCD_MODULE_ENABLED is uncommented. The PCD module is used for USB related functionality.

Re: [STM32L496] Building firmware for a new board

Posted: Mon Sep 04, 2017 2:38 pm
by Guenther78
HAL_PCD_MODULE_ENABLED is already uncommented.
I tested the building with the STM32L476DISC board and that worked!

In the folder stmhal/hal/l4/inc I found a file named stm32l4xx_hal_pcd.h. There I added

Code: Select all

|| defined(STM32L496xx)
in line 46.
The next error I solved in a similar way, I added the same code in stmhal/hal/l4/inc/stm32l4xx_ll_usb.h.

But the next error is hard:

Code: Select all

 'GPIO_AF10_OTG_FS' undeclared (first use in this function)
I tried to solve it like above, but I haven't found the flie whrere GPIO_A10_OTG_FS is declared.
I think it's a constant and a member of the GPIO_InitStruct should be set to this value.
The GPIO_InitStruct is from type GPIO_InitTypeDef, but I haven't found the declaration of this struct yet.
And why doesn't this error appear at building of the L476 firmware?

Does anyone of You have an idea? I will look again at the micropython source code and keep you informed if a find a solution.

Re: [STM32L496] Building firmware for a new board

Posted: Mon Sep 04, 2017 5:22 pm
by dhylands
I use a tool called ack for searching whole directory trees. You can find it here:

I found GPIO_AF10_USB_FS defined in the lib/stm32lib/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_gpio_ex.h and it looks like it needs a similar treatment to the other changes you've done.

Re: [STM32L496] Building firmware for a new board

Posted: Thu Sep 07, 2017 3:25 pm
by Guenther78
Great, now I have fixed this and similar problems.

But then I got messages like this:

Code: Select all

build-STM32L496DISC/genhdr/pins_af_const.h:22:66: error: 'GPIO_AF3_SPI2' undeclared here (not in a function)
First time that the origin of the error was not in the micropython source code, it was in the created files.
I found out, that the number of the alternate functions differ from the alternate functions of already existing boards.
I added the mapping of number and alternate funciton for the STM32L496 in the file stm32l4xx_hal_gpio_ex.h.

But not enough, a next error occurs:

Code: Select all

build-STM32L496DISC/pins_STM32L496DISC.c:34:13: error: 'GPIOI' undeclared here (not in a function)
     .gpio = GPIO ## p_port, \
build-STM32L496DISC/pins_STM32L496DISC.c:1763:26: note: in expansion of macro 'PIN'
 const pin_obj_t pin_I0 = PIN(I, 0, pin_I0_af, 0, 0);
make: *** [Makefile:373: build-STM32L496DISC/pins_STM32L496DISC.o] Fehler 1
Here I found more infos about GPIOI: ... const-gpio

GPIOI is a periphal base address...

I searched for GPIOI in my directory tree. And the only location for L4xx controller is the file hal/l4/inc/Legacy/stm32_hal_legacy.h.

Code: Select all

There are many locations with GPIOI in cmsis/STM32fxxx but I am not sure if I can copy them.
A new error and no idea how to fix it.

Maybe someone of You have an idea. I will keep You informed if I find a solution.

Re: [STM32L496] Building firmware for a new board

Posted: Thu Sep 07, 2017 6:23 pm
by dhylands
I see GPIOI defined in this file:

which should be included if STM32L496xx is defined. Your boards file should have a line which looks like:

Code: Select all

which is used by the Makefile to add an appropriate -D option when compiling.

If you copied the 476 file and didn't change it, then that would explain why GPIOI isn't defined (the 476 doesn't have an I port).

GPIO_AF3_SPI2 is defined here: ... _ex.h#L474 and is inside a #if ... _ex.h#L435 which assumes that STM32L496xx is defined, so that further suggests that your problem is related to the fact that CMSIS_MCU is set incorrectly.

Re: [STM32L496] Building firmware for a new board

Posted: Sun Apr 29, 2018 2:53 pm
by badi
See PR #3745
Looking forward to test results and feedback.