Porting to STM32L433

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
Turbinenreiter
Posts: 288
Joined: Sun May 04, 2014 8:54 am

Porting to STM32L433

Post by Turbinenreiter » Sun Oct 14, 2018 10:40 am

This is I think my fourth try to add a port to a new stm32 microcontroller, on the first three tries I gave up after a while.

I'll post the diff and the error I'm currently seeing below, but I think it makes sense to talk method first.

How do you port to a new stm32 target?

What I know:

In "boards", you need:
  • BOARD_NAME/mpconfigboard.h
  • BOARD_NAME/mpconfigboard.mk
  • BOARD_NAME/pins.csv
  • BOARD_NAME/stm32X4xx_hal_conf.h
  • stm32X4xx_af.csv
  • stm32X4xxxx.ld
I copy this from the closest relative I can find.
Then, I start with the linker script, which I seem to be able to figure out well enough using all the other examples.
Next, I mostly ignore the af and pins file - I'm thinking I should get the build passing before I dive into the right names and mapping. Especially af is huge and I'm not looking forward to extract all these mappings from the datasheet, but I never got that far ... .
mpconfigboard.mk again seems quite simple and with the examples of the other ports I think I'm doing this right.
Then, mpconfigboard.h, where I make sure that I have the right pins and mostly disable everything but UART for the first try. For my first build, I just want to get the UART REPL, all the other stuff comes later.
Lastly, stm32X4xx_hal_conf.h, where I think I also only have to disable the HAL features I don't have on the controller, and where I have to get the clock right.

Is there anything fundamentally wrong with that approach?


Onwards to the specific problem:
When building, I get this error (both with #define MICROPY_HW_ENABLE_TIMER (1)
and (0)):

Code: Select all

timer.c:614:17: error: implicit declaration of function '__HAL_RCC_TIM3_CLK_ENABLE'; did you mean '__HAL_RCC_TIM7_CLK_ENABLE'? [-Werror=implicit-function-declaration]
         case 3: __HAL_RCC_TIM3_CLK_ENABLE(); break;
                 ^~~~~~~~~~~~~~~~~~~~~~~~~
                 __HAL_RCC_TIM7_CLK_ENABLE
timer.c: At top level:
timer.c:699:49: error: 'TIM3' undeclared here (not in a function); did you mean 'TIM1'?
I don't know from where I control this behaviour. The hardware has 11 timers.

https://github.com/micropython/micropyt ... tm32l433rc

complete build error

Code: Select all

CC timer.c
timer.c: In function 'pyb_timer_init_helper':
timer.c:614:17: error: implicit declaration of function '__HAL_RCC_TIM3_CLK_ENABLE'; did you mean '__HAL_RCC_TIM7_CLK_ENABLE'? [-Werror=implicit-function-declaration]
         case 3: __HAL_RCC_TIM3_CLK_ENABLE(); break;
                 ^~~~~~~~~~~~~~~~~~~~~~~~~
                 __HAL_RCC_TIM7_CLK_ENABLE
timer.c: At top level:
timer.c:699:49: error: 'TIM3' undeclared here (not in a function); did you mean 'TIM1'?
 #define TIM_ENTRY(id, irq) [id - 1] = (uint32_t)TIM##id | irq
                                                 ^
timer.c:709:5: note: in expansion of macro 'TIM_ENTRY'
     TIM_ENTRY(3, TIM3_IRQn),
     ^~~~~~~~~
timer.c:709:18: error: 'TIM3_IRQn' undeclared here (not in a function); did you mean 'TIM7_IRQn'?
     TIM_ENTRY(3, TIM3_IRQn),
                  ^
timer.c:699:59: note: in definition of macro 'TIM_ENTRY'
 #define TIM_ENTRY(id, irq) [id - 1] = (uint32_t)TIM##id | irq
                                                           ^~~
cc1: all warnings being treated as errors
make: *** [../../py/mkrules.mk:47: build-PL_L433RC/timer.o] Error 1
make: *** Waiting for unfinished jobs....
In file included from ../../py/mpstate.h:35:0,
                 from ../../py/runtime.h:29,
                 from pin.c:31:
build-PL_L433RC/genhdr/pins_af_const.h:6:56: error: 'GPIO_AF14_TIM17' undeclared here (not in a function); did you mean 'GPIO_AF14_TIM15'?
     { MP_ROM_QSTR(MP_QSTR_AF14_TIM17),      MP_ROM_INT(GPIO_AF14_TIM17) },
                                                        ^
../../py/obj.h:87:67: note: in definition of macro 'MP_OBJ_NEW_SMALL_INT'
 #define MP_OBJ_NEW_SMALL_INT(small_int) ((mp_obj_t)((((mp_uint_t)(small_int)) << 1) | 1))
                                                                   ^~~~~~~~~
build-PL_L433RC/genhdr/pins_af_const.h:6:45: note: in expansion of macro 'MP_ROM_INT'
     { MP_ROM_QSTR(MP_QSTR_AF14_TIM17),      MP_ROM_INT(GPIO_AF14_TIM17) },
                                             ^~~~~~~~~~
build-PL_L433RC/genhdr/pins_af_const.h:11:56: error: 'GPIO_AF2_TIM3' undeclared here (not in a function); did you mean 'GPIO_AF2_TIM1'?
     { MP_ROM_QSTR(MP_QSTR_AF2_TIM3),        MP_ROM_INT(GPIO_AF2_TIM3) },
                                                        ^
../../py/obj.h:87:67: note: in definition of macro 'MP_OBJ_NEW_SMALL_INT'
 #define MP_OBJ_NEW_SMALL_INT(small_int) ((mp_obj_t)((((mp_uint_t)(small_int)) << 1) | 1))
                                                                   ^~~~~~~~~
build-PL_L433RC/genhdr/pins_af_const.h:11:45: note: in expansion of macro 'MP_ROM_INT'
     { MP_ROM_QSTR(MP_QSTR_AF2_TIM3),        MP_ROM_INT(GPIO_AF2_TIM3) },
                                             ^~~~~~~~~~
build-PL_L433RC/genhdr/pins_af_const.h:12:56: error: 'GPIO_AF2_TIM4' undeclared here (not in a function); did you mean 'GPIO_AF2_TIM3'?
     { MP_ROM_QSTR(MP_QSTR_AF2_TIM4),        MP_ROM_INT(GPIO_AF2_TIM4) },
                                                        ^
../../py/obj.h:87:67: note: in definition of macro 'MP_OBJ_NEW_SMALL_INT'
 #define MP_OBJ_NEW_SMALL_INT(small_int) ((mp_obj_t)((((mp_uint_t)(small_int)) << 1) | 1))
                                                                   ^~~~~~~~~
build-PL_L433RC/genhdr/pins_af_const.h:12:45: note: in expansion of macro 'MP_ROM_INT'
     { MP_ROM_QSTR(MP_QSTR_AF2_TIM4),        MP_ROM_INT(GPIO_AF2_TIM4) },
                                             ^~~~~~~~~~
build-PL_L433RC/genhdr/pins_af_const.h:13:56: error: 'GPIO_AF2_TIM5' undeclared here (not in a function); did you mean 'GPIO_AF2_TIM4'?
     { MP_ROM_QSTR(MP_QSTR_AF2_TIM5),        MP_ROM_INT(GPIO_AF2_TIM5) },
                                                        ^
../../py/obj.h:87:67: note: in definition of macro 'MP_OBJ_NEW_SMALL_INT'
 #define MP_OBJ_NEW_SMALL_INT(small_int) ((mp_obj_t)((((mp_uint_t)(small_int)) << 1) | 1))
                                                                   ^~~~~~~~~
build-PL_L433RC/genhdr/pins_af_const.h:13:45: note: in expansion of macro 'MP_ROM_INT'
     { MP_ROM_QSTR(MP_QSTR_AF2_TIM5),        MP_ROM_INT(GPIO_AF2_TIM5) },
                                             ^~~~~~~~~~
build-PL_L433RC/genhdr/pins_af_const.h:14:56: error: 'GPIO_AF3_TIM8' undeclared here (not in a function); did you mean 'GPIO_AF2_TIM5'?
     { MP_ROM_QSTR(MP_QSTR_AF3_TIM8),        MP_ROM_INT(GPIO_AF3_TIM8) },
                                                        ^
../../py/obj.h:87:67: note: in definition of macro 'MP_OBJ_NEW_SMALL_INT'
 #define MP_OBJ_NEW_SMALL_INT(small_int) ((mp_obj_t)((((mp_uint_t)(small_int)) << 1) | 1))
                                                                   ^~~~~~~~~
build-PL_L433RC/genhdr/pins_af_const.h:14:45: note: in expansion of macro 'MP_ROM_INT'
     { MP_ROM_QSTR(MP_QSTR_AF3_TIM8),        MP_ROM_INT(GPIO_AF3_TIM8) },
                                             ^~~~~~~~~~
make: *** [../../py/mkrules.mk:47: build-PL_L433RC/pin.o] Error 1

jickster
Posts: 629
Joined: Thu Sep 07, 2017 8:57 pm

Re: Porting to STM32L433

Post by jickster » Mon Oct 15, 2018 10:37 pm

Background: I've never done what you're trying to do.

I searched around the code and I think I found what you may be doing wrong:
Next, I mostly ignore the af and pins file - I'm thinking I should get the build passing before I dive into the right names and mapping.
If you look at

Code: Select all

timer.c:STATIC const uint32_t tim_instance_table[MICROPY_HW_MAX_TIMER]
you'll see there's a lot of

Code: Select all

#if defined(TIM6)
    TIM_ENTRY(6, TIM6_DAC_IRQn),
    #endif
Searching for "TIM6" in the entire code you'll see it popsup in the .csv files;
I think the build uses the .csv file to generate some other .h.

So, you have to take care of the af.csv file to build.
You may not have to define EVERY pin but at least the ones that result in a build error.

mroussel
Posts: 7
Joined: Fri Nov 23, 2018 6:08 pm
Location: Montreal, Quebec, Canada

Re: Porting to STM32L433

Post by mroussel » Sat Nov 24, 2018 5:57 pm

Turbinenreiter

Did you finish this port ?

Post Reply