2020-03-02 07:26 PM
I am trying to get the demostration firmware to output some logs through UART or USART but was not able to do so.
Both USB cables are connected (micro and mini) and I used Putty to connect to the Mini USB interface (ST link USB port). I also put the board in the USB mode.
From the firmware side, I ensured that I recompiled and reflashed with
USE_LOGGER=1 -- was =2 originally in the example
I was not able to get anything out of the Putty connection, though all other functions are working ok.
Is there something I'm missing from my setup? or any physical jumpers that I need to change.
Attached are some of the logging code from the example firmware.
THanks in advance.
Solved! Go to Solution.
2020-03-03 01:58 AM
Dear ec.1,
The logger is not enabled in the ST25R3916-DISCO demo and some extra work is required to have it working.
Before you follow the instructions to enable it, please note that no usefull message will be displayed by default.
Thus enabling the logger is pointless unless you want to instrument the code with your own messages.
Knowing that, let's enabling the logger.
1. Initialize the UART1
Copy the following function to your main.c
static void UART1_Init(UART_HandleTypeDef *husart)
{
husart->Instance = USART1;
husart->Init.BaudRate = 115200;
husart->Init.WordLength = UART_WORDLENGTH_8B;
husart->Init.StopBits = UART_STOPBITS_1;
husart->Init.Parity = UART_PARITY_NONE;
husart->Init.Mode = UART_MODE_TX_RX;
husart->Init.HwFlowCtl = UART_HWCONTROL_NONE;
husart->Init.OverSampling = UART_OVERSAMPLING_16;
husart->Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
husart->AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
HAL_UART_Init(husart);
}
Declares a handle for UART1 (global variable):
UART_HandleTypeDef log_uart;
Then call the init functions from the main:
UART1_Init(&log_uart);
logUsartInit(&log_uart);
2. Initialize the PIO for UART1
In the stm32l4xx_hal_msp.c, in the HAL_UART_MspInit function, adds the following statements:
if(huart->Instance==USART1)
{
/* USER CODE BEGIN USART2_MspInit 0 */
__HAL_RCC_GPIOB_CLK_ENABLE();
/* USER CODE END USART2_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_USART1_CLK_ENABLE();
/* USART2 GPIO Configuration
PA2 ------> USART2_TX
PA3 ------> USART2_RX
*/
gpio_initstruct.Pin = GPIO_PIN_6;
gpio_initstruct.Mode = GPIO_MODE_AF_PP;
gpio_initstruct.Pull = GPIO_NOPULL;
gpio_initstruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
gpio_initstruct.Alternate = GPIO_AF7_USART1;
HAL_GPIO_Init(GPIOB, &gpio_initstruct);
gpio_initstruct.Pin = GPIO_PIN_7;
gpio_initstruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(GPIOB, &gpio_initstruct);
}
3. Enable logger
Make sure that USE_LOGGER compilation flag is set to 1
4. Terminal baudrate
To get the output, you should open a terminal on the ST-Link Vitual COM port with a baudrate set to 115200.
Please update this thread if anything is still missing on your side.
2020-03-03 01:58 AM
Dear ec.1,
The logger is not enabled in the ST25R3916-DISCO demo and some extra work is required to have it working.
Before you follow the instructions to enable it, please note that no usefull message will be displayed by default.
Thus enabling the logger is pointless unless you want to instrument the code with your own messages.
Knowing that, let's enabling the logger.
1. Initialize the UART1
Copy the following function to your main.c
static void UART1_Init(UART_HandleTypeDef *husart)
{
husart->Instance = USART1;
husart->Init.BaudRate = 115200;
husart->Init.WordLength = UART_WORDLENGTH_8B;
husart->Init.StopBits = UART_STOPBITS_1;
husart->Init.Parity = UART_PARITY_NONE;
husart->Init.Mode = UART_MODE_TX_RX;
husart->Init.HwFlowCtl = UART_HWCONTROL_NONE;
husart->Init.OverSampling = UART_OVERSAMPLING_16;
husart->Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
husart->AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
HAL_UART_Init(husart);
}
Declares a handle for UART1 (global variable):
UART_HandleTypeDef log_uart;
Then call the init functions from the main:
UART1_Init(&log_uart);
logUsartInit(&log_uart);
2. Initialize the PIO for UART1
In the stm32l4xx_hal_msp.c, in the HAL_UART_MspInit function, adds the following statements:
if(huart->Instance==USART1)
{
/* USER CODE BEGIN USART2_MspInit 0 */
__HAL_RCC_GPIOB_CLK_ENABLE();
/* USER CODE END USART2_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_USART1_CLK_ENABLE();
/* USART2 GPIO Configuration
PA2 ------> USART2_TX
PA3 ------> USART2_RX
*/
gpio_initstruct.Pin = GPIO_PIN_6;
gpio_initstruct.Mode = GPIO_MODE_AF_PP;
gpio_initstruct.Pull = GPIO_NOPULL;
gpio_initstruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
gpio_initstruct.Alternate = GPIO_AF7_USART1;
HAL_GPIO_Init(GPIOB, &gpio_initstruct);
gpio_initstruct.Pin = GPIO_PIN_7;
gpio_initstruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(GPIOB, &gpio_initstruct);
}
3. Enable logger
Make sure that USE_LOGGER compilation flag is set to 1
4. Terminal baudrate
To get the output, you should open a terminal on the ST-Link Vitual COM port with a baudrate set to 115200.
Please update this thread if anything is still missing on your side.
2020-03-03 04:45 AM
Hi Ronald,
Thanks for the guide on enabling logger for ST25R3916-DISCO. I was just comparing this to the example firmware for the NFC03 board which had logger enabled by default and was trying to replicate that.
If I understand it correctly there are already logger statements which dumps some status messages ie. ceInitialize in the existing DISCO firmware (as attached previously) so I'm not sure why you suggested that there are no useful messages.
The example firmware (and previously attached screenshot) was downloaded here
https://www.st.com/content/st_com/en/products/embedded-software/st25-nfc-rfid-software/stsw-st25r011.html, so I hope we are talking about the same firmware version/type.
Thanks again for replying.
2020-03-03 05:00 AM
You're correct there are a bunch of log messages in the demo.
But maybe not enough to consistently monitor what the demo is doing (depending on your expectations).
Regards
2020-03-03 05:05 AM
Thanks for the confirmation, I'll try out your suggestions and let you know later how I go.
2020-03-04 03:08 PM
Works ok. However I have to add that in order to allow platformLog() to work we need to have the below in platform.h
#define platformLog(...) logUsart (__VA_ARGS__)
And perhaps add in some \r \n in the logging strings.