stmhal -- how is it used in micropython?
stmhal -- how is it used in micropython?
I was searching through the source for timer functions and come across the code st.com contributed
and wonder how it is called.
micropython/stmhal/hal/f4/src/stm32f4xx_hal_tim.c
seems like a giant lookup table.
Where is the contact point with micropython terms like:
t1 = pyb.Timer(1, prescaler=83, period=xfmr_pulse_w, mode=pyb.Timer.UP
t1ch1 = t1.channel(1, pyb.Timer.OC_ACTIVE, polarity= pyb.Timer.HIGH, pin=pyb.Pin.board.JP5)
It must be here in
micropython/stmhal/timer.c
because there I find words like callback and compare and OC_ACTIVE and
oc_config.OCPolarity = TIM_OCPOLARITY_HIGH;
but no one pulse or onepulse anywhere. And no ONE_SHOT constant as mentioned in docs that may be only for the wipy, but are filed under pyboard and stmhal now.
http://docs.micropython.org/en/v1.8.2/p ... t=one_shot
stmhal/timer.c would be where to add one pulse feature, right?
and wonder how it is called.
micropython/stmhal/hal/f4/src/stm32f4xx_hal_tim.c
seems like a giant lookup table.
Where is the contact point with micropython terms like:
t1 = pyb.Timer(1, prescaler=83, period=xfmr_pulse_w, mode=pyb.Timer.UP
t1ch1 = t1.channel(1, pyb.Timer.OC_ACTIVE, polarity= pyb.Timer.HIGH, pin=pyb.Pin.board.JP5)
It must be here in
micropython/stmhal/timer.c
because there I find words like callback and compare and OC_ACTIVE and
oc_config.OCPolarity = TIM_OCPOLARITY_HIGH;
but no one pulse or onepulse anywhere. And no ONE_SHOT constant as mentioned in docs that may be only for the wipy, but are filed under pyboard and stmhal now.
http://docs.micropython.org/en/v1.8.2/p ... t=one_shot
stmhal/timer.c would be where to add one pulse feature, right?
John Griessen blog.kitmatic.com
Re: stmhal -- how is it used in micropython?
These 4 files:
stmhal/hal/f4/inc/stm32f4xx_hal_tim.h
stmhal/hal/f4/inc/stm32f4xx_hal_tim_ex.h
stmhal/hal/f4/src/stm32f4xx_hal_tim.c
stmhal/hal/f4/src/stm32f4xx_hal_tim_ex.c
are the HAL files for the timer. They only callable from C.
stmhal/timer.c contains the python interface and it in turn calls into the HAL files.
The one pulse mode constants are defined here:
https://github.com/micropython/micropyt ... #L545-L551
and I see these functions:
https://github.com/micropython/micropyt ... #L196-L201
https://github.com/micropython/micropyt ... l_tim_ex.c (search for OnePulse)
Currently there is no support for this exposed in the python code.
stmhal/hal/f4/inc/stm32f4xx_hal_tim.h
stmhal/hal/f4/inc/stm32f4xx_hal_tim_ex.h
stmhal/hal/f4/src/stm32f4xx_hal_tim.c
stmhal/hal/f4/src/stm32f4xx_hal_tim_ex.c
are the HAL files for the timer. They only callable from C.
stmhal/timer.c contains the python interface and it in turn calls into the HAL files.
The one pulse mode constants are defined here:
https://github.com/micropython/micropyt ... #L545-L551
and I see these functions:
https://github.com/micropython/micropyt ... #L196-L201
https://github.com/micropython/micropyt ... l_tim_ex.c (search for OnePulse)
Currently there is no support for this exposed in the python code.
Re: stmhal -- how is it used in micropython?
I've been reading in the stmhal/hal/f4/inc/stm32f4xx_hal_tim.h and stmhal/hal/f4/src/stm32f4xx_hal_tim_ex.c
and not figured how to use that yet,
so I'm going to be doing a register write as in your example using stm.mem16 on the OC1M and OC3M control registers.
Any help looking up the part like: stm.mem16[stm.TIM2 + stm.TIM_SMCR]
but for OC1M and OC3M appreciated.
and not figured how to use that yet,
so I'm going to be doing a register write as in your example using stm.mem16 on the OC1M and OC3M control registers.
Any help looking up the part like: stm.mem16[stm.TIM2 + stm.TIM_SMCR]
but for OC1M and OC3M appreciated.
John Griessen blog.kitmatic.com
Re: stmhal -- how is it used in micropython?
You can get more examples by downloading the whole HAL from here: http://www.st.com/content/st_com/en/pro ... ubef4.htmljgriessen wrote:I've been reading in the stmhal/hal/f4/inc/stm32f4xx_hal_tim.h and stmhal/hal/f4/src/stm32f4xx_hal_tim_ex.c
and not figured how to use that yet,
That includes a HAL user manual as well as the HAL source code and a ton of examples.
Note that this is a slightly newer version of the HAL than whats included in MicroPython, but the differences should be minor.
Re: stmhal -- how is it used in micropython?
Thanks for the link to the ST docs on HAL. I asked an ST apps engineer and he hasn't even come back with that yet...
Once I have the register write figured out, maybe in a couple weeks I can add it to micropython as a method.
I don't think the current way Timer.OC_FORCED_ACTIVE is implemented is working, or useful, or in line with the STM32F4xx ref manual.
Since it is in channel config, it does not happen at the useful time. It needs to be in a method instead.
I did a test where Timer.OC_FORCED_ACTIVE was followed by Timer.OC_INACTIVE, and it seemed as if the first one was nullified by the second. In the ref manual, forcing an OC output active is something to do on the fly, or in a ISR, not during setup.
Once I have the register write figured out, maybe in a couple weeks I can add it to micropython as a method.
I don't think the current way Timer.OC_FORCED_ACTIVE is implemented is working, or useful, or in line with the STM32F4xx ref manual.
Since it is in channel config, it does not happen at the useful time. It needs to be in a method instead.
I did a test where Timer.OC_FORCED_ACTIVE was followed by Timer.OC_INACTIVE, and it seemed as if the first one was nullified by the second. In the ref manual, forcing an OC output active is something to do on the fly, or in a ISR, not during setup.
John Griessen blog.kitmatic.com
Re: stmhal -- how is it used in micropython?
Well, it can also be used during setup to get the output into a know, but unchanging state.
The HAL code assumes that you'll set the OCMode in one of the init calls and doesn't really provide any mechanism for changing the mode on the fly. I'm not saying that you can't, just saying I that the HAL doesn't really provide any way of doing it.
Doing the direct register writes would be the most efficient (calling any of the TIM_XXX_Init functions seems like way too much overhead to me).
What we've done so far in the hal code is really just to cover off the "typical" cases. When making API changes we also need to consider how those changes will fit into other architectures (like ESP8266, WiPy, teensy, etc).
The HAL code assumes that you'll set the OCMode in one of the init calls and doesn't really provide any mechanism for changing the mode on the fly. I'm not saying that you can't, just saying I that the HAL doesn't really provide any way of doing it.
Doing the direct register writes would be the most efficient (calling any of the TIM_XXX_Init functions seems like way too much overhead to me).
What we've done so far in the hal code is really just to cover off the "typical" cases. When making API changes we also need to consider how those changes will fit into other architectures (like ESP8266, WiPy, teensy, etc).
Re: stmhal -- how is it used in micropython?
Hmm... i'm just reading the Description of STM32F4xx HAL drivers and see lots of layers of stuff to understand,Doing the direct register writes would be the most efficient (calling any of the TIM_XXX_Init functions seems like way too much overhead to me).
and a note that "LL drivers will not be described in this document." so it's hard to trace all the way to registers and
ref manual functions.
For instance disabling, enabling a timer after setting it up:
No example. How do you use the words TIM handle? Looking them up gets me to confusing stuff like lists jammed together almost unreadable. That suggests they made the docs with some code automation, and the whole cross API thing with some document automation that makes it all less readable/understandable. So, back to learning to register write and reading the STM32F4xx ref manual__HAL_TIM_ENABLE
Enable the TIM peripheral.
Parameters:
__HANDLE__: TIM handle
John Griessen blog.kitmatic.com
Re: stmhal -- how is it used in micropython?
Yeah - that's pretty typical. I think most of the documentation is extracted from the code.
The LL modules only exist for the complicated peripherals (like USB or SD).
All of the peripherals use similar pardigms where there is a handle object for the peripheral and then a bunch of functions that work on it (which is C's version of ADT - Abstract Data Types).
Here's a typical example of using a timer to generate PWM:
https://github.com/micropython/micropyt ... #L140-L149
and just above it you'll see another example of using the HAL to initialize a GPIO pin.
I find that I rely on reading the source a bit more than the docs. So your __HAL_TIM_ENABLE example:
https://github.com/micropython/micropyt ... #L140-L149
takes a handle, which will be a pointer to the TIM_HandleTypeDef object
https://github.com/micropython/micropyt ... #L286-L295
that you passed into the HAL_TIM_XXX_Init function, like this one:
https://github.com/micropython/micropyt ... im.h#L1356
Note that disabling a timer won't change the state of the output, just stop the counter from incrementing/decrementing.
The LL modules only exist for the complicated peripherals (like USB or SD).
All of the peripherals use similar pardigms where there is a handle object for the peripheral and then a bunch of functions that work on it (which is C's version of ADT - Abstract Data Types).
Here's a typical example of using a timer to generate PWM:
https://github.com/micropython/micropyt ... #L140-L149
and just above it you'll see another example of using the HAL to initialize a GPIO pin.
I find that I rely on reading the source a bit more than the docs. So your __HAL_TIM_ENABLE example:
https://github.com/micropython/micropyt ... #L140-L149
takes a handle, which will be a pointer to the TIM_HandleTypeDef object
https://github.com/micropython/micropyt ... #L286-L295
that you passed into the HAL_TIM_XXX_Init function, like this one:
https://github.com/micropython/micropyt ... im.h#L1356
Note that disabling a timer won't change the state of the output, just stop the counter from incrementing/decrementing.
Re: stmhal -- how is it used in micropython?
OK, but I still had difficulty figuring where to look next to find how to use such -- for instanceHere's a typical example of using a timer to generate PWM:
https://github.com/micropython/micropyt ... #L140-L149
and just above it you'll see another example of using the HAL to initialize a GPIO pin.
what does pointer s->pulse_cur do?
I'm lost. maybe it will soak in later.takes a handle, which will be a pointer to the TIM_HandleTypeDef object
HAL_StatusTypeDef HAL_TIM_OC_Init(TIM_HandleTypeDef *htim); What does this line mean?
Meanwhile, after hearing you say HAL has too much overhead for most uses in micropython, so it was only selectively included
makes me focus on bit twiddled register writes now. I've been getting a little
bit figured out about timers.
John Griessen blog.kitmatic.com
Re: stmhal -- how is it used in micropython?
s is declared here are a function argument:jgriessen wrote:OK, but I still had difficulty figuring where to look next to find how to use such -- for instanceHere's a typical example of using a timer to generate PWM:
https://github.com/micropython/micropyt ... #L140-L149
and just above it you'll see another example of using the HAL to initialize a GPIO pin.
what does pointer s->pulse_cur do?
https://github.com/micropython/micropyt ... rvo.c#L120
and it's a pointer to a pyb_servo_ovj_t struct, which is defined here:
https://github.com/micropython/micropyt ... .c#L48-L60
s->pulse_cur returns the pulse_cur member of the pyb_servo_obj_t struct pointed to by s.
That's a function prototype (the extern is optional and not used here). The function is named HAL_TIM_OC_Init, returns an object of type HAL_StatusTypeDef and takes one argument, which is a pointer to a TIM_HandleTypeDef struct.I'm lost. maybe it will soak in later.takes a handle, which will be a pointer to the TIM_HandleTypeDef object
HAL_StatusTypeDef HAL_TIM_OC_Init(TIM_HandleTypeDef *htim); What does this line mean?
I don't know about "most uses", but there are certainly lots of cases where it's definitely overkill (and I think that's certainly the case for what you're trying to do).Meanwhile, after hearing you say HAL has too much overhead for most uses in micropython, so it was only selectively included
makes me focus on bit twiddled register writes now. I've been getting a little
bit figured out about timers.