2024-05-06 02:12 PM
In my graduation project, I'm utilizing the STM32H735_DK microcontroller to communicate with a GMSL (Generalized Memory Scalable Logic) device. Typically, these devices are configured using terminal programs like Putty or TeraTerm. Commands, such as "PICT START," are sent via a USB A to USB B cable from a PC to the GMSL.
Despite my attempts to replicate this communication using UART and USB CDC with the STM32, I've encountered difficulties. Conversely, my friend successfully communicated with a GMSL device using a Raspberry Pi via a serial port.
I'm unsure how to resolve these issues and would appreciate any assistance. Thank you!
2024-05-08 09:10 AM
@sana1 wrote:I have gathered information from the schematic of the GMSL UART connection to an MCU (Micro 100). .
So why don't you just copy that, and use the STM32 in place of the "Micro 100"
Then you have a simple UART connection from the STM32 to the "GMSL" (still no idea what that is).
@sana1 wrote:My question is about configuring the USB on the STM32. .
Your question doesn't seem to be really about the STM32, but a fundamental lack of understanding of how USB works.
Therefore I would strongly suggest that you don't use USB, and just use a simple UART connection instead.
@sana1 wrote:Should I set it up as a USB CDC device or host ... I'm new to working with STM .
This has nothing specifically to do with STM32.
Whatever device you use - whether it's a PC or a Raspberry Pi or an STM32 or any other microcontroller - needs to be a USB Host, and that Host will need to implement the CDC.
@sana1 wrote:I'm new to working with STM and this project marks my first venture into this field. Any guidance would be greatly appreciated.
You should be seeking guidance from your teacher/supervisor/tutor. It sounds like your project may be a bit beyond you - you really should be discussing with your teacher/supervisor/tutor whether it's actually an appropriate project for you...
2024-05-08 09:29 AM
I appreciate your response. My objective is to use the STM32 to send commands instead of relying on a PC connected via USB. From what I understand, I should configure the USB of the STM32 as a host because the GMSL module acts as a USB device, requiring a host for communication to accept commands. The GMSL module is crucial for generating photos or videos for a cluster of
2024-05-08 09:39 AM
@sana1 wrote:the GMSL module acts as a USB device,
But that's not what you showed in your schematics!
Your schematics showed an external USB-to-UART converter.
So why not just do away with that converter, and use a simple UART connection direct to the mystery "GMSL" ?
@sana1 wrote:The GMSL module is crucial for generating photos or videos for a cluster of
Would you care to complete that sentence?
Are you sure that "GMSL" doesn't actually stand for "Gigabit Multimedia Serial Link" ?
🤔
2024-05-08 10:43 AM
Unfortunately, I don't have direct access to the UART because all the components are integrated on the PCB.
2024-05-08 10:44 AM
so i have just access to the usb
2024-05-08 03:11 PM
So why did you even suggest UART in the first place?
Clearly, then, your only choice is to implement a Host for the FT232 chip.
As your classmate already has this working on a Raspberry Pi, why don't you also use a Raspberry Pi ?
Breakout boards for the FT232RL are widely available; eg,
https://thepihut.com/products/ft232-usb-uart-board-usb-c
It would be wise to start with something like that - so you can test your Host independently of the "GMSL".
2024-05-09 04:07 AM
Since communication with the GMSL module is integral to the project, I must utilize the STM32, as using a Raspberry Pi is not an option. I've already developed a project using USB HOST functionality. However, I'm encountering an issue where the Appli_state remains in a state of not being ready.
2024-05-09 04:13 AM
Please use this button to properly post source code:
@sana1 wrote:I must utilize the STM32, as using a Raspberry Pi is not an option.
So how come your classmate is using a Raspberry Pi?
@sana1 wrote:I've already developed a project using USB HOST functionality.
Does that work with a standalone FT232RL - eg, on a breakout board or in a cable?
Or with any other USB CDC device?
@sana1 wrote:the Appli_state remains in a state of not being ready.
So what state is it in?
2024-05-09 07:11 AM
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "usb_host.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "usbh_cdc.h"
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
void MX_USB_HOST_Process(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
extern USBH_HandleTypeDef hUsbHostHS;
extern ApplicationTypeDef Appli_state ;
USBH_StatusTypeDef usbresult;
#define RX_BUFF_SIZE 1024
uint8_t CDC_RX_Buffer[RX_BUFF_SIZE];
uint8_t CDC_TX_Buffer[RX_BUFF_SIZE];
typedef enum{
CDC_STATE_IDLE=0,
CDC_SEND,
CDC_RECEIVE,
}CDC_StateTypedef;
CDC_StateTypedef CDC_STATE=CDC_STATE_IDLE;
uint8_t i=0;
void CDC_HANDLE(void)
{
switch (CDC_STATE)
{
case CDC_STATE_IDLE:
{USBH_CDC_Stop(&hUsbHostHS);
int len = sprintf((char*)CDC_TX_Buffer ,"pict start 03\n");
if(USBH_CDC_Transmit(&hUsbHostHS,CDC_TX_Buffer,len)==USBH_OK)
{ HAL_Delay(1000);
HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_2);
CDC_STATE=CDC_RECEIVE;
}break;
}
case CDC_RECEIVE:
{
USBH_CDC_Stop(&hUsbHostHS);
usbresult =USBH_CDC_Receive(&hUsbHostHS,(uint8_t*)CDC_RX_Buffer,RX_BUFF_SIZE);
HAL_Delay(1000);
CDC_STATE=CDC_IDLE;
}
default:
break;
}
}
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USB_HOST_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
MX_USB_HOST_Process();
/* USER CODE BEGIN 3 */
//userfunction();
if(Appli_state == APPLICATION_READY)
{
CDC_HANDLE();
}
}
/* USER CODE END 3 */
}
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Supply configuration update enable
*/
HAL_PWREx_ConfigSupply(PWR_DIRECT_SMPS_SUPPLY);
/** Configure the main internal regulator output voltage
*/
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE0);
while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48|RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 32;
RCC_OscInitStruct.PLL.PLLN = 129;
RCC_OscInitStruct.PLL.PLLP = 2;
RCC_OscInitStruct.PLL.PLLQ = 4;
RCC_OscInitStruct.PLL.PLLR = 2;
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_2;
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
RCC_OscInitStruct.PLL.PLLFRACN = 0;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
|RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.AHBCLKDivider = 2;
RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV2;
RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2;
RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV2;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3) != HAL_OK)
{
Error_Handler();
}
}
/**
* @brief GPIO Initialization Function
* @PAram None
* @retval None
*/
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOH_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOH, GPIO_PIN_5, GPIO_PIN_RESET);
/*Configure GPIO pin : PC13 */
GPIO_InitStruct.Pin = GPIO_PIN_13;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
/*Configure GPIO pin : PH5 */
GPIO_InitStruct.Pin = GPIO_PIN_5;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);
}
/* USER CODE BEGIN 4 */
/* USER CODE END 4 */
/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
__disable_irq();
while (1)
{
}
/* USER CODE END Error_Handler_Debug */
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @PAram file: pointer to the source file name
* @PAram line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */