2024-12-13 03:34 AM - edited 2024-12-16 04:36 AM
Hello,
for the project I am developing I am using a STM32L433.
We have connected a motor encoder signals to PA15 and PB3, that are CH1 and CH2 for timer1 TIM2 configured in encoder mode.
We used CubeMX to configure the HW, and that worked perfectly for another encoder on other pins.
We use a ST link HW interface for FW run/debug, using the SWD interface.
I have a problem with the encoder in timer1 to count while the motor is spinning in some cases.
Compiled both in release mode or debug mode and running it or debugging it the FW shows a random behavior with the timer1 often not counting the encoder signals. Behavior may change after a reset or a power on/off cycle.
I have verified that in all cases the input signal is received correctly by periodically reading one of encoder signal status and driving a LED accordingly. If I manually spin the motor the LED blinks, which means the toggling signals are correctly received by the microprocessor. But the timer1 cannot count them.
As we have no problems with the other encoder on timer2 TIM1, we suspect that the problem lies in the multiplexing of signals PA15 and PB3 with JTAG JTDI and JTDO functionality. I have gone through the manual but beside the table describing the JTAG signals pin allocation, there not a description on how to disable them. CubeMX generated code seems not to address this problem.
I have also looked on the forums and the proposed solution seems to use this macro:
__HAL_AFIO_REMAP_SWJ_NOJTAG();
Unfortunately for this microprocessor I cannot find this macro anywhere.
And there's also no AFIO register to directly bit bang.
So how can I disable the JTAG functionality and have the PA15 and PB3 signals be directed to timer1 TIM2 instead of the JTAG controller?
Thanks in advance
Mauro
Solved! Go to Solution.
2024-12-16 04:34 AM
Ok, sorry for the question.
The problem seemed to be in another part of the code where the Timer, after being correctly configured, was NOT (always) turned on.
What I have learnt with this issue is that with this L4 micro there's nothing more than to configure the AF functionality to disable the JTAG multiplexing.
Thanks again
Mauro
2024-12-13 06:06 PM
Exactly which STM32L433 are you using?
I've looked at the STM32L433CB, STM32L433RB, and STM32L433VC.
PB3 and PA15 don't have TIM1 Channels, only TIM2 Channels exist on those pins.
2024-12-16 12:41 AM
Hello,
the exact model of the micro is STM32L433VCT6
And you are right, those signal are tied to TIM2, not one.I'm going to correct the post. Thanks.
We have another encoder tied to TIM1 and that works without problems.
Mauro
2024-12-16 02:03 AM
Have you looked at the Reference Manual for your stm32?
That has a chapter on General-purpose I/Os (GPIO) that describes the alternate function register e.g. GPIOA->AFRH, bits 28 to 31 of which control which alternate-function controls a PA15 when the PA15 is set to be controlled by an alternate-function.
And then GPIOA->MODER has bits 30 and 31 controlling whether the pin is GPIO digital input, GPIO digital output, tied to alternate-function, or analog input.
The next question is which AF0 to AF15 corresponds to which peripheral (including JTAG), and the table if this is in the data sheet for your stm32, in a couple of tables at the end of the "Pinouts and Pin Description" chapter.
I do wish ST would highlight the Reference Manual more strongly; it is an excellent reference with a huge amount of vital information, but sadly that can make it feel overwhelming at first.
2024-12-16 03:05 AM
Hello,
of course I have looked at the manual, but it does not describe the right procedure to disable the JTAG.
The pins are configured by CubeMX and it sets the right AF mode for the TIM2 encoder.
Here the generated code:
/**TIM2 GPIO Configuration
PA15 (JTDI) ------> TIM2_CH1
PB3 (JTDO-TRACESWO) ------> TIM2_CH2
*/
GPIO_InitStruct.Pin = ENC2_A_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF1_TIM2;
HAL_GPIO_Init(ENC2_A_GPIO_Port, &GPIO_InitStruct);
GPIO_InitStruct.Pin = ENC2_B_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF1_TIM2;
HAL_GPIO_Init(ENC2_B_GPIO_Port, &GPIO_InitStruct);
Where GPIO_AF1_TIM1 is the right value (0x01).
But this configuration which is generated in tim.c file and set in the initial firmware start phase, seems to be randomly forgotten/not applied depending on poweron/reset mico internal conditions.
As said if I turn the system on/off many times, it sometimes works but sometimes it does not. The configuration of the pins should then be correct because they sometimes work but only when the configuration is correctly applied/accepted.
I think there's something missing or a critical timing non respected, but I could not find it described in the manual.
Mauro
2024-12-16 04:34 AM
Ok, sorry for the question.
The problem seemed to be in another part of the code where the Timer, after being correctly configured, was NOT (always) turned on.
What I have learnt with this issue is that with this L4 micro there's nothing more than to configure the AF functionality to disable the JTAG multiplexing.
Thanks again
Mauro
2024-12-16 05:02 AM
Hello @MauroF ,
Instead of modifying the title and add [Solved/Resolved] better to mark the comment that answered your question Accepted as Solution.