USART2
-
- Posts: 89
- Joined: Fri Sep 11, 2015 10:47 pm
- Location: Italy
USART2
Hi,
I wanted to know if it possible use the USART (in particular USART2 - from stm32f405_af.csv AF7 PA2 as TX and PA4 as CLOCK) for interfacing with a Smart Card with the pyboard 1.0 and if yes, can you please direct me?
STM32CubeF4 includes the necessary libraries but are not included in hal folder how can I use them?
Is there any measure to be taken to include them and use them properly?
Thanks Francesco
I wanted to know if it possible use the USART (in particular USART2 - from stm32f405_af.csv AF7 PA2 as TX and PA4 as CLOCK) for interfacing with a Smart Card with the pyboard 1.0 and if yes, can you please direct me?
STM32CubeF4 includes the necessary libraries but are not included in hal folder how can I use them?
Is there any measure to be taken to include them and use them properly?
Thanks Francesco
Re: USART2
Damien made a decision to only include the HAL files which were actually being used in order to keep the size of the HAL reasonable (there are currently 3 different HALs - one for F2, F4, and F7)
So you'd need to goto the STMHAL and grab the files you need, copy them in, and then make appropriate changes to use them.
You probably want to bring this up as an issue on github to discuss the best way to make use of the new functions (i.e. what arguments should be added to the uart class etc).
It may also be possible to use the stm module to directly manipulate the registers to get the functionality you need. It depends on how complicated that would turn out to be.
So you'd need to goto the STMHAL and grab the files you need, copy them in, and then make appropriate changes to use them.
You probably want to bring this up as an issue on github to discuss the best way to make use of the new functions (i.e. what arguments should be added to the uart class etc).
It may also be possible to use the stm module to directly manipulate the registers to get the functionality you need. It depends on how complicated that would turn out to be.
-
- Posts: 89
- Joined: Fri Sep 11, 2015 10:47 pm
- Location: Italy
Re: USART2
Hi Dave,
Thanks for the reply.
I tried to add the hal libraries stm32f4xx_hal_usart. c/h stm32f4xx_hal_smartcard. c/h into f4 enabled in stm32f4xx_hal_conf. h file pybv10 and added a simple example of a smartcard. c/h and all are built correctly.
I initialize the gpio and USART2 needed, but I don't have any signal from the USART2 clock.
Paste the init function:
Any suggestions?
I skipped some steps to enable USART2?
Thanks Francesco
Thanks for the reply.
I tried to add the hal libraries stm32f4xx_hal_usart. c/h stm32f4xx_hal_smartcard. c/h into f4 enabled in stm32f4xx_hal_conf. h file pybv10 and added a simple example of a smartcard. c/h and all are built correctly.
I initialize the gpio and USART2 needed, but I don't have any signal from the USART2 clock.
Paste the init function:
Code: Select all
/* USART2 init function */
void MX_USART2_SMARTCARD_Init(SMARTCARD_HandleTypeDef smartcard) {
/* GPIO Ports Clock Enable */
mp_hal_gpio_clock_enable(GPIOA);
/* Configure Smartcard TX pin */
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.Pin = GPIO_PIN_2;
GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
GPIO_InitStructure.Pull = GPIO_PULLUP;
GPIO_InitStructure.Alternate = GPIO_AF7_USART2;
HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
__USART2_CLK_ENABLE();
smartcard.Instance = USART2;
smartcard.Init.BaudRate = 10753;
smartcard.Init.WordLength = SMARTCARD_WORDLENGTH_9B;
smartcard.Init.StopBits = SMARTCARD_STOPBITS_1_5;
smartcard.Init.Parity = SMARTCARD_PARITY_EVEN;
smartcard.Init.Mode = SMARTCARD_MODE_TX_RX;
smartcard.Init.CLKPolarity = SMARTCARD_POLARITY_LOW;
smartcard.Init.CLKPhase = SMARTCARD_PHASE_1EDGE;
smartcard.Init.CLKLastBit = SMARTCARD_LASTBIT_DISABLE;
smartcard.Init.Prescaler = 6;
smartcard.Init.GuardTime = 12;
smartcard.Init.NACKState = SMARTCARD_NACK_ENABLED;
HAL_SMARTCARD_Init(&smartcard);
HAL_NVIC_DisableIRQ(USART2_IRQn);
__SMARTCARD_DISABLE_IT(&smartcard, SMARTCARD_IT_RXNE);
}
I skipped some steps to enable USART2?
Thanks Francesco
Re: USART2
Your code seems to have initialized the Tx pin, but I don't see any code to initialize the clock pin.
By default, when the processor RESETs, all pins are configured as GPIO inputs.
By default, when the processor RESETs, all pins are configured as GPIO inputs.
-
- Posts: 89
- Joined: Fri Sep 11, 2015 10:47 pm
- Location: Italy
Re: USART2
Thanks Dave,
added this:
and now i have usart2 clock signal.
Thanks
added this:
Code: Select all
/* Configure USART Clock pin as alternate function push-pull */
GPIO_InitStruct.Pin = GPIO_PIN_4;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
Thanks
-
- Posts: 89
- Joined: Fri Sep 11, 2015 10:47 pm
- Location: Italy
Re: USART2
Hi Dave,
how i can set USART2 clock to work at 4Mhz?
Thanks Francesco
how i can set USART2 clock to work at 4Mhz?
Thanks Francesco
-
- Posts: 89
- Joined: Fri Sep 11, 2015 10:47 pm
- Location: Italy
Re: USART2
Hi Dave,
i must set 4MHz via prescaler of HAL_SmartCard:
USART2 is on 84MHz for set to 4MHz is correct set prescaler to 21?
Thanks Francesco
i must set 4MHz via prescaler of HAL_SmartCard:
Code: Select all
smartcard.Instance = USART2;
smartcard.Init.BaudRate = 10753;
smartcard.Init.WordLength = SMARTCARD_WORDLENGTH_9B;
smartcard.Init.StopBits = SMARTCARD_STOPBITS_1_5;
smartcard.Init.Parity = SMARTCARD_PARITY_EVEN;
smartcard.Init.Mode = SMARTCARD_MODE_TX_RX;
smartcard.Init.CLKPolarity = SMARTCARD_POLARITY_LOW;
smartcard.Init.CLKPhase = SMARTCARD_PHASE_1EDGE;
smartcard.Init.CLKLastBit = SMARTCARD_LASTBIT_DISABLE;
smartcard.Init.Prescaler = 21;
smartcard.Init.GuardTime = 12;
smartcard.Init.NACKState = SMARTCARD_NACK_ENABLED;
Thanks Francesco
Re: USART2
As I read chapter 7 of ref manual, USART2 is on APB1 which runs at 42MHz. you could verify your 4MHz with scope or analyzer.pagano.paganino wrote: USART2 is on 84MHz for set to 4MHz is correct set prescaler to 21?
Re: USART2
The datasheet also mentions (in the section that USART register section for USART_GPTR register) that for smartcard mode that the value given in the register is multiplied by 2 to come up with the divider.
Given that USART2 is on APB1, which runs at 42 MHz, this means that the closest you can get is to use a prescalar value of 5 which will result in 4.2 MHz.
If you drop the CPU frequency down from 168MHz to 160MHz, then APB1 will be clocked at 40 MHz, and a prescalar value of 5 will give you your desired 4 MHz frequency.
Given that USART2 is on APB1, which runs at 42 MHz, this means that the closest you can get is to use a prescalar value of 5 which will result in 4.2 MHz.
If you drop the CPU frequency down from 168MHz to 160MHz, then APB1 will be clocked at 40 MHz, and a prescalar value of 5 will give you your desired 4 MHz frequency.