cancel
Showing results for 
Search instead for 
Did you mean: 

Sensortile UART pins 6 &7

Steven Wu
Associate II
Posted on June 19, 2018 at 23:32

Hello,

I'd like to use the UART pins on the SensorTile to receive data from another microcontroller (STM M0) via UART.  I've noticed all virtual com port examples for this device use the USBD library instead of UART library. 

I am working off of the ALLMEMS1_ST project because I see that 'stm32l4xx_hal_uart.c' is included in the drivers.  I've tracked down the pinouts on Sensortile:

  • Pin 6 - RX_USB_DP; PA12 & PD12 
  • Pin 7 - TX_USB_DM; PA11 & PD12

I wanted to use the expansion cradle first so I connected SB10 and SB21 which should correspond to CN9.1 and CN9.2.  Is this correct?

I added the stm32l4xx_hal_msp.c file to the User folder (by clicking add and finding in the list), and by default, the GPIO UART Pins are:

  • USART2_CMN_DEFAULT_TX_PIN
  • USART2_CMN_DEFAULT_RX_PIN

But I cannot locate these definitions in the IDE to determine if the correct pins are being assigned. This is confusing me and do not know if I am doing this correctly. 

I don't see an error in my project, and my HAL_UART_Transmit() function returns HAL_OK

I've done my best looking through resources online, am I close or off?

Thanks.

2 REPLIES 2
Steven Wu
Associate II
Posted on June 21, 2018 at 21:13

I am trying UART5 (not USART 5 since it does not exist) and here is the

https://st.com/content/ccc/resource/technical/document/user_manual/group0/bc/b1/ad/c8/36/de/40/92/DM00320099/files/DM00320pdf/jcr:content/translations/en.DM00320pdf

.

I generated code using STM CubeMX software to confirm.

Here is my configuration:

static void GPIO_Init(void)
{
 /* GPIO Ports Clock Enable*/
 __HAL_RCC_GPIOD_CLK_ENABLE();
 __HAL_RCC_GPIOC_CLK_ENABLE();
 __UART5_CLK_ENABLE();
 
 GPIO_InitTypeDef GPIO_InitStruct;
 GPIO_InitStruct.Pin = GPIO_PIN_12;
 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
 GPIO_InitStruct.Pull = GPIO_PULLUP;
 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
 GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
 
 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
 /* UART RX GPIO pin configuration */
 GPIO_InitStruct.Pin = GPIO_PIN_2;
 GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
 HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
 
}
static void UART5_Init(void) 
{
 huart5.Instance = UART5;
 huart5.Init.BaudRate= 9600;
 huart5.Init.WordLength = UART_WORDLENGTH_8B;
 huart5.Init.StopBits = UART_STOPBITS_1;
 huart5.Init.Parity = UART_PARITY_NONE;
 huart5.Init.Mode = UART_MODE_TX_RX;
 huart5.Init.HwFlowCtl = UART_HWCONTROL_NONE;
 huart5.Init.OverSampling = UART_OVERSAMPLING_16;
 huart5.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
 huart5.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
 if (HAL_UART_Init(&huart5) != HAL_OK)
 {
 Error_Handler(); 
// printf('Uart not INIT
');
 }
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
int main(void)
{
 HAL_Init();
 SystemClock_Config();
 
 BSP_LED_Init( LED1 ); 
 BSP_LED_On( LED1);
 
 GPIO_Init();
 UART5_Init();
 HAL_Delay(500);
 
 
// printf('%d
', (&huart5)->RxState);
// printf('%d
', 0x20U); //HAL_UART_STATE_READY
 if(HAL_UART_Receive(&huart5, (uint8_t*)aRxBuffer, RXBUFFERSIZE, 0x1FFFFFF) !=HAL_OK ) {
// if(HAL_UART_Receive(&huart5, (uint8_t*)aRxBuffer, RXBUFFERSIZE,1000) !=HAL_OK ) {
// Error_Handler();
 BSP_LED_Off(LED1);
 }
 else{
 printf('data received
');
 for(int i=0; i < RXBUFFERSIZE; i++ ) {
// printf('%c',aRxBuffer[i]);
 }
 BSP_LED_Off(LED1);
 HAL_Delay(400);
 BSP_LED_On(LED1);
 HAL_Delay(400);
 BSP_LED_Off(LED1);
 HAL_Delay(400);
 BSP_LED_On(LED1);
 HAL_Delay(400);
 BSP_LED_Off(LED1);
 HAL_Delay(400);
 BSP_LED_On(LED1);
 HAL_Delay(400);
 }
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

I am going off the STM32Cube_FW_V1.0 UART Polling example, using the Nucleo64 L476 board as my transmitter (using default PA9/PA10 --> CN21/CN33).

SB10 and SB21 are bridged and I read 3.3V on the line. Pins 6 and 7 on the Sensortile read 1.8V.

Is the error because I am powering off USB and there is a conflict? If so, should I disable the USB library in the preprocessor and where do I find this flag? I've browsed ALLMEMS1_config.h

Steven Wu
Associate II
Posted on June 25, 2018 at 21:30

Perhaps I need to bridge all SB10, SB11, SB20, SB21? This is why I think so (from the user guide):

The USB connector on the board can be used to supply power and for communication (USB_OTG_FS). To use the USB peripheral, use the following solder bridge configuration:

 SB10, SB11, SB20 and SB21 OFF (disconnect the signals from U5)

 SB9 ON (supply 3.3 V to the USB peripheral of the STM32 MCU)

*update, i tried SB10, SB11, SB20 and SB21 ON (but did not disconnect SB9). I put a simple transmit & receive loop and connected CN9.1 and CN9.2 and received HAL_TIMEOUT on receive, i.e. transmission was not received.  Is this due to conflicting with USB?

I tried this same test on the Nucleo board, and saw at least the first character received by the board. 

Ultimately, I will want to use the Cradle Board (STLCR01V1) and receive data from the UART.  Reviewing the schematics, I see that Board Pins 6 & 7 are connected to the USB line (RXD-USB_DP and RXD_USB_DM).  

Will the UART lines (UART5 assigned PD12 and PC2) work if I connected wires to pins 6 and 7 appropriately (I will use a level shifter (1.8->3.3V) to interface with the Nucleo or similar board). Or should I place Kapton tape over these pins so that there is no conflict?