mirror of
https://github.com/aprochazka/ProfilometerProbe.git
synced 2025-06-29 17:17:21 +02:00
Sending pictures - problems with cdc testing using receiver app
This commit is contained in:
2
.gitmodules
vendored
Normal file
2
.gitmodules
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
[submodule "Firmware/tinyusb"]
|
||||
url = https://github.com/hathach/tinyusb
|
@ -34,9 +34,9 @@ extern "C"
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
#define CFG_EXAMPLE_VIDEO_READONLY
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "stdlib.h"
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
#include "stdbool.h"
|
||||
#include "tusb.h"
|
||||
#include "Cam.h"
|
||||
|
@ -21,7 +21,7 @@
|
||||
#include "images.h"
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
#include "tusb.h"
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
@ -47,15 +47,22 @@ DMA_HandleTypeDef hdma_spi1_tx;
|
||||
|
||||
UART_HandleTypeDef huart2;
|
||||
|
||||
|
||||
|
||||
PCD_HandleTypeDef hpcd_USB_FS;
|
||||
|
||||
/* USER CODE BEGIN PV */
|
||||
//DAC_HandleTypeDef hdac1;
|
||||
|
||||
//TIM_HandleTypeDef htim15;
|
||||
|
||||
int SPI_Rx_Done_Flag = 0;
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
void SystemClock_Config(void);
|
||||
static void MX_GPIO_Init(void);
|
||||
|
||||
static void MX_DMA_Init(void);
|
||||
static void MX_USART2_UART_Init(void);
|
||||
static void MX_SPI1_Init(void);
|
||||
@ -63,7 +70,8 @@ static void MX_I2C1_Init(void);
|
||||
static void MX_USB_PCD_Init(void);
|
||||
/* USER CODE BEGIN PFP */
|
||||
|
||||
|
||||
//static void MX_DAC1_Init(void);
|
||||
//static void MX_TIM15_Init(void);
|
||||
/* USER CODE END PFP */
|
||||
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
@ -216,6 +224,7 @@ int send_CDC_Bulk(){
|
||||
int main(void)
|
||||
{
|
||||
/* USER CODE BEGIN 1 */
|
||||
LED_On();
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/* MCU Configuration--------------------------------------------------------*/
|
||||
@ -243,11 +252,11 @@ int main(void)
|
||||
MX_I2C1_Init();
|
||||
MX_USB_PCD_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
//MX_DAC1_Init();
|
||||
//MX_TIM15_Init();
|
||||
HAL_PWREx_EnableVddUSB();
|
||||
HAL_Delay(1);
|
||||
tud_init(BOARD_DEVICE_RHPORT_NUM);
|
||||
|
||||
|
||||
HAL_Delay(10);
|
||||
SPI_Init(&hspi1);
|
||||
@ -264,21 +273,22 @@ int main(void)
|
||||
|
||||
uint16_t image_size = Cam_FIFO_length(&hspi1);
|
||||
|
||||
//uint8_t *image_data = malloc((image_size + (image_size%10)) * sizeof(uint8_t));
|
||||
uint8_t image_data[10000];
|
||||
memset(image_data, 0x00, image_size + (image_size%10));
|
||||
//memset(image_data, 0x00, image_size);
|
||||
|
||||
Cam_Start_Burst_Read(&hspi1);
|
||||
|
||||
HAL_SPI_Receive_DMA(&hspi1, image_data, image_size);
|
||||
//HAL_SPI_Receive(&hspi1, image_data, image_size, HAL_MAX_DELAY);
|
||||
|
||||
while (SPI_Rx_Done_Flag == 0)
|
||||
{
|
||||
// Wait for SPI transfer to finish
|
||||
}
|
||||
LED_On();
|
||||
|
||||
CS_Off();
|
||||
SPI_Rx_Done_Flag = 0;
|
||||
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Infinite loop */
|
||||
@ -288,12 +298,13 @@ int main(void)
|
||||
|
||||
tud_task();
|
||||
|
||||
if(currentSendingIndex >= 590){
|
||||
if(currentSendingIndex >= 9989){
|
||||
//if(false){
|
||||
currentSendingIndex = 0;
|
||||
|
||||
//free(image_data);
|
||||
Cam_Capture(&hspi1);
|
||||
|
||||
|
||||
image_size = Cam_FIFO_length(&hspi1);
|
||||
|
||||
//image_data = malloc((image_size + (image_size%10)) * sizeof(uint8_t));
|
||||
@ -301,12 +312,13 @@ int main(void)
|
||||
|
||||
Cam_Start_Burst_Read(&hspi1);
|
||||
|
||||
HAL_SPI_Receive_DMA(&hspi1, &(image_data[0]), image_size);
|
||||
Debug_LED_On();
|
||||
HAL_SPI_Receive_DMA(&hspi1, image_data, 10000);
|
||||
//Debug_LED_On();
|
||||
|
||||
while (SPI_Rx_Done_Flag == 0)
|
||||
{
|
||||
// Wait for SPI transfer to finish
|
||||
tud_task();
|
||||
}
|
||||
CS_Off();
|
||||
SPI_Rx_Done_Flag = 0;
|
||||
@ -317,7 +329,10 @@ int main(void)
|
||||
}
|
||||
else {
|
||||
LED_On();
|
||||
tud_cdc_write(&sendT[currentSendingIndex], 10);
|
||||
//tud_cdc_write("11111111\r\n", 10);
|
||||
//tud_cdc_write_flush();
|
||||
//tud_cdc_write(&sendT[currentSendingIndex], 10);
|
||||
tud_cdc_write(&image_data[currentSendingIndex], 10);
|
||||
tud_cdc_write_flush();
|
||||
currentSendingIndex = currentSendingIndex + 10;
|
||||
HAL_Delay(5);
|
||||
|
@ -1,3 +1,5 @@
|
||||
SHELL=/bin/bash
|
||||
|
||||
.PHONY: all build build-container cmake format format-linux flash-stlink flash-jlink format-container shell image build-container clean clean-image clean-all
|
||||
############################### Native Makefile ###############################
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
@ -11,12 +11,13 @@ void Receiver::printHex(unsigned char value) {
|
||||
void Receiver::openStream(){
|
||||
while(1){
|
||||
// Open the CDC device file for reading
|
||||
cdcFile = open("/dev/ttyACM1", O_RDWR | O_NOCTTY);
|
||||
if (cdcFile == -1) {
|
||||
cdcFile = open("/dev/ttyACM0", O_RDWR | O_NOCTTY);
|
||||
if(cdcFile == -1){
|
||||
std::cerr << "Failed to open CDC device file" << std::endl;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
continue;
|
||||
}
|
||||
|
||||
std::cout << "successfully opened stream" << cdcFile << std::endl;
|
||||
break;
|
||||
}
|
||||
@ -28,7 +29,7 @@ int Receiver::initSerial(){
|
||||
std::cerr << "Error in tcgetattr" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
tcflush(cdcFile, TCIFLUSH);
|
||||
//tcflush(cdcFile, TCIFLUSH);
|
||||
cfsetospeed(&tty, B115200);
|
||||
cfsetispeed(&tty, B115200);
|
||||
tty.c_cflag |= (CLOCAL | CREAD);
|
||||
@ -49,7 +50,7 @@ int Receiver::initSerial(){
|
||||
}
|
||||
|
||||
std::cout << "OPENED!" << std::endl;
|
||||
tcflush(cdcFile, TCIFLUSH);
|
||||
//tcflush(cdcFile, TCIFLUSH);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -64,15 +65,13 @@ int Receiver::readCdcData(unsigned char (*character)[10]) {
|
||||
std::cerr << "Error in read" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
/*
|
||||
for(int i = 0; i<10; i++)
|
||||
{
|
||||
printHex((*character)[i]);
|
||||
//std::cout << unsigned(character[i]);
|
||||
std::cout << " ";
|
||||
}*/
|
||||
|
||||
|
||||
//std::cout << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
BIN
Receiver/main
BIN
Receiver/main
Binary file not shown.
@ -11,8 +11,11 @@
|
||||
struct termios tty;
|
||||
|
||||
void readLoop(Receiver ** receiverPtr){
|
||||
std::cout << "1" << std::endl;
|
||||
(*receiverPtr)->openStream();
|
||||
std::cout << "2" << std::endl;
|
||||
(*receiverPtr)->initSerial();
|
||||
std::cout << "3" << std::endl;
|
||||
|
||||
while (true) {
|
||||
unsigned char character[10];
|
||||
|
BIN
Receiver/main.o
BIN
Receiver/main.o
Binary file not shown.
Reference in New Issue
Block a user