parent
254056a8d7
commit
7d48eedf12
File diff suppressed because one or more lines are too long
@ -0,0 +1,158 @@ |
|||||||
|
#ifndef __PH_H |
||||||
|
#define __PH_H |
||||||
|
|
||||||
|
#ifdef __cplusplus |
||||||
|
extern "C" { |
||||||
|
#endif |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include "FreeRTOS.h" |
||||||
|
#include "task.h" |
||||||
|
#include "main.h" |
||||||
|
#include "cmsis_os.h" |
||||||
|
#include "usart.h" |
||||||
|
|
||||||
|
|
||||||
|
#include "elog.h" |
||||||
|
|
||||||
|
#ifdef __cplusplus |
||||||
|
extern "C" { |
||||||
|
#endif |
||||||
|
|
||||||
|
#include <string.h> |
||||||
|
#include "uart_helper.h" |
||||||
|
#include "uart_interface.h" |
||||||
|
// #include "config.h"
|
||||||
|
|
||||||
|
#define PH_Rcv_Buf_Size 9 |
||||||
|
#define PH_Command_Number 1 |
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{ |
||||||
|
PH_Status_Waiting , |
||||||
|
PH_Status_Ready , |
||||||
|
PH_Status_Sending , |
||||||
|
PH_Status_Send_Cplt , |
||||||
|
PH_Status_RCV_OK , |
||||||
|
PH_Status_DATA_OK , |
||||||
|
PH_Status_Timeout , |
||||||
|
PH_Status_Error , |
||||||
|
} PH_Status_TypeDef; |
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{ |
||||||
|
UartHelper_TypeDef *uarthelper; |
||||||
|
// UART_HandleTypeDef *huart;
|
||||||
|
uint8_t interface_type; /* 0: common, 1: 485 ,2:3160*/ |
||||||
|
uint8_t *send_buf; |
||||||
|
uint16_t size_send; |
||||||
|
uint8_t *rcv_buf; |
||||||
|
uint16_t size_rcv; |
||||||
|
|
||||||
|
|
||||||
|
uint8_t mode_232_485; /* 0: common, 1: 485 */ |
||||||
|
uint8_t trans_type; /* 0 :polling, 1: IT 2: DMA*/ |
||||||
|
uint8_t rcv_type; /* 0 :polling, 1: IT 2: DMA*/ |
||||||
|
uint8_t idle_enable_disable; /* 0 不开启空闲中断 , 1 开启空闲中断 */ |
||||||
|
uint8_t trans_mode; /* 0 :polling, 1: IT 2: DMA*/ |
||||||
|
|
||||||
|
uint64_t timebase; |
||||||
|
uint16_t timeout_ms; |
||||||
|
volatile uint8_t send_flag; /* 发送标志位 */ |
||||||
|
Uart_Status_TypeDef send_status; /* 发送状态 1:正在发送 busy,0:发送ok,*/ |
||||||
|
Uart_Status_TypeDef status; /* 发送状态 1:正在发送 busy,0:发送ok,*/ |
||||||
|
|
||||||
|
uint8_t command_seq ; /* 命令序号 */ |
||||||
|
uint8_t mode; /* 0 : normal , 1 : get wavelength , 2 : get sn */ |
||||||
|
|
||||||
|
uint8_t vipersn_buf[15]; |
||||||
|
uint8_t PH_Wavelength_Buf[2][ PH_Rcv_Buf_Size ]; |
||||||
|
uint8_t PH_Data_Buf[2][ PH_Rcv_Buf_Size ]; |
||||||
|
|
||||||
|
uint8_t rcv_ok; /* 接收数据完整可以处理 */ |
||||||
|
uint8_t data_begin_flag; /* 接收数据完整可以处理 */ |
||||||
|
uint8_t data_ok; /* 接收数据完整可以处理 */ |
||||||
|
|
||||||
|
volatile PH_Status_TypeDef state; |
||||||
|
|
||||||
|
// int (*Init)(void); //初始化触摸屏控制器
|
||||||
|
// // uint8_t (*Setup)( ); //扫描触摸屏.0,屏幕扫描;1,物理坐标;
|
||||||
|
// uint8_t (*Port)( ); //扫描触摸屏.0,屏幕扫描;1,物理坐标;
|
||||||
|
|
||||||
|
|
||||||
|
}PH_TypeDef; |
||||||
|
|
||||||
|
extern PH_TypeDef *ph ; |
||||||
|
|
||||||
|
int PH_Init( ); |
||||||
|
int PH_Test( ); |
||||||
|
void PH_Start( ); |
||||||
|
void PH_Stop( ); |
||||||
|
|
||||||
|
void PH_Set_Uarthelper( PH_TypeDef *ph, UartHelper_TypeDef * uarthelper ); |
||||||
|
void PH_Set_Interface( PH_TypeDef *ph, UartInterface_TypeDef * interface ); |
||||||
|
void PH_Set_Huart( PH_TypeDef *ph, UART_HandleTypeDef * huart ); |
||||||
|
void PH_Set_Interface_Type( PH_TypeDef *ph, Uart_Interface_Type_Typedef interface_type ); |
||||||
|
void PH_Set_Trans_Type( PH_TypeDef *ph, Uart_Transmode_TypeDef trans_type ); |
||||||
|
void PH_Set_Rcv_Type( PH_TypeDef *ph, Uart_Transmode_TypeDef rcv_type ); |
||||||
|
void PH_Set_Idle_Enable( PH_TypeDef *ph, Uart_IDLE_Enable_TypeDef idle_enable_disable ); |
||||||
|
void PH_Set_TransMode( PH_TypeDef *ph, Uart_Transmode_TypeDef trans_mode ); |
||||||
|
void PH_Set_RsMode_232_485( PH_TypeDef *ph, Uart_RS_Mode_TypeDef rs_232_485 ); |
||||||
|
void PH_Set_Timeout( PH_TypeDef *ph, uint16_t timeout_ms ); |
||||||
|
void PH_Set_Sendbuf( PH_TypeDef *ph, uint8_t * buf, uint16_t size ); |
||||||
|
void PH_Set_Rcvbuf( PH_TypeDef *ph, uint8_t * buf, uint16_t size ); |
||||||
|
|
||||||
|
int PH_Send( PH_TypeDef *ph, uint8_t * buf, uint16_t size); |
||||||
|
|
||||||
|
|
||||||
|
void PH_Begin_Rcv(PH_TypeDef *ph, uint8_t * buf, uint16_t size); |
||||||
|
|
||||||
|
extern void PH_Rcv_Cplt_Callback( PH_TypeDef *ph ); |
||||||
|
extern void PH_Send_Cplt_Callback( PH_TypeDef *ph ); |
||||||
|
|
||||||
|
int PH_Get_Data_OK(PH_TypeDef *ph ); |
||||||
|
void PH_Set_Send_Flag( PH_TypeDef *ph ); |
||||||
|
|
||||||
|
// extern void PH_Setup( );
|
||||||
|
extern void PH_Port( ); |
||||||
|
// extern void PH_SN( );
|
||||||
|
// extern void PH_Wavelength( );
|
||||||
|
void PH_Task( ); |
||||||
|
|
||||||
|
/* 再封装演示 */
|
||||||
|
typedef struct
|
||||||
|
{ |
||||||
|
uint8_t (*init)( );
|
||||||
|
uint8_t (*port)(void);
|
||||||
|
int (*test)(void); |
||||||
|
void (*start)(void); |
||||||
|
int (*stop)(void); |
||||||
|
//扫描触摸屏.0,屏幕扫描;1,物理坐标;
|
||||||
|
GPIO_TypeDef *sel_gpio;
|
||||||
|
GPIO_TypeDef *dplx_gpio;
|
||||||
|
GPIO_TypeDef *de_gpio;
|
||||||
|
uint16_t sel_pin; |
||||||
|
uint16_t dplx_pin; |
||||||
|
uint16_t de_pin; |
||||||
|
|
||||||
|
Uart_Interface_Type_Typedef interface_type; /* 0: common, 1: 485 ,2:3160*/ |
||||||
|
Uart_RS_Mode_TypeDef mode_232_485; /* 0 commome 1:485*/ |
||||||
|
Uart_Transmode_TypeDef trans_type; /* 0 :polling, 1: IT 2: DMA*/ |
||||||
|
Uart_Transmode_TypeDef rcv_type; /* 0 :polling, 1: IT 2: DMA*/ |
||||||
|
Uart_IDLE_Enable_TypeDef idle_enable_disable; /* 0 :不启用空闲 , 1: 启用空闲*/ |
||||||
|
|
||||||
|
uint16_t ph_val; |
||||||
|
uint16_t temp_val; |
||||||
|
PH_TypeDef *ph; /*不是常量 不能直接初始化*/ |
||||||
|
|
||||||
|
|
||||||
|
}My_PH_TypeDef; |
||||||
|
extern My_PH_TypeDef my_pH ; |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus |
||||||
|
} |
||||||
|
#endif |
||||||
|
#endif |
||||||
@ -1,107 +1,492 @@ |
|||||||
//i2c_ads1115.c
|
// i2c_ads1115.c
|
||||||
#include "i2c_ads1115.h" |
#include "i2c_ads1115.h" |
||||||
#include <stdlib.h> |
#include "stdlib.h" |
||||||
#include "i2c.h" |
#include "stdio.h" |
||||||
#include "main.h" |
|
||||||
#include "elog.h" |
#include "elog.h" |
||||||
|
|
||||||
/*
|
/*
|
||||||
* ads1115_get_voltage_val( hi2c1, 0x00, CONFIG_REG_H, CONFIG_REG_L ) |
多路测量的话, 需要配置不同的 config_H config_L |
||||||
*/ |
*/ |
||||||
|
|
||||||
extern I2C_HandleTypeDef hi2c1; |
static I2C_HandleTypeDef *pADS1115_I2C = &hi2c1; |
||||||
#define ADS1115_hi2c hi2c1 |
|
||||||
int ads1115_test(I2C_HandleTypeDef ads1115_I2cHandle) |
osThreadId_t ads1115TaskHandle; |
||||||
|
const osThreadAttr_t ads1115Task_attributes = { |
||||||
|
.name = "ads1115Task", |
||||||
|
.stack_size = 256 * 4, |
||||||
|
.priority = (osPriority_t) osPriorityNormal, |
||||||
|
}; |
||||||
|
|
||||||
|
osEventFlagsId_t ads1115EventHandle; |
||||||
|
const osEventFlagsAttr_t ads1115Event_attributes = { |
||||||
|
.name = "ads1115Event", |
||||||
|
}; |
||||||
|
|
||||||
|
// ads1115EventHandle = osEventFlagsNew (&ads1115Event_attributes);
|
||||||
|
// typedef enum
|
||||||
|
// {
|
||||||
|
// EV_READY, /*!< Startup finished. */
|
||||||
|
// EV_FRAME_RECEIVED, /*!< Frame received. */
|
||||||
|
// EV_EXECUTE, /*!< Execute function. */
|
||||||
|
// EV_FRAME_SENT /*!< Frame sent. */
|
||||||
|
// } eMBEventType;
|
||||||
|
// osEventFlagsSet(modbusEventHandle,eEvent);
|
||||||
|
// osEventFlagsClear (osEventFlagsId_t ef_id, uint32_t flags)
|
||||||
|
// recvedEvent = osEventFlagsWait (modbusEventHandle,
|
||||||
|
// EV_READY | EV_FRAME_RECEIVED | EV_EXECUTE |
|
||||||
|
// EV_FRAME_SENT, /* 接收任务感兴趣的事件 */
|
||||||
|
// 0,
|
||||||
|
// portMAX_DELAY); /* 指定超时事件,无限等待 */
|
||||||
|
|
||||||
|
ADS1115_TypeDef my_ads1115 = |
||||||
|
{ |
||||||
|
ads1115_init, |
||||||
|
ads1115_port, |
||||||
|
ads1115_test, |
||||||
|
ads1115_start, |
||||||
|
ads1115_stop, |
||||||
|
NULL, |
||||||
|
ADS1115_REG_CONFIG_OS_START, |
||||||
|
ADS1115_REG_CONFIG_MUX_SINGLE_0, |
||||||
|
ADS1115_REG_CONFIG_PGA_4, |
||||||
|
ADS1115_REG_CONFIG_MODE_SINGLE, |
||||||
|
ADS1115_REG_CONFIG_DR_128, |
||||||
|
ADS1115_REG_CONFIG_COMP_MODE_TRADITIONAL, |
||||||
|
ADS1115_REG_CONFIG_COMP_POL_LOW, |
||||||
|
ADS1115_REG_CONFIG_COMP_LAT_NONLATCH, |
||||||
|
ADS1115_REG_CONFIG_COMP_QUE_DIS, |
||||||
|
0, // point addr
|
||||||
|
0, // config_H
|
||||||
|
0, // config_L
|
||||||
|
{ 0, 0, 0 }, // reg_data[3]
|
||||||
|
ADS1115_OUTPUT_UNIT_mv, // 默认输出毫伏
|
||||||
|
0, // event_flags
|
||||||
|
0, // state
|
||||||
|
{0,0}, // result
|
||||||
|
}; |
||||||
|
|
||||||
|
void ads1115_task(void) |
||||||
{ |
{ |
||||||
ads1115_config_register(ads1115_I2cHandle, 0x00, CONFIG_REG_H, CONFIG_REG_L); |
uint8_t event_flags; |
||||||
return 0; |
uint8_t reg_data[3] ={0};
|
||||||
|
for (;;) |
||||||
|
{ |
||||||
|
switch ( my_ads1115.state ) |
||||||
|
{ |
||||||
|
case ADS1115_WORK_STATE_WAITING: |
||||||
|
osDelay(20); |
||||||
|
break; |
||||||
|
|
||||||
|
// Init
|
||||||
|
case ADS1115_WORK_STATE_INIT: |
||||||
|
// log_i("ads1115 init .... %d ", osEventFlagsGet( ads1115EventHandle));
|
||||||
|
|
||||||
|
if ( osEventFlagsGet( ads1115EventHandle) == 0 ) |
||||||
|
{ |
||||||
|
osEventFlagsSet( ads1115EventHandle, ADS1115_Event_INIT ); |
||||||
|
|
||||||
|
my_ads1115.reg_data[0] = 0x01; // point addr 8bit 配置寄存器
|
||||||
|
my_ads1115.reg_data[1] = my_ads1115.config_H; // config_reg 高位
|
||||||
|
my_ads1115.time_ticks = osKernelGetTickCount( ); |
||||||
|
if ( HAL_I2C_Master_Transmit_IT( pADS1115_I2C, ADS1115_WRITE_ADDRESS, my_ads1115.reg_data, 3 ) != HAL_OK) |
||||||
|
{ |
||||||
|
// log_e( "ads1115 set register failure while reading!!!" );
|
||||||
|
my_ads1115.state == ADS1115_WORK_STATE_ERROR ; |
||||||
|
}
|
||||||
|
} |
||||||
|
if ( (osKernelGetTickCount() - my_ads1115.time_ticks) > 5 *1000) |
||||||
|
{ |
||||||
|
my_ads1115.state == ADS1115_WORK_STATE_TIMEOUT ; |
||||||
|
} |
||||||
|
break;
|
||||||
|
case ADS1115_WORK_STATE_INIT_SUCCESS: |
||||||
|
// log_i("ads1115 init success ... " );
|
||||||
|
osEventFlagsClear( ads1115EventHandle, ADS1115_Event_INIT ); |
||||||
|
osEventFlagsSet( ads1115EventHandle, ADS1115_Event_READY ); |
||||||
|
break;
|
||||||
|
|
||||||
|
// SET REGISTER
|
||||||
|
case ADS1115_WORK_STATE_SET_REGISTER: |
||||||
|
// log_i("ads1115 set register .... %d ", osEventFlagsGet( ads1115EventHandle));
|
||||||
|
|
||||||
|
if ( osEventFlagsGet( ads1115EventHandle) == 0 ) |
||||||
|
{ |
||||||
|
osEventFlagsSet( ads1115EventHandle, ADS1115_Event_SET_REGISTER ); |
||||||
|
|
||||||
|
my_ads1115.reg_data[0] = 0x01; // point addr 8bit 配置寄存器
|
||||||
|
my_ads1115.reg_data[1] = my_ads1115.config_H; // config_reg 高位
|
||||||
|
my_ads1115.time_ticks = osKernelGetTickCount( ); |
||||||
|
if ( HAL_I2C_Master_Transmit_IT( pADS1115_I2C, ADS1115_WRITE_ADDRESS, my_ads1115.reg_data, 3 ) != HAL_OK) |
||||||
|
{ |
||||||
|
// log_e("ads1115 set register failure while reading!!!");
|
||||||
|
my_ads1115.state = ADS1115_WORK_STATE_ERROR ; |
||||||
|
} |
||||||
|
} |
||||||
|
if ( (osKernelGetTickCount() - my_ads1115.time_ticks) > 5 *1000) |
||||||
|
{ |
||||||
|
my_ads1115.state = ADS1115_WORK_STATE_TIMEOUT ; |
||||||
|
} |
||||||
|
break;
|
||||||
|
case ADS1115_WORK_STATE_SET_REGISTER_SUCCESS: |
||||||
|
// log_e("ads1115 set register.....succ");
|
||||||
|
osEventFlagsClear( ads1115EventHandle, ADS1115_Event_SET_REGISTER ); |
||||||
|
osEventFlagsSet( ads1115EventHandle, ADS1115_Event_READY ); |
||||||
|
my_ads1115.state = ADS1115_WORK_STATE_SET_POINT_ADDR ; |
||||||
|
break;
|
||||||
|
|
||||||
|
// SET POINT ADDR
|
||||||
|
case ADS1115_WORK_STATE_SET_POINT_ADDR: |
||||||
|
// log_i("ads1115 set point addr .... %d ", osEventFlagsGet( ads1115EventHandle));
|
||||||
|
if ( osEventFlagsGet( ads1115EventHandle) == 0 ) |
||||||
|
{ |
||||||
|
osEventFlagsSet( ads1115EventHandle, ADS1115_Event_SET_POINT_ADDR ); |
||||||
|
my_ads1115.time_ticks = osKernelGetTickCount( ); |
||||||
|
if ( HAL_I2C_Master_Transmit_IT(pADS1115_I2C, ADS1115_WRITE_ADDRESS, 0x00, 1 ) != HAL_OK ) |
||||||
|
{ |
||||||
|
// log_e("ads1115 set register failure while reading!!!");
|
||||||
|
my_ads1115.state = ADS1115_WORK_STATE_ERROR ; |
||||||
|
} |
||||||
|
} |
||||||
|
if ( (osKernelGetTickCount() - my_ads1115.time_ticks) > 5 *1000 ) |
||||||
|
{ |
||||||
|
my_ads1115.state = ADS1115_WORK_STATE_TIMEOUT ; |
||||||
|
} |
||||||
|
break;
|
||||||
|
case ADS1115_WORK_STATE_SET_POINT_ADDR_SUCCESS: |
||||||
|
// log_e("ads1115 set point addr.....succ");
|
||||||
|
osEventFlagsClear( ads1115EventHandle, ADS1115_Event_SET_POINT_ADDR ); |
||||||
|
osEventFlagsSet( ads1115EventHandle, ADS1115_Event_READY ); |
||||||
|
my_ads1115.state = ADS1115_WORK_STATE_RCV_DATA ; |
||||||
|
break;
|
||||||
|
|
||||||
|
// RCV DATA
|
||||||
|
case ADS1115_WORK_STATE_RCV_DATA: |
||||||
|
// log_i("ads1115 rcv data .... %d ", osEventFlagsGet( ads1115EventHandle));
|
||||||
|
if ( osEventFlagsGet( ads1115EventHandle) == 0 ) |
||||||
|
{ |
||||||
|
// log_e("ads1115 set rcv data *** .....");
|
||||||
|
my_ads1115.time_ticks = osKernelGetTickCount( ); |
||||||
|
osEventFlagsSet( ads1115EventHandle, ADS1115_Event_RCV_DATA ); |
||||||
|
if ( HAL_I2C_Master_Receive_IT( pADS1115_I2C, ADS1115_READ_ADDRESS, my_ads1115.result , 2 ) != HAL_OK ) |
||||||
|
{ |
||||||
|
// log_e("ads1115 set register failure while reading!!!");
|
||||||
|
my_ads1115.state = ADS1115_WORK_STATE_ERROR ; |
||||||
|
} |
||||||
|
} |
||||||
|
if ( (osKernelGetTickCount() - my_ads1115.time_ticks) > 5 *1000 ) |
||||||
|
{ |
||||||
|
my_ads1115.state = ADS1115_WORK_STATE_TIMEOUT ; |
||||||
|
} |
||||||
|
break;
|
||||||
|
case ADS1115_WORK_STATE_RCV_DATA_SUCCESS: |
||||||
|
// log_w("ads1115 rcv data .....succ result : %d ", my_ads1115.result );
|
||||||
|
osEventFlagsClear( ads1115EventHandle, ADS1115_Event_RCV_DATA ); |
||||||
|
osEventFlagsSet( ads1115EventHandle, ADS1115_Event_READY ); |
||||||
|
my_ads1115.state = ADS1115_WORK_STATE_DATA_OK ; |
||||||
|
|
||||||
|
// log_i( "ad val : %d ", 256*my_ads1115.result[0] +my_ads1115.result[1] );
|
||||||
|
break;
|
||||||
|
case ADS1115_WORK_STATE_DATA_OK: |
||||||
|
osDelay(20); |
||||||
|
break;
|
||||||
|
case ADS1115_WORK_STATE_ERROR: |
||||||
|
log_e("ads1115 error!!!"); |
||||||
|
break;
|
||||||
|
case ADS1115_WORK_STATE_TIMEOUT: |
||||||
|
log_e("ads1115 timeout!!!"); |
||||||
|
break; |
||||||
|
case ADS1115_WORK_STATE_STOP: |
||||||
|
break;
|
||||||
|
default: |
||||||
|
break; |
||||||
|
} |
||||||
|
osDelay( 20 ); |
||||||
|
|
||||||
|
}
|
||||||
|
} |
||||||
|
|
||||||
|
void ads1115_port(void) |
||||||
|
{ |
||||||
|
ads1115TaskHandle = osThreadNew(ads1115_task, NULL, &ads1115Task_attributes); |
||||||
|
ads1115EventHandle = osEventFlagsNew ( &ads1115Event_attributes ); |
||||||
} |
} |
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief |
* @brief |
||||||
* @param [in] ads1115_I2cHandle |
* @param [in] ads1115_I2cHandle |
||||||
* @param [in] pointADD -- 0x01 写配置寄存器 |
* @param [in] pointADD -- 读的寄存器地址 |
||||||
* @param [in] configH |
* @param [in] configH |
||||||
* @param [in] configL |
* @param [in] configL |
||||||
* |
* |
||||||
* @details |
* @details |
||||||
*/ |
*/ |
||||||
void ads1115_config_register(I2C_HandleTypeDef ads1115_I2cHandle,uint8_t pointADD,uint8_t configH,uint8_t configL) |
int ads1115_init() |
||||||
{ |
{ |
||||||
uint8_t reg_data[3]={pointADD,configH,configL}; |
uint8_t reg_data[3];
|
||||||
while(HAL_I2C_Master_Transmit(&ads1115_I2cHandle, ADS1115_WRITE_ADDRESS, reg_data, 3, 2000) != HAL_OK) |
my_ads1115.hi2c= pADS1115_I2C; |
||||||
{ |
my_ads1115.config_H = my_ads1115.config_os|my_ads1115.config_mux |
||||||
if(HAL_I2C_GetError(&ads1115_I2cHandle) != HAL_I2C_ERROR_AF) |
|my_ads1115.config_PGA|my_ads1115.config_MODE; |
||||||
{ |
my_ads1115.config_L = my_ads1115.config_DR|my_ads1115.config_COMP_MODE|my_ads1115.config_COMP_POL |
||||||
log_i("ads1115 Config Register error!!!\r\n"); |
|my_ads1115.config_COMP_LAT|my_ads1115.config_COMP_QUE ; |
||||||
} |
my_ads1115.reg_data[0] = 0x01; // point addr 8bit 配置寄存器 0x01
|
||||||
} |
my_ads1115.reg_data[1] = my_ads1115.config_H; // config_reg 高位
|
||||||
|
my_ads1115.reg_data[2] = my_ads1115.config_L; // config_reg 低位
|
||||||
|
|
||||||
|
ads1115_set_state( ADS1115_WORK_STATE_INIT ); |
||||||
|
// osEventFlagsSet ( ads1115EventHandle, ADS1115_Event_INIT );
|
||||||
|
// if (HAL_I2C_Master_Transmit_IT(pADS1115_I2C, ADS1115_WRITE_ADDRESS, my_ads1115.reg_data, 3 ) != HAL_OK)
|
||||||
|
// {
|
||||||
|
// return -1;
|
||||||
|
// }
|
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
int ads1115_test() |
||||||
|
{ |
||||||
|
|
||||||
|
return 0; |
||||||
} |
} |
||||||
|
|
||||||
int16_t ads1115_read_data(I2C_HandleTypeDef ads1115_I2cHandle) |
void ads1115_start( ) // set register开始测量
|
||||||
|
{ |
||||||
|
osEventFlagsSet( ads1115EventHandle, ADS1115_Event_READY ); |
||||||
|
ads1115_set_state( ADS1115_WORK_STATE_SET_REGISTER ); |
||||||
|
} |
||||||
|
void ads1115_stop( ) // 结束测量 等待
|
||||||
|
{ |
||||||
|
ads1115_set_state( ADS1115_WORK_STATE_WAITING ); |
||||||
|
} |
||||||
|
|
||||||
|
int ads1115_setup(ADS1115_REG_CONFIG_MUX_Diff_TypeDef mux) |
||||||
|
{ |
||||||
|
my_ads1115.config_mux &= mux; |
||||||
|
my_ads1115.config_H =my_ads1115.config_os|my_ads1115.config_mux |
||||||
|
|my_ads1115.config_PGA|my_ads1115.config_MODE; |
||||||
|
my_ads1115.reg_data[1] = my_ads1115.config_H; |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
void ads1115_set_event_flags(ADS1115_Event_TypeDef evt) |
||||||
|
{ |
||||||
|
osEventFlagsSet ( ads1115EventHandle, evt ); |
||||||
|
} |
||||||
|
|
||||||
|
void ads1115_set_state(ADS1115_WORK_STATE_TypeDef state) |
||||||
|
{ |
||||||
|
my_ads1115.state = state; |
||||||
|
} |
||||||
|
|
||||||
|
int16_t ads1115_read_data( ) |
||||||
{ |
{ |
||||||
int16_t data; |
int16_t data; |
||||||
uint8_t rx_data[2]={0}; |
uint8_t rx_data[2] = {0}; |
||||||
|
|
||||||
while(HAL_I2C_Master_Transmit(&ads1115_I2cHandle, ADS1115_WRITE_ADDRESS, 0x00, 1, 2000) != HAL_OK) |
// TODO 阻塞式, 改为 DMA 中断模式
|
||||||
|
// 读寄存器 0x00 十六位
|
||||||
|
while (HAL_I2C_Master_Transmit(pADS1115_I2C, ADS1115_WRITE_ADDRESS, 0x00, 1, 2000) != HAL_OK) |
||||||
|
// while ( HAL_I2C_Master_Transmit_IT(pADS1115_I2C, ADS1115_WRITE_ADDRESS, 0x00, 1 ) != HAL_OK )
|
||||||
{ |
{ |
||||||
if(HAL_I2C_GetError(&ads1115_I2cHandle) != HAL_I2C_ERROR_AF) |
if (HAL_I2C_GetError(pADS1115_I2C) != HAL_I2C_ERROR_AF) |
||||||
{ |
{ |
||||||
log_i("ads1115 convert Register error!!!\r\n"); |
printf("ads1115 convert Register error!!!\r\n"); |
||||||
} |
} |
||||||
} |
} |
||||||
|
// 读两位
|
||||||
while(HAL_I2C_Master_Receive(&ads1115_I2cHandle, ADS1115_READ_ADDRESS, rx_data, 2, 2000) != HAL_OK) |
// while (HAL_I2C_Master_Receive(pADS1115_I2C, ADS1115_READ_ADDRESS, rx_data, 2, 2000) != HAL_OK)
|
||||||
|
while ( HAL_I2C_Master_Receive_IT(pADS1115_I2C, ADS1115_READ_ADDRESS, rx_data, 2 ) != HAL_OK ) |
||||||
{ |
{ |
||||||
if(HAL_I2C_GetError(&ads1115_I2cHandle) != HAL_I2C_ERROR_AF) |
if ( HAL_I2C_GetError(pADS1115_I2C) != HAL_I2C_ERROR_AF ) |
||||||
{ |
{ |
||||||
log_i("ads1115 read data error!!!\r\n"); |
printf("ads1115 read data error!!!\r\n"); |
||||||
} |
} |
||||||
} |
} |
||||||
|
data = rx_data[0] * 256 + rx_data[1]; |
||||||
data = rx_data[0]*256 + rx_data[1]; |
|
||||||
return data; |
return data; |
||||||
} |
} |
||||||
|
|
||||||
double ads1115_get_voltage_val( I2C_HandleTypeDef ads1115_I2cHandle, uint8_t pointADD, uint8_t configH, uint8_t configL) |
double ads1115_get_voltage_val( ) |
||||||
{ |
{ |
||||||
double val; |
double val; |
||||||
int16_t ad_val; |
int16_t ad_val; |
||||||
double coeff_mv = 1000.0; /* 输出 毫伏*/ |
// TODO 去掉延时,使用寄存器的指示, setup 和读取数据分开执行
|
||||||
double coeff_v = 1000000.0; /* 输出 伏*/ |
// ads1115_setup( pADS1115_I2C, pointADD, configH, configL );
|
||||||
|
// ads1115_setup( ADS1115_REG_CONFIG_MUX_SINGLE_0 );
|
||||||
|
|
||||||
|
HAL_Delay(10); |
||||||
|
// ad_val = ads1115_read_data( pADS1115_I2C );
|
||||||
|
ad_val = my_ads1115.result[0] * 256 + my_ads1115.result[1]; |
||||||
|
if ( (ad_val == 0x7FFF) | (ad_val == 0X8000)) // 是否超量程了
|
||||||
|
{ |
||||||
|
ad_val = 0; |
||||||
|
// printf("over PGA\r\n");
|
||||||
|
} |
||||||
|
switch ((0x0E & my_ads1115.config_H) >> 1) // 量程对应的分辨率
|
||||||
|
{ |
||||||
|
case (0x00): |
||||||
|
val = (double)ad_val * 187.5 / 1000.0; //
|
||||||
|
break; |
||||||
|
case (0x01): |
||||||
|
val = (double)ad_val * 125 / 1000.0; |
||||||
|
break; |
||||||
|
case (0x02): |
||||||
|
val = (double)ad_val * 62.5 / 1000.0; |
||||||
|
break; |
||||||
|
case (0x03): |
||||||
|
val = (double)ad_val * 31.25 / 1000.0; |
||||||
|
break; |
||||||
|
case (0x04): |
||||||
|
val = (double)ad_val * 15.625 / 1000.0; |
||||||
|
break; |
||||||
|
case (0x05): |
||||||
|
val = (double)ad_val * 7.8125 / 1000.0; |
||||||
|
break; |
||||||
|
} |
||||||
|
return (my_ads1115.unit == ADS1115_OUTPUT_UNIT_mv)?val:(val/1000.0); |
||||||
|
} |
||||||
|
|
||||||
ads1115_config_register( ads1115_I2cHandle, pointADD, configH, configL ); |
uint16_t ADS1115_Get_Coeff_BY_128( ) |
||||||
// HAL_Delay(10);
|
{ |
||||||
osDelay(10); |
uint16_t val; |
||||||
|
|
||||||
ad_val=ads1115_read_data( ads1115_I2cHandle ); |
switch ((0x0E & my_ads1115.config_H) >> 1) // 量程对应的分辨率
|
||||||
if( (ad_val==0x7FFF)|(ad_val==0X8000) )//是否超量程了
|
|
||||||
{ |
{ |
||||||
ad_val=0; |
case (0x00): |
||||||
log_i("over PGA\r\n"); |
val = (int)( 187.5 * 128.0); //
|
||||||
|
break; |
||||||
|
case (0x01): |
||||||
|
val = (int)( 125.5 * 128.0);
|
||||||
|
break; |
||||||
|
case (0x02): |
||||||
|
val = (int)( 62.5 * 128.0);
|
||||||
|
break; |
||||||
|
case (0x03): |
||||||
|
val = (int)( 31.25 * 128.0);
|
||||||
|
break; |
||||||
|
case (0x04): |
||||||
|
val = (int)( 15.625 * 128.0);
|
||||||
|
break; |
||||||
|
case (0x05): |
||||||
|
val = (int)( 7.8125 * 128.0);
|
||||||
|
break; |
||||||
} |
} |
||||||
|
|
||||||
switch( ( 0x0E&configH )>>1 )//量程对应的分辨率
|
return val; |
||||||
|
} |
||||||
|
|
||||||
|
double ADS1115_Get_Voltage_From_U16( uint16_t voltage) |
||||||
|
{ |
||||||
|
double val; |
||||||
|
if ( ( voltage == 0x7FFF) | (voltage == 0X8000)) // 是否超量程了
|
||||||
|
{ |
||||||
|
voltage = 0; |
||||||
|
// printf("over PGA\r\n");
|
||||||
|
} |
||||||
|
switch ((0x0E & my_ads1115.config_H) >> 1) // 量程对应的分辨率
|
||||||
{ |
{ |
||||||
case(0x00): |
case (0x00): |
||||||
val=(double)ad_val*187.5/coeff_mv;//
|
val = (double)voltage * 187.5 / 1000.0; //
|
||||||
break; |
break; |
||||||
case(0x01): |
case (0x01): |
||||||
val=(double)ad_val*125/coeff_mv; |
val = (double)voltage * 125 / 1000.0; |
||||||
break; |
break; |
||||||
case(0x02): |
case (0x02): |
||||||
val=(double)ad_val*62.5/coeff_mv; |
val = (double)voltage * 62.5 / 1000.0; |
||||||
break; |
break; |
||||||
case(0x03): |
case (0x03): |
||||||
val=(double)ad_val*31.25/coeff_mv; |
val = (double)voltage * 31.25 / 1000.0; |
||||||
break; |
break; |
||||||
case(0x04): |
case (0x04): |
||||||
val=(double)ad_val*15.625/coeff_mv; |
val = (double)voltage * 15.625 / 1000.0; |
||||||
break; |
break; |
||||||
case(0x05): |
case (0x05): |
||||||
val=(double)ad_val*7.8125/coeff_mv; |
val = (double)voltage * 7.8125 / 1000.0; |
||||||
break; |
break; |
||||||
} |
} |
||||||
|
|
||||||
return val; |
return val; |
||||||
|
} |
||||||
|
|
||||||
|
//主机模式发送回调函数
|
||||||
|
void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *I2cHandle) |
||||||
|
{ |
||||||
|
if (I2cHandle == pADS1115_I2C) |
||||||
|
{ |
||||||
|
log_i("ads1115 send cplt..."); |
||||||
|
if ( my_ads1115.state == ADS1115_WORK_STATE_INIT )
|
||||||
|
{ |
||||||
|
my_ads1115.state = ADS1115_WORK_STATE_INIT_SUCCESS; |
||||||
|
// osEventFlagsSet( ads1115EventHandle, ADS1115_Event_INIT_SUCCESS );
|
||||||
|
// osEventFlagsClear( ads1115EventHandle, ADS1115_Event_INIT );
|
||||||
|
} |
||||||
|
if ( my_ads1115.state == ADS1115_WORK_STATE_SET_REGISTER )
|
||||||
|
{ |
||||||
|
my_ads1115.state = ADS1115_WORK_STATE_SET_REGISTER_SUCCESS; |
||||||
|
// osEventFlagsSet( ads1115EventHandle, ADS1115_Event_SET_REGISTER_SUCCESS );
|
||||||
|
} |
||||||
|
if ( my_ads1115.state == ADS1115_WORK_STATE_SET_POINT_ADDR )
|
||||||
|
{ |
||||||
|
my_ads1115.state = ADS1115_WORK_STATE_SET_POINT_ADDR_SUCCESS; |
||||||
|
// osEventFlagsSet( ads1115EventHandle, ADS1115_Event_TRANS_SUCCESS );
|
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
//主机模式接收回调函数
|
||||||
|
void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *I2cHandle) |
||||||
|
{ |
||||||
|
if (I2cHandle == pADS1115_I2C) |
||||||
|
{ |
||||||
|
log_i("ads1115 rcv cplt..."); |
||||||
|
if ( my_ads1115.state == ADS1115_WORK_STATE_RCV_DATA )
|
||||||
|
{ |
||||||
|
my_ads1115.state = ADS1115_WORK_STATE_RCV_DATA_SUCCESS; |
||||||
|
// osEventFlagsSet( ads1115EventHandle, ADS1115_Event_RCV_DATA_SUCCESS );
|
||||||
|
} |
||||||
|
} |
||||||
} |
} |
||||||
|
|
||||||
|
|
||||||
|
// int ads1115_test()
|
||||||
|
// {
|
||||||
|
|
||||||
|
// log_i( "ads1115_test -> " );
|
||||||
|
// uint32_t flag;
|
||||||
|
|
||||||
|
// flag = osEventFlagsWait ( ads1115EventHandle,
|
||||||
|
// ADS1115_Event_READY|ADS1115_Event_INIT|ADS1115_Event_SET_REGISTER|ADS1115_Event_SET_POINT_ADDR|ADS1115_Event_RCV_DATA,
|
||||||
|
// 0,
|
||||||
|
// 10);
|
||||||
|
// log_i( "flag -> %d ", flag );
|
||||||
|
|
||||||
|
|
||||||
|
// log_i( " -> %d ", osEventFlagsGet( ads1115EventHandle) );
|
||||||
|
// osEventFlagsSet( ads1115EventHandle, ADS1115_Event_READY ) ;
|
||||||
|
// log_i( " ready -> %d ", osEventFlagsGet( ads1115EventHandle) );
|
||||||
|
// osEventFlagsSet( ads1115EventHandle, ADS1115_Event_INIT ) ;
|
||||||
|
// log_i( " init -> %d ", osEventFlagsGet( ads1115EventHandle) );
|
||||||
|
|
||||||
|
// osEventFlagsSet( ads1115EventHandle, ADS1115_Event_RCV_DATA ) ;
|
||||||
|
// log_i( " set register -> %d ", osEventFlagsGet( ads1115EventHandle) );
|
||||||
|
|
||||||
|
// osEventFlagsSet( ads1115EventHandle, ADS1115_Event_SET_REGISTER ) ;
|
||||||
|
// osEventFlagsSet( ads1115EventHandle, ADS1115_Event_SET_POINT_ADDR ) ;
|
||||||
|
// log_i( " set register -> %d ", osEventFlagsGet( ads1115EventHandle) );
|
||||||
|
|
||||||
|
|
||||||
|
// osEventFlagsClear( ads1115EventHandle, ADS1115_Event_SET_POINT_ADDR ) ;
|
||||||
|
// log_i( " clear -> %d ", osEventFlagsGet( ads1115EventHandle) );
|
||||||
|
// flag = osEventFlagsWait ( ads1115EventHandle,
|
||||||
|
// ADS1115_Event_READY|ADS1115_Event_INIT|ADS1115_Event_SET_REGISTER|ADS1115_Event_SET_POINT_ADDR|ADS1115_Event_RCV_DATA,
|
||||||
|
// 0,
|
||||||
|
// 10);
|
||||||
|
// log_i( "flag 2 -> %d ", flag );
|
||||||
|
|
||||||
|
// if (flag&ADS1115_Event_SET_POINT_ADDR == 0)
|
||||||
|
// {
|
||||||
|
// log_i("get ...... ");
|
||||||
|
// }else{
|
||||||
|
// log_i(" not get ... ");
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
|||||||
@ -0,0 +1,412 @@ |
|||||||
|
#include "pH.h" |
||||||
|
#include "elog.h" |
||||||
|
#include "FreeRTOS.h" |
||||||
|
#include "cmsis_os.h" |
||||||
|
#include "stm32f4xx.h" |
||||||
|
#include "usart.h" |
||||||
|
#include "main.h" |
||||||
|
|
||||||
|
|
||||||
|
/****** Port ***************/ |
||||||
|
#if 1 |
||||||
|
|
||||||
|
#define PH_Uart_IRQHandler USART3_IRQHandler |
||||||
|
// #define PH_Uart_IRQHandler USART4_IRQHandler
|
||||||
|
UART_HandleTypeDef *pPHUart = &huart3; |
||||||
|
PH_TypeDef *ph ; |
||||||
|
|
||||||
|
My_PH_TypeDef my_pH = |
||||||
|
{ |
||||||
|
PH_Init, |
||||||
|
PH_Port, |
||||||
|
PH_Test, |
||||||
|
PH_Start, |
||||||
|
PH_Stop, |
||||||
|
SEL_232_485_GPIO_Port, |
||||||
|
HDPLX_GPIO_Port,
|
||||||
|
DE485_GPIO_Port, |
||||||
|
SEL_232_485_Pin, |
||||||
|
HDPLX_Pin, |
||||||
|
DE485_Pin, |
||||||
|
Uart_Interface_Max3160, /* 接口类型 0: common, 1: 485 ,2:3160*/ |
||||||
|
Uart_RSMODE_485, /* mode_232_485 0 commome 1:485*/ |
||||||
|
Uart_Trans_DMA, /* trans_type0 :polling, 1: IT 2: DMA*/ |
||||||
|
Uart_Trans_DMA, /* rcv_type 0 :polling, 1: IT 2: DMA*/ |
||||||
|
Uart_IDLE_IT_ENABLE, /* idle_enable_disable 0 :不启用空闲 , 1: 启用空闲*/ |
||||||
|
0, //ph
|
||||||
|
0, // temprature
|
||||||
|
NULL, /* pointer huart*/ |
||||||
|
}; |
||||||
|
|
||||||
|
extern volatile uint8_t measure_flag ; |
||||||
|
|
||||||
|
uint8_t PH_SND_Buf[8] = { 0x01, 0x03, 0x00, 0x00, 0x00, 0x02, 0xC4, 0x0B }; |
||||||
|
uint8_t PH_RCV_Buf[PH_Rcv_Buf_Size*2] = { 0 }; |
||||||
|
|
||||||
|
osThreadId_t phHandle; |
||||||
|
const osThreadAttr_t PH_attributes = { |
||||||
|
.name = "ph", |
||||||
|
.stack_size = 1024, |
||||||
|
.priority = (osPriority_t) osPriorityBelowNormal, |
||||||
|
}; |
||||||
|
|
||||||
|
void PH_Uart_IRQHandler(void) |
||||||
|
{ |
||||||
|
if (__HAL_UART_GET_FLAG( ph->uarthelper->huart, UART_FLAG_TC) != RESET) |
||||||
|
{ |
||||||
|
// log_i("ph....huart3 TC callback ...");
|
||||||
|
PH_Send_Cplt_Callback( ph ); |
||||||
|
// ph->state = PH_Status_Send_Cplt;
|
||||||
|
ph->uarthelper->huart->gState = HAL_UART_STATE_READY;
|
||||||
|
__HAL_UART_CLEAR_FLAG( ph->uarthelper->huart, UART_FLAG_TC ); |
||||||
|
} |
||||||
|
|
||||||
|
if (__HAL_UART_GET_FLAG( ph->uarthelper->huart, UART_FLAG_IDLE ) != RESET) |
||||||
|
{ |
||||||
|
uint16_t count = __HAL_DMA_GET_COUNTER( ph->uarthelper->huart->hdmarx ); |
||||||
|
log_i("....huart3 IDLE.... %d site3 == 4 %02X ", count, PH_RCV_Buf[2] ); |
||||||
|
uint16_t data_length = 2*PH_Rcv_Buf_Size - count;
|
||||||
|
if (count == PH_Rcv_Buf_Size)
|
||||||
|
{
|
||||||
|
// HAL_UART_DMAStop( ph->uarthelper->huart );
|
||||||
|
ph->state = PH_Status_RCV_OK; |
||||||
|
} |
||||||
|
if (count < PH_Rcv_Buf_Size)
|
||||||
|
{
|
||||||
|
// HAL_UART_DMAStop( ph->uarthelper->huart );
|
||||||
|
ph->state = PH_Status_Error; |
||||||
|
} |
||||||
|
__HAL_UART_CLEAR_IDLEFLAG( ph->uarthelper->huart ); |
||||||
|
} |
||||||
|
HAL_UART_IRQHandler( ph->uarthelper->huart ); |
||||||
|
} |
||||||
|
|
||||||
|
int PH_Init( ) |
||||||
|
{ |
||||||
|
ph = (PH_TypeDef *)malloc(sizeof(PH_TypeDef)); |
||||||
|
|
||||||
|
UartInterface_TypeDef *interface = UartInterface_Init( ); |
||||||
|
UartHelper_TypeDef *uarthelper = UartHelper_Init(); |
||||||
|
|
||||||
|
PH_Set_Uarthelper( ph, uarthelper ); |
||||||
|
PH_Set_Interface( ph, interface ); |
||||||
|
PH_Set_Huart( ph, pPHUart ); |
||||||
|
|
||||||
|
/* set_GPIO UartInterface */ |
||||||
|
UartInterface_Set_Sel_GPIO_Pin( ph->uarthelper->interface, my_pH.sel_gpio, my_pH.sel_pin ); |
||||||
|
UartInterface_Set_Dplx_GPIO_Pin( ph->uarthelper->interface, my_pH.dplx_gpio, my_pH.dplx_pin ); |
||||||
|
UartInterface_Set_DE485_GPIO_Pin( ph->uarthelper->interface, my_pH.de_gpio, my_pH.de_pin ); |
||||||
|
|
||||||
|
/* interface type */ |
||||||
|
PH_Set_Interface_Type( ph, my_pH.interface_type ); |
||||||
|
PH_Set_RsMode_232_485 ( ph, my_pH.mode_232_485 ); // max3160 的232 485选择
|
||||||
|
PH_Set_Trans_Type( ph, my_pH.trans_type ) ; |
||||||
|
PH_Set_Rcv_Type ( ph, my_pH.rcv_type ) ; |
||||||
|
PH_Set_Idle_Enable (ph, my_pH.idle_enable_disable ) ; |
||||||
|
// UartHelper_Setup_Interface_type( ph ,my_pH.interface_type);
|
||||||
|
|
||||||
|
// check
|
||||||
|
if ( ph->uarthelper->huart == pPHUart ){ |
||||||
|
log_i ( "ph set huart ok. trans_type -> %d rcv_type -> %d ( 0 :polling, 1: IT 2: DMA) ",ph->trans_type ,ph->rcv_type ) ; |
||||||
|
log_i( " interface-> %d %d (0:default, 1:485, 2:3160) " ,ph->uarthelper->interface_type ,ph->uarthelper->interface->interface_type );
|
||||||
|
log_i( "ph 232_485 -> %d %d (0:232 ,1: 485) " ,ph->uarthelper->mode_232_485, ph->uarthelper->interface->mode_232_485 );
|
||||||
|
}else{ |
||||||
|
log_e ( "ph set huart failure " ) ; |
||||||
|
} |
||||||
|
|
||||||
|
PH_Set_Timeout( ph, 500 ); |
||||||
|
PH_Set_Sendbuf( ph, PH_SND_Buf, 8 ); |
||||||
|
PH_Set_Rcvbuf( ph, PH_RCV_Buf, sizeof(PH_RCV_Buf) ); |
||||||
|
|
||||||
|
// set paras;
|
||||||
|
ph->timebase = 0; |
||||||
|
// ph->timeout_ms = 1000;
|
||||||
|
ph->send_status = Uart_Status_Ready; |
||||||
|
ph->send_flag = 0; |
||||||
|
ph->command_seq = 4; |
||||||
|
ph->mode = 2; |
||||||
|
ph->data_begin_flag = 0; |
||||||
|
ph->state = PH_Status_Waiting; |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
void PH_Port( ) |
||||||
|
{ |
||||||
|
phHandle = osThreadNew( PH_Task, NULL, &PH_attributes ); |
||||||
|
} |
||||||
|
|
||||||
|
void PH_Task( ) |
||||||
|
{ |
||||||
|
// log_i( " ph tran mode : %d ", ph->->trans_mode );
|
||||||
|
memset( PH_RCV_Buf, 0, 2*PH_Rcv_Buf_Size ); /* ph*3 ph *2 否则内存泄漏 */ |
||||||
|
uint64_t time_ticks; |
||||||
|
// log_i( " ph tran mode : %d %d " , ph->trans_mode , ph->mode );
|
||||||
|
|
||||||
|
for ( ; ; ) |
||||||
|
{
|
||||||
|
switch (ph->state) |
||||||
|
{ |
||||||
|
case PH_Status_Waiting: |
||||||
|
osDelay(20); |
||||||
|
break; |
||||||
|
case PH_Status_Ready: |
||||||
|
log_i(" pH send .................. ");
|
||||||
|
my_pH.ph_val = 0; |
||||||
|
my_pH.temp_val = 0; |
||||||
|
memset( ph->rcv_buf, 0, 2*PH_Rcv_Buf_Size ); |
||||||
|
PH_Begin_Rcv( ph, ph->rcv_buf, ph->size_rcv ); |
||||||
|
// HAL_UARTEx_ReceiveToIdle_DMA( &huart3, PH_RCV_Buf, PH_Rcv_Buf_Size );
|
||||||
|
// HAL_UART_Receive_DMA ( &huart3, ph->rcv_buf, ph->size_rcv );
|
||||||
|
// __HAL_UART_ENABLE_IT( &huart3, UART_IT_IDLE );
|
||||||
|
|
||||||
|
ph->timebase = osKernelGetTickCount( ); |
||||||
|
// max3160_485_send_mode();
|
||||||
|
ph->state = PH_Status_Sending ; |
||||||
|
PH_Send( ph, ph->send_buf, ph->size_send ); |
||||||
|
break;
|
||||||
|
case PH_Status_Sending: |
||||||
|
time_ticks = osKernelGetTickCount() ; |
||||||
|
// log_i( " time_ticks :%d %d" , time_ticks, ph->timebase);
|
||||||
|
if ( ( time_ticks - ph->timebase ) > ph->timeout_ms)
|
||||||
|
{ |
||||||
|
ph->state = PH_Status_Timeout ; |
||||||
|
} |
||||||
|
osDelay(5);
|
||||||
|
break; |
||||||
|
case PH_Status_Send_Cplt: |
||||||
|
time_ticks = osKernelGetTickCount() ; |
||||||
|
log_i( "PH_Status_Send_Cplt ..... " ); |
||||||
|
if ( (time_ticks - ph->timebase ) > ph->timeout_ms)
|
||||||
|
{ |
||||||
|
ph->state = PH_Status_Timeout ; |
||||||
|
} |
||||||
|
osDelay(5);
|
||||||
|
break; |
||||||
|
case PH_Status_RCV_OK: |
||||||
|
if ( my_pH.ph_val == 0 & my_pH.temp_val==0 ) |
||||||
|
{ |
||||||
|
my_pH.ph_val = ph->rcv_buf[3]*256 + ph->rcv_buf[4]; |
||||||
|
my_pH.temp_val = ph->rcv_buf[5]*256 + ph->rcv_buf[6]; |
||||||
|
|
||||||
|
log_i( "PH_Status_RCV_OK ..... ph %d temp %d " , my_pH.ph_val, my_pH.temp_val); |
||||||
|
ph->state = PH_Status_DATA_OK ; |
||||||
|
} |
||||||
|
// TODO 停止DMA
|
||||||
|
HAL_UART_DMAStop( ph->uarthelper->huart );
|
||||||
|
osDelay(20);
|
||||||
|
break; |
||||||
|
case PH_Status_DATA_OK: |
||||||
|
osDelay(20);
|
||||||
|
break;
|
||||||
|
case PH_Status_Timeout: |
||||||
|
log_e( " pH timeout ..... " ); |
||||||
|
ph->state = PH_Status_Waiting ; |
||||||
|
HAL_UART_DMAStop( ph->uarthelper->huart );
|
||||||
|
osDelay(5);
|
||||||
|
break; |
||||||
|
case PH_Status_Error: |
||||||
|
log_e( " pH error ..... " ); |
||||||
|
ph->state = PH_Status_Waiting ; |
||||||
|
HAL_UART_DMAStop( ph->uarthelper->huart );
|
||||||
|
osDelay(5);
|
||||||
|
break;
|
||||||
|
default: |
||||||
|
break; |
||||||
|
} |
||||||
|
|
||||||
|
osDelay(20);
|
||||||
|
}
|
||||||
|
} |
||||||
|
|
||||||
|
int PH_Test( ) |
||||||
|
{ |
||||||
|
HAL_UART_Transmit_IT( &huart3, ph->send_buf, ph->size_send ); |
||||||
|
osDelay(20); |
||||||
|
if ( HAL_UART_Receive ( &huart3, ph->rcv_buf, ph->size_rcv ,0xFF) != HAL_OK ){ |
||||||
|
return -1; |
||||||
|
} |
||||||
|
return 0; |
||||||
|
} |
||||||
|
void PH_Start( ) |
||||||
|
{ |
||||||
|
// log_e( " pH PH_Start ..... " );
|
||||||
|
ph->state = PH_Status_Ready;
|
||||||
|
} |
||||||
|
void PH_Stop( ) |
||||||
|
{ |
||||||
|
ph->state = PH_Status_Waiting;
|
||||||
|
} |
||||||
|
|
||||||
|
/****************** 接口 *******************/ |
||||||
|
|
||||||
|
|
||||||
|
void PH_Set_Uarthelper( PH_TypeDef *ph, UartHelper_TypeDef * uarthelper) |
||||||
|
{ |
||||||
|
ph->uarthelper = uarthelper; |
||||||
|
} |
||||||
|
void PH_Set_Interface( PH_TypeDef *ph, UartInterface_TypeDef * interface ) |
||||||
|
{ |
||||||
|
UartHelper_Set_Interface( ph->uarthelper, interface ); |
||||||
|
} |
||||||
|
void PH_Set_Huart( PH_TypeDef *ph, UART_HandleTypeDef * huart ) |
||||||
|
{ |
||||||
|
ph->uarthelper->huart = huart; |
||||||
|
// UartHelper_Set_Huart( ph->uarthelper, huart );
|
||||||
|
} |
||||||
|
void PH_Set_Interface_Type( PH_TypeDef *ph, Uart_Interface_Type_Typedef interface_type ) |
||||||
|
{ |
||||||
|
ph->interface_type = interface_type;
|
||||||
|
ph->uarthelper->interface_type = interface_type;
|
||||||
|
UartInterface_Setup_Interface_type( ph->uarthelper->interface ,ph->interface_type);
|
||||||
|
} |
||||||
|
void PH_Set_RsMode_232_485( PH_TypeDef *ph, Uart_RS_Mode_TypeDef rs_232_485 ) |
||||||
|
{ |
||||||
|
ph->mode_232_485 = rs_232_485;
|
||||||
|
ph->uarthelper->mode_232_485 = rs_232_485;
|
||||||
|
UartInterface_Setup_Mode_232_485( ph->uarthelper->interface, my_pH.mode_232_485 ); |
||||||
|
|
||||||
|
} |
||||||
|
void PH_Set_Trans_Type( PH_TypeDef *ph, Uart_Transmode_TypeDef trans_type ) |
||||||
|
{ |
||||||
|
ph->trans_type = trans_type;
|
||||||
|
} |
||||||
|
void PH_Set_Rcv_Type( PH_TypeDef *ph, Uart_Transmode_TypeDef rcv_type ) |
||||||
|
{ |
||||||
|
ph->rcv_type = rcv_type;
|
||||||
|
|
||||||
|
} |
||||||
|
void PH_Set_Idle_Enable( PH_TypeDef *ph, Uart_IDLE_Enable_TypeDef idle_enable_disable ) |
||||||
|
{ |
||||||
|
ph->idle_enable_disable = idle_enable_disable;
|
||||||
|
} |
||||||
|
|
||||||
|
void PH_Set_TransMode( PH_TypeDef *ph, Uart_Transmode_TypeDef trans_mode ) |
||||||
|
{ |
||||||
|
ph->trans_type = trans_mode;
|
||||||
|
ph->rcv_type = trans_mode;
|
||||||
|
} |
||||||
|
|
||||||
|
void PH_Set_Timeout( PH_TypeDef *ph, uint16_t timeout_ms) |
||||||
|
{ |
||||||
|
ph->timeout_ms = timeout_ms;
|
||||||
|
} |
||||||
|
void PH_Set_Sendbuf( PH_TypeDef *ph, uint8_t * buf, uint16_t size) |
||||||
|
{ |
||||||
|
ph->send_buf = buf; |
||||||
|
ph->size_send = size; |
||||||
|
// log_i( " size_send %d", sensor->size_send);
|
||||||
|
} |
||||||
|
|
||||||
|
void PH_Set_Rcvbuf( PH_TypeDef *ph, uint8_t * buf, uint16_t size) |
||||||
|
{ |
||||||
|
ph->rcv_buf = buf; |
||||||
|
ph->size_rcv = size; |
||||||
|
// log_i( " size_rcv %d", demo->size_rcv);
|
||||||
|
} |
||||||
|
|
||||||
|
int PH_Send( PH_TypeDef *ph, uint8_t * buf, uint16_t size ) |
||||||
|
{ |
||||||
|
// log_i( "SensorSend size_ %d", demo->size_send );
|
||||||
|
ph->timebase = HAL_GetTick(); |
||||||
|
UartInterface_Set_GPIO_For_Transmit( ph->uarthelper->interface ); |
||||||
|
// UartHelper_Send_TxPrepare_Callback( ph->uarthelper );
|
||||||
|
// ph->send_status = 1;
|
||||||
|
if ( ph->trans_type == 0 ) |
||||||
|
return HAL_UART_Transmit( ph->uarthelper->huart, buf, size ,0XFF); |
||||||
|
if ( ph->trans_type == 1 ) |
||||||
|
return HAL_UART_Transmit_IT( ph->uarthelper->huart, buf, size ); |
||||||
|
if ( ph->trans_type == 2 ) |
||||||
|
return HAL_UART_Transmit_DMA( ph->uarthelper->huart, buf, size ); |
||||||
|
return -1; |
||||||
|
// ph->send_flag = 0;
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
void PH_Begin_Rcv( PH_TypeDef *ph, uint8_t * buf, uint16_t size) |
||||||
|
{ |
||||||
|
/* 是否开启空闲中断*/ |
||||||
|
if ( ph->idle_enable_disable == 1 ) |
||||||
|
{ |
||||||
|
// log_i(" ** idle enable...");
|
||||||
|
__HAL_UART_ENABLE_IT( ph->uarthelper->huart, UART_IT_IDLE ); |
||||||
|
} |
||||||
|
|
||||||
|
if ( ph->trans_type == 0 ) |
||||||
|
{ |
||||||
|
// TODO 发生错误怎么处理
|
||||||
|
HAL_UART_Receive( ph->uarthelper->huart, buf, size ,0X0FFF); |
||||||
|
} |
||||||
|
|
||||||
|
if ( ph->trans_type == 1 ) |
||||||
|
{ |
||||||
|
HAL_UART_Receive_IT( ph->uarthelper->huart, buf, size); |
||||||
|
} |
||||||
|
|
||||||
|
if ( ph->trans_type == 2 ) |
||||||
|
{ |
||||||
|
HAL_UART_Receive_DMA( ph->uarthelper->huart, buf, size); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void PH_Send_Cplt_Callback( PH_TypeDef *ph ) |
||||||
|
{ |
||||||
|
// ph->timebase = HAL_GetTick();
|
||||||
|
ph->status = Uart_Status_Send_Cplt; |
||||||
|
if ( ph->interface_type != 0 ) |
||||||
|
{ |
||||||
|
UartInterface_Set_GPIO_For_Trans_Cplt( ph->uarthelper->interface ); |
||||||
|
// UartHelper_Set_GPIO_For_Trans_Cplt( ph->uarthelper );
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
void PH_Rcv_Idle_Callback( PH_TypeDef *ph ) |
||||||
|
{ |
||||||
|
/* 搬运 数据到 kfifo*/ |
||||||
|
ph->status = 0; |
||||||
|
ph->send_flag = 0; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void PH_Rcv_Cplt_Callback( PH_TypeDef *ph ) |
||||||
|
{ |
||||||
|
/* 搬运 数据到 kfifo*/ |
||||||
|
log_i( " PH_Rcv_Cplt_Callback 1 .... " ); |
||||||
|
ph->rcv_ok = 1 ; |
||||||
|
// ph->status = 0;
|
||||||
|
// ph->send_flag = 1;
|
||||||
|
// if ( ph->mode < 2 )
|
||||||
|
// ph->command_seq++;
|
||||||
|
} |
||||||
|
|
||||||
|
int PH_Get_Data_OK( PH_TypeDef *ph ) |
||||||
|
{ |
||||||
|
return ph->rcv_ok; |
||||||
|
} |
||||||
|
void PH_Set_Send_Flag( PH_TypeDef *ph ) |
||||||
|
{ |
||||||
|
// vPortEnterCritical();
|
||||||
|
ph->send_flag = 1; |
||||||
|
ph->command_seq = 0; |
||||||
|
ph->data_ok = 0; |
||||||
|
// vPortExitCritical( );
|
||||||
|
} |
||||||
|
|
||||||
|
#endif |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// UartHelper_Set_232 485 UartInterface
|
||||||
|
// UartInterface_Setup_Mode_232_485( ph->uarthelper->interface, my_pH.mode_232_485 );
|
||||||
|
// if (ph->interface_type == 0)
|
||||||
|
// UartInterface_Set_232( ph->uarthelper->interface);
|
||||||
|
// if (ph->interface_type == 1)
|
||||||
|
// UartInterface_Set_485( ph->uarthelper->interface);
|
||||||
|
// if (ph->interface_type ==2 && my_pH.mode_232_485 ==Uart_RSMODE_232)
|
||||||
|
// UartInterface_Set_232( ph->uarthelper->interface);
|
||||||
|
// if (ph->interface_type ==2 && my_pH.mode_232_485 ==Uart_RSMODE_485)
|
||||||
|
// UartInterface_Set_485( ph->uarthelper->interface);
|
||||||
|
// log_i( " interface-> %d %d (0:default, 1:485, 2:3160) " ,ph->uarthelper->interface_type ,ph->uarthelper->interface->interface_type );
|
||||||
|
// log_i( "ph 232_485 -> %d %d (0:232 ,1: 485) " ,ph->uarthelper->mode_232_485, ph->uarthelper->interface->mode_232_485 );
|
||||||
@ -0,0 +1,167 @@ |
|||||||
|
#ifndef EEPROM_H_ |
||||||
|
#define EEPROM_H_ |
||||||
|
/*
|
||||||
|
* 两种方法: |
||||||
|
* 一种直接调用读写多字节, 多任务下可能导致阻塞 |
||||||
|
* 一种设置size send_buf 实现 |
||||||
|
*/ |
||||||
|
#include "main.h" |
||||||
|
// #include "platform.h"
|
||||||
|
#include "i2c.h" |
||||||
|
#include "i2c_helper.h" |
||||||
|
|
||||||
|
#include "FreeRTOSConfig.h" |
||||||
|
#include "cmsis_os2.h" |
||||||
|
#include "elog.h" |
||||||
|
|
||||||
|
#define EEPROM_BYTE_DELAY_ENABLE 1 |
||||||
|
|
||||||
|
typedef enum { |
||||||
|
EEPROM_EVT_WRITE, |
||||||
|
EEPROM_EVT_READ, |
||||||
|
EEPROM_EVT_WRITE_BYTE_DELAY, |
||||||
|
}EEPROM_EVT_TypeDef; |
||||||
|
|
||||||
|
typedef enum { |
||||||
|
EEPROM_STATE_READY, |
||||||
|
EEPROM_STATE_WRITE, |
||||||
|
EEPROM_STATE_READ, |
||||||
|
}EEPROM_STATE_TypeDef; |
||||||
|
|
||||||
|
typedef enum { |
||||||
|
EEPROM_MEM_ADDR_TYPE_Bit8, |
||||||
|
EEPROM_MEM_ADDR_BIT_TYPE_Bit16, |
||||||
|
}EEPROM_MEM_ADDR_TypeDef; |
||||||
|
|
||||||
|
typedef enum { |
||||||
|
EEPROM_MEM_ADDR_BIT_8, |
||||||
|
EEPROM_MEM_ADDR_BIT_16, |
||||||
|
}EEPROM_MEM_ADDR_BIT_TypeDef; |
||||||
|
|
||||||
|
typedef enum { |
||||||
|
EEPROM_DEV_ADDR_BIT_8, |
||||||
|
EEPROM_DEV_ADDR_BIT_10, |
||||||
|
} EEPROM_DEV_ADDR_TypeDef; |
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
AT24C01 =127, // 8bit mem_addr
|
||||||
|
AT24C02 =255, |
||||||
|
AT24C04 =511, // 16bit mem_addr,先发 high8 后 low8
|
||||||
|
AT24C08 =1023, |
||||||
|
AT24C16 =2047, |
||||||
|
AT24C32 =4095, |
||||||
|
AT24C64 =8191, |
||||||
|
AT24C128 =16383, |
||||||
|
AT24C256 =32767,
|
||||||
|
}EEPROM_MODEL_TypeDef; |
||||||
|
|
||||||
|
// typedef void (*read_callback)();
|
||||||
|
// typedef void (*write_callback)();
|
||||||
|
typedef struct |
||||||
|
{ |
||||||
|
I2C_HandleTypeDef *hi2c; |
||||||
|
// I2CHelper_TypeDef *i2chelper;
|
||||||
|
EEPROM_MODEL_TypeDef model; // AT24C01 AT24C02 AT24C256
|
||||||
|
EEPROM_MEM_ADDR_TypeDef mem_addr_type; // 1: 8bit 2: 16bit I2C_MEMADD_SIZE_8BIT I2C_MEMADD_SIZE_16BIT
|
||||||
|
// EEPROM_MEM_ADDR_BIT_TypeDef mem_addr_bit; // 1: 7bit 2: 10bit
|
||||||
|
EEPROM_DEV_ADDR_TypeDef dev_addr; // 8bit 写地址
|
||||||
|
uint8_t page_addr; |
||||||
|
|
||||||
|
volatile EEPROM_STATE_TypeDef state; |
||||||
|
uint8_t write_delay_ms; // 5-8ms
|
||||||
|
uint32_t time_base; // 从系统获得一个systick的毫秒数
|
||||||
|
|
||||||
|
uint8_t mode; // polling 0 , it 1, dma 2
|
||||||
|
uint8_t writeCplt; |
||||||
|
uint8_t readCplt; |
||||||
|
|
||||||
|
// 设置任务参数 发送一个 mem_addr++ send_buf++ size--
|
||||||
|
uint8_t *send_buf;
|
||||||
|
uint16_t size;
|
||||||
|
uint16_t mem_addr;
|
||||||
|
uint8_t is_busy; |
||||||
|
uint8_t error; |
||||||
|
|
||||||
|
HAL_I2C_StateTypeDef stat; |
||||||
|
}EEPROM_TypeDef; |
||||||
|
extern EEPROM_TypeDef *eeprom; |
||||||
|
|
||||||
|
typedef struct |
||||||
|
{ |
||||||
|
void (*init)(void); |
||||||
|
void (*deinit)(void); |
||||||
|
void (*port)(void) ; |
||||||
|
EEPROM_MODEL_TypeDef model; // AT24C01 AT24C02 AT24C256
|
||||||
|
EEPROM_MEM_ADDR_TypeDef mem_addr_type;
|
||||||
|
// EEPROM_MEM_ADDR_BIT_TypeDef data_addr_bit;
|
||||||
|
EEPROM_DEV_ADDR_TypeDef dev_addr;
|
||||||
|
uint8_t page_addr; |
||||||
|
}My_EEPROM_TypeDef; |
||||||
|
extern My_EEPROM_TypeDef my_eeprom; |
||||||
|
|
||||||
|
void Eeprom_Init( ); |
||||||
|
void Eeprom_DeInit( ); |
||||||
|
void Eeprom_Port( ); |
||||||
|
int Eeprom_SET_I2CHelper( EEPROM_TypeDef *eeprom, I2CHelper_TypeDef *i2chelper ); |
||||||
|
int Eeprom_SET_Device_Model( EEPROM_TypeDef *eeprom, EEPROM_MODEL_TypeDef model ); |
||||||
|
int Eeprom_SET_Device_Addr( EEPROM_TypeDef *eeprom, uint8_t dev_addr ); |
||||||
|
int Eeprom_SET_Mem_Addr ( EEPROM_TypeDef *eeprom, uint16_t mem_addr ); |
||||||
|
int Eeprom_SET_Mem_Addr_Type( EEPROM_TypeDef *eeprom, EEPROM_MEM_ADDR_TypeDef mem_addr_type ); |
||||||
|
int Eeprom_SET_Mem_Addr_Bit_Type( EEPROM_TypeDef *eeprom, EEPROM_MEM_ADDR_BIT_TypeDef mem_addr_bit ); |
||||||
|
|
||||||
|
int Eeprom_SET_WorkMode( EEPROM_TypeDef *eeprom, I2C_HELPER_MODE_TypeDef mem_addr_type); |
||||||
|
int Eeprom_SET_Write_Delay_ms( EEPROM_TypeDef *eeprom, uint8_t write_delay_ms); |
||||||
|
|
||||||
|
// int Eeprom_Transmit(EEPROM_TypeDef *eeprom, uint8_t * buf, uint16_t size);
|
||||||
|
// int Eeprom_Begin_Rcv(EEPROM_TypeDef *eeprom, uint8_t * buf, uint16_t size);
|
||||||
|
|
||||||
|
int Eeprom_Read(EEPROM_TypeDef *eeprom, uint8_t * buf, uint16_t size ); |
||||||
|
// int Eeprom_Write(EEPROM_TypeDef *eeprom, uint8_t * buf, uint16_t size );
|
||||||
|
|
||||||
|
void Eeprom_Set_Sendbuf_Size(EEPROM_TypeDef *eeprom, uint8_t * buf, uint16_t size); |
||||||
|
|
||||||
|
int Eeprom_Test( ); |
||||||
|
|
||||||
|
#ifdef EEPROM_BYTE_DELAY_ENABLE |
||||||
|
int Eeprom_Write_By_Byte_Delay(EEPROM_TypeDef *eeprom, uint8_t * buf, uint16_t size); |
||||||
|
#endif |
||||||
|
|
||||||
|
#endif |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 用非阻塞方法写 EEPROM 会写不进去--> 写数据到EEPROM,每个字节加5-8ms 延时 |
||||||
|
* 还是用阻塞的方法区写, 读可以考虑非阻塞 --> IT DMA
|
||||||
|
* 不用 i2chelper 直接用hi2c,
|
||||||
|
*
|
||||||
|
* Eeprom_SET_Mem_Addr 设置eeprom数据地址 |
||||||
|
* Eeprom_Set_Sendbuf_Size 设置buf size 进行写入 EEprom |
||||||
|
*
|
||||||
|
* 读取 |
||||||
|
* Eeprom_SET_Mem_Addr 设置eeprom数据地址 |
||||||
|
* HAL_I2C_Mem_Read |
||||||
|
* @details
|
||||||
|
*
|
||||||
|
* uint8_t buf1[4] ={0x05, 0x03 , 0x04, 0x05}; |
||||||
|
uint8_t buf2[4] = {0x08,0x08,0x08,0x08} ; |
||||||
|
int st; |
||||||
|
// Eeprom_Set_Sendbuf_Size(eeprom, buf1, 4);
|
||||||
|
// my_eeprom.port();
|
||||||
|
Eeprom_SET_Mem_Addr( eeprom, 0 ); |
||||||
|
st = HAL_I2C_Mem_Write(eeprom->hi2c, eeprom->dev_addr, eeprom->mem_addr, eeprom->mem_addr_type, buf1, 4, eeprom->write_delay_ms); |
||||||
|
osDelay( 10 ); |
||||||
|
// Eeprom_Read( eeprom, buf2, 4);
|
||||||
|
// st = HAL_I2C_Mem_Read(eeprom->hi2c, eeprom->dev_addr, eeprom->mem_addr, eeprom->mem_addr_type, buf2, 4, eeprom->write_delay_ms);
|
||||||
|
|
||||||
|
Eeprom_SET_Mem_Addr( eeprom, 0 ); |
||||||
|
if ( Eeprom_Read(eeprom, buf2, 4) != 0 )
|
||||||
|
{ |
||||||
|
log_i(" Eeprom Read Config Error "); |
||||||
|
}else{ |
||||||
|
log_i(" Eeprom Read Config OK! "); |
||||||
|
} |
||||||
|
|
||||||
|
osDelay(10); |
||||||
|
log_i( "buf2 %d %d ", buf2[0] , buf2[1]); |
||||||
|
*/ |
||||||
@ -0,0 +1,118 @@ |
|||||||
|
#ifndef __I2C_HELPER_H |
||||||
|
#define __I2C_HELPER_H |
||||||
|
/**
|
||||||
|
* 封装 Master模式
|
||||||
|
*/ |
||||||
|
|
||||||
|
#ifdef __cplusplus |
||||||
|
extern "C" { |
||||||
|
#endif |
||||||
|
|
||||||
|
#include "i2c.h" |
||||||
|
#include <stdlib.h> |
||||||
|
/* 回调函数,将数据返回上层 */ |
||||||
|
typedef void (*it_callback)(void *obj,uint8_t *buf, uint32_t buf_size ); |
||||||
|
|
||||||
|
/* 由于可能存在多个外设,考虑将 事件类型封装在helper, 事件定义初始化不必放这里*/ |
||||||
|
typedef enum |
||||||
|
{ |
||||||
|
I2C_HELPER_Event_READY, /*!< Startup finished. */ |
||||||
|
I2C_HELPER_Event_INIT,
|
||||||
|
I2C_HELPER_Event_INIT_SUCCESS,
|
||||||
|
I2C_HELPER_Event_TRANS_ONLY,
|
||||||
|
I2C_HELPER_Event_TRANS_FOR_DATA,
|
||||||
|
I2C_HELPER_Event_DATA_RCV,
|
||||||
|
} I2C_HELPER_Event_TypeDef; |
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{ |
||||||
|
I2C_HELPER_TRANS_POLLING, |
||||||
|
I2C_HELPER_TRANS_IT, |
||||||
|
I2C_HELPER_TRANS_DMA |
||||||
|
}I2C_HELPER_TRANS_TypeDef; |
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{ |
||||||
|
I2C_HELPER_RCV_POLLING, |
||||||
|
I2C_HELPER_RCV_IT, |
||||||
|
I2C_HELPER_RCV_DMA |
||||||
|
}I2C_HELPER_RCV_TypeDef; |
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{ |
||||||
|
I2C_HELPER_MODE_MASTER, |
||||||
|
I2C_HELPER_MODE_SLAVE |
||||||
|
}I2C_HELPER_MODE_TypeDef; |
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{ |
||||||
|
I2C_HandleTypeDef *hi2c; |
||||||
|
uint8_t i2c_write_address; |
||||||
|
uint8_t i2c_read_address; |
||||||
|
I2C_HELPER_TRANS_TypeDef trans_type; /* 0 :polling, 1: IT 2: DMA*/ |
||||||
|
I2C_HELPER_RCV_TypeDef rcv_type; /* 0 :polling, 1: IT 2: DMA*/ |
||||||
|
I2C_HELPER_MODE_TypeDef mode;
|
||||||
|
|
||||||
|
uint8_t *trans_buf; |
||||||
|
volatile uint32_t trans_size; |
||||||
|
volatile uint32_t trans_data_con; |
||||||
|
|
||||||
|
uint8_t *receive_buf; |
||||||
|
volatile uint32_t receive_size; |
||||||
|
volatile uint8_t receive_data_con; |
||||||
|
|
||||||
|
// volatile uint8_t receive_buf_con;
|
||||||
|
// uint32_t receive_buf_half_len;
|
||||||
|
// uint8_t half_flag; /*0 : 未半满, 1:半满, 2: 半满已经处理*/
|
||||||
|
|
||||||
|
// volatile Uart_Status_TypeDef status; /* 发送状态 0: ready , 1:正在发送 busy,2:发送ok,*/
|
||||||
|
|
||||||
|
void * obj; |
||||||
|
it_callback callback; |
||||||
|
|
||||||
|
|
||||||
|
}I2CHelper_TypeDef; |
||||||
|
|
||||||
|
I2CHelper_TypeDef * I2CHelper_Init( ); |
||||||
|
void I2CHelper_Set_Hi2c( I2CHelper_TypeDef *i2chelper, I2C_HandleTypeDef * hi2c ); |
||||||
|
void I2CHelper_Set_Mode( I2CHelper_TypeDef *i2chelper, I2C_HELPER_MODE_TypeDef mode ); |
||||||
|
void I2CHelper_Set_Trans_Type( I2CHelper_TypeDef *i2chelper, I2C_HELPER_TRANS_TypeDef trans_type ); |
||||||
|
void I2CHelper_Set_Rcv_Type( I2CHelper_TypeDef *i2chelper, I2C_HELPER_RCV_TypeDef rcv_type ); |
||||||
|
|
||||||
|
// void I2CHelper_Set_timeout( I2CHelper_TypeDef *i2chelper, uint32_t timeout_ms );
|
||||||
|
|
||||||
|
int I2CHelper_Set_callback_func_obj( I2CHelper_TypeDef *i2chelper, void * obj, it_callback callback ); |
||||||
|
|
||||||
|
void I2CHelper_Set_rcv_buf( I2CHelper_TypeDef *i2chelper, uint8_t *buf, uint32_t buf_size ); |
||||||
|
void I2CHelper_Set_Trans_Buf( I2CHelper_TypeDef *i2chelper, uint8_t *buf, uint32_t buf_size ); |
||||||
|
|
||||||
|
int I2CHelper_Write( I2CHelper_TypeDef *i2chelper, uint8_t * buf, uint16_t size); |
||||||
|
int I2CHelper_Read(I2CHelper_TypeDef *i2chelper, uint8_t * buf, uint16_t size); |
||||||
|
|
||||||
|
void I2CHelper_Snd_Cplt_Callback( ); |
||||||
|
void I2CHelper_Rcv_Cplt_Callback( ); |
||||||
|
|
||||||
|
// int I2CHelper_Flags_Set(I2CHelper_TypeDef *i2chelper, I2C_HELPER_Event_TypeDef evt_type );
|
||||||
|
// int I2CHelper_Flags_Clear(I2CHelper_TypeDef *i2chelper, I2C_HELPER_Event_TypeDef evt_type );
|
||||||
|
// int I2CHelper_Flags_Wait(I2CHelper_TypeDef *i2chelper, I2C_HELPER_Event_TypeDef evt_type );
|
||||||
|
|
||||||
|
|
||||||
|
// void I2CHelper_Set_GPIO_For_Trans_Cplt( I2CHelper_TypeDef *i2chelper );
|
||||||
|
// void I2CHelper_Rcv_Cplt_Callback( I2CHelper_TypeDef *i2chelper );
|
||||||
|
// void I2CHelper_Rcv_Idle_Callback( I2CHelper_TypeDef *i2chelper );
|
||||||
|
// void I2CHelper_Rcv_DMA_Half_Callback( I2CHelper_TypeDef *i2chelper );
|
||||||
|
|
||||||
|
int I2CHelper_copy( I2CHelper_TypeDef *i2chelper, uint8_t *buf, uint32_t buf_size ); |
||||||
|
int I2CHelper_isbusy( I2CHelper_TypeDef *i2chelper ); |
||||||
|
void I2CHelper_error( I2CHelper_TypeDef *i2chelper ); |
||||||
|
|
||||||
|
|
||||||
|
// uint16_t Get_Crc16(const char *buf, uint16_t len);
|
||||||
|
// uint8_t Check_Crc16(uint8_t *buf, uint16_t length);
|
||||||
|
#ifdef __cplusplus |
||||||
|
} |
||||||
|
#endif |
||||||
|
|
||||||
|
#endif |
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,125 @@ |
|||||||
|
#ifndef __SPI_HELPER_H |
||||||
|
#define __SPI_HELPER_H |
||||||
|
/**
|
||||||
|
* 封装 uart 发送接收操作 |
||||||
|
* ?? 是否用到buf?
|
||||||
|
*/ |
||||||
|
|
||||||
|
#if 0
|
||||||
|
|
||||||
|
#ifdef __cplusplus |
||||||
|
extern "C" { |
||||||
|
#endif |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include "spi.h" |
||||||
|
#include <stdlib.h> |
||||||
|
/* 回调函数,将数据返回上层 */ |
||||||
|
typedef void (*it_callback)(void *obj,uint8_t *buf, uint32_t buf_size ); |
||||||
|
|
||||||
|
/* 由于可能存在多个外设,考虑将 事件类型封装在helper, 事件定义初始化不必放这里*/ |
||||||
|
typedef enum |
||||||
|
{ |
||||||
|
SPI_HELPER_Event_READY, /*!< Startup finished. */ |
||||||
|
SPI_HELPER_Event_INIT,
|
||||||
|
SPI_HELPER_Event_INIT_SUCCESS,
|
||||||
|
SPI_HELPER_Event_TRANS_ONLY,
|
||||||
|
SPI_HELPER_Event_TRANS_FOR_DATA,
|
||||||
|
SPI_HELPER_Event_DATA_RCV,
|
||||||
|
} SPI_HELPER_Event_TypeDef; |
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{ |
||||||
|
SPI_HELPER_TRANS_POLLING, |
||||||
|
SPI_HELPER_TRANS_IT, |
||||||
|
SPI_HELPER_TRANS_DMA |
||||||
|
}SPI_HELPER_TRANS_TypeDef; |
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{ |
||||||
|
SPI_HELPER_RCV_POLLING, |
||||||
|
SPI_HELPER_RCV_IT, |
||||||
|
SPI_HELPER_RCV_DMA |
||||||
|
}SPI_HELPER_RCV_TypeDef; |
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{ |
||||||
|
SPI_HELPER_MODE_MASTER, |
||||||
|
SPI_HELPER_MODE_SLAVE |
||||||
|
}SPI_HELPER_MODE_TypeDef; |
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{ |
||||||
|
SPI_HandleTypeDef *hspi; |
||||||
|
uint8_t i2c_write_address; |
||||||
|
uint8_t i2c_read_address; |
||||||
|
SPI_HELPER_TRANS_TypeDef trans_type; /* 0 :polling, 1: IT 2: DMA*/ |
||||||
|
SPI_HELPER_RCV_TypeDef rcv_type; /* 0 :polling, 1: IT 2: DMA*/ |
||||||
|
SPI_HELPER_MODE_TypeDef mode;
|
||||||
|
|
||||||
|
uint8_t *trans_buf; |
||||||
|
volatile uint32_t trans_size; |
||||||
|
volatile uint32_t trans_data_con; |
||||||
|
|
||||||
|
uint8_t *receive_buf; |
||||||
|
volatile uint32_t receive_size; |
||||||
|
volatile uint8_t receive_data_con; |
||||||
|
|
||||||
|
// volatile uint8_t receive_buf_con;
|
||||||
|
// uint32_t receive_buf_half_len;
|
||||||
|
// uint8_t half_flag; /*0 : 未半满, 1:半满, 2: 半满已经处理*/
|
||||||
|
|
||||||
|
// volatile Uart_Status_TypeDef status; /* 发送状态 0: ready , 1:正在发送 busy,2:发送ok,*/
|
||||||
|
|
||||||
|
void * obj; |
||||||
|
it_callback callback; |
||||||
|
|
||||||
|
|
||||||
|
}SPIHelper_TypeDef; |
||||||
|
|
||||||
|
SPIHelper_TypeDef * SPIHelper_Init( ); |
||||||
|
void SPIHelper_Set_hspi( SPIHelper_TypeDef *spihelper, SPI_HandleTypeDef * hspi ); |
||||||
|
void SPIHelper_Set_Mode( SPIHelper_TypeDef *spihelper, SPI_HELPER_MODE_TypeDef mode ); |
||||||
|
void SPIHelper_Set_Trans_Type( SPIHelper_TypeDef *spihelper, SPI_HELPER_TRANS_TypeDef trans_type ); |
||||||
|
void SPIHelper_Set_Rcv_Type( SPIHelper_TypeDef *spihelper, SPI_HELPER_RCV_TypeDef rcv_type ); |
||||||
|
|
||||||
|
// void SPIHelper_Set_timeout( SPIHelper_TypeDef *spihelper, uint32_t timeout_ms );
|
||||||
|
|
||||||
|
int SPIHelper_Set_callback_func_obj( SPIHelper_TypeDef *spihelper, void * obj, it_callback callback ); |
||||||
|
|
||||||
|
void SPIHelper_Set_rcv_buf( SPIHelper_TypeDef *spihelper, uint8_t *buf, uint32_t buf_size ); |
||||||
|
void SPIHelper_Set_Trans_Buf( SPIHelper_TypeDef *spihelper, uint8_t *buf, uint32_t buf_size ); |
||||||
|
|
||||||
|
int SPIHelper_Transmit( SPIHelper_TypeDef *spihelper, uint8_t * buf, uint16_t size); |
||||||
|
int SPIHelper_Begin_Rcv(SPIHelper_TypeDef *spihelper, uint8_t * buf, uint16_t size); |
||||||
|
|
||||||
|
// int SPIHelper_Flags_Set(SPIHelper_TypeDef *spihelper, SPI_HELPER_Event_TypeDef evt_type );
|
||||||
|
// int SPIHelper_Flags_Clear(SPIHelper_TypeDef *spihelper, SPI_HELPER_Event_TypeDef evt_type );
|
||||||
|
// int SPIHelper_Flags_Wait(SPIHelper_TypeDef *spihelper, SPI_HELPER_Event_TypeDef evt_type );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void SPIHelper_Set_GPIO_For_Trans_Cplt( SPIHelper_TypeDef *spihelper ); |
||||||
|
void SPIHelper_Rcv_Cplt_Callback( SPIHelper_TypeDef *spihelper ); |
||||||
|
void SPIHelper_Rcv_Idle_Callback( SPIHelper_TypeDef *spihelper ); |
||||||
|
void SPIHelper_Rcv_DMA_Half_Callback( SPIHelper_TypeDef *spihelper ); |
||||||
|
|
||||||
|
int SPIHelper_copy(SPIHelper_TypeDef *spihelper,uint8_t *buf,uint32_t buf_size); |
||||||
|
int SPIHelper_isbusy(SPIHelper_TypeDef *spihelper ); |
||||||
|
void SPIHelper_error(SPIHelper_TypeDef *spihelper ); |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// uint16_t Get_Crc16(const char *buf, uint16_t len);
|
||||||
|
// uint8_t Check_Crc16(uint8_t *buf, uint16_t length);
|
||||||
|
#ifdef __cplusplus |
||||||
|
} |
||||||
|
#endif |
||||||
|
|
||||||
|
#endif |
||||||
|
|
||||||
|
#endif |
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,89 @@ |
|||||||
|
#ifndef __UART_HELPER_H |
||||||
|
#define __UART_HANDLE_H |
||||||
|
/**
|
||||||
|
* 封装 uart 发送接收操作 |
||||||
|
* ?? 是否用到buf?
|
||||||
|
*/ |
||||||
|
|
||||||
|
#ifdef __cplusplus |
||||||
|
extern "C" { |
||||||
|
#endif |
||||||
|
|
||||||
|
#include "uart_interface.h" |
||||||
|
|
||||||
|
/* 回调函数,将数据返回上层 */ |
||||||
|
typedef void (*it_callback)(void *obj,uint8_t *buf, uint32_t buf_size ); |
||||||
|
|
||||||
|
// typedef struct uart_tx_record
|
||||||
|
// {
|
||||||
|
// uint32_t size;
|
||||||
|
// uint8_t *buf;
|
||||||
|
// } Uart_Trans_Record_TypeDef;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{ |
||||||
|
UART_HandleTypeDef *huart; |
||||||
|
UartInterface_TypeDef *interface; |
||||||
|
uint8_t interface_type; /* 0: common, 1: 485 ,2:3160*/ |
||||||
|
uint8_t mode_232_485; /* 0: common, 1: 485 */ |
||||||
|
uint8_t trans_type; /* 0 :polling, 1: IT 2: DMA*/ |
||||||
|
uint8_t rcv_type; /* 0 :polling, 1: IT 2: DMA*/ |
||||||
|
uint8_t idle_enable_disable; /* 0 不开启空闲中断 , 1 开启空闲中断 */ |
||||||
|
uint8_t trans_mode; /* 0 :polling, 1: IT 2: DMA*/ |
||||||
|
|
||||||
|
volatile uint32_t trans_size; |
||||||
|
uint8_t *trans_buf; |
||||||
|
|
||||||
|
volatile uint8_t receive_buf_con; |
||||||
|
// volatile uint8_t transferring_flag;
|
||||||
|
volatile uint32_t receive_data_size; |
||||||
|
uint8_t *receive_buf; |
||||||
|
uint32_t receive_buf_half_len; |
||||||
|
uint8_t half_flag; /*0 : 未半满, 1:半满, 2: 半满已经处理*/ |
||||||
|
|
||||||
|
volatile Uart_Status_TypeDef status; /* 发送状态 0: ready , 1:正在发送 busy,2:发送ok,*/ |
||||||
|
|
||||||
|
void * obj; |
||||||
|
it_callback callback; |
||||||
|
|
||||||
|
}UartHelper_TypeDef; |
||||||
|
|
||||||
|
UartHelper_TypeDef * UartHelper_Init( ); |
||||||
|
void UartHelper_Set_Interface( UartHelper_TypeDef *uarthelper, UartInterface_TypeDef * interface ); |
||||||
|
void UartHelper_Set_Huart( UartHelper_TypeDef *uarthelper, UART_HandleTypeDef * huart ); |
||||||
|
void UartHelper_Set_Interface_Type( UartHelper_TypeDef *uarthelper, Uart_Interface_Type_Typedef interface_type ); |
||||||
|
void UartHelper_Set_Trans_Type( UartHelper_TypeDef *uarthelper, Uart_Transmode_TypeDef trans_type ); |
||||||
|
void UartHelper_Set_Rcv_Type( UartHelper_TypeDef *uarthelper, Uart_Transmode_TypeDef rcv_type ); |
||||||
|
void UartHelper_Set_Idle_Enable( UartHelper_TypeDef *uarthelper, Uart_IDLE_Enable_TypeDef idle_enable_disable ); |
||||||
|
void UartHelper_Set_TransMode( UartHelper_TypeDef *uarthelper, Uart_Transmode_TypeDef trans_mode ); |
||||||
|
void UartHelper_Set_RsMode_232_485( UartHelper_TypeDef *uarthelper, Uart_RS_Mode_TypeDef mode_232_485 ); |
||||||
|
// void UartHelper_Set_timeout( UartHelper_TypeDef *uarthelper, uint32_t timeout_ms );
|
||||||
|
|
||||||
|
int UartHelper_Set_callback_func_obj( UartHelper_TypeDef *uarthelper, void * obj, it_callback callback ); |
||||||
|
|
||||||
|
|
||||||
|
void UartHelper_Set_rcv_buf( UartHelper_TypeDef *uarthelper, uint8_t *buf, uint32_t buf_size ); |
||||||
|
void UartHelper_Set_Trans_Buf( UartHelper_TypeDef *uarthelper, uint8_t *buf, uint32_t buf_size ); |
||||||
|
|
||||||
|
int UartHelper_Transmit( UartHelper_TypeDef *uarthelper, uint8_t * buf, uint16_t size); |
||||||
|
int UartHelper_Begin_Rcv(UartHelper_TypeDef *uarthelper, uint8_t * buf, uint16_t size); |
||||||
|
|
||||||
|
void UartHelper_Set_GPIO_For_Trans_Cplt( UartHelper_TypeDef *uarthelper ); |
||||||
|
void UartHelper_Rcv_Cplt_Callback( UartHelper_TypeDef *uarthelper ); |
||||||
|
void UartHelper_Rcv_Idle_Callback( UartHelper_TypeDef *uarthelper ); |
||||||
|
void UartHelper_Rcv_DMA_Half_Callback( UartHelper_TypeDef *uarthelper ); |
||||||
|
|
||||||
|
int UartHelper_copy(UartHelper_TypeDef *uarthelper,uint8_t *buf,uint32_t buf_size); |
||||||
|
int UartHelper_isbusy(UartHelper_TypeDef *uarthelper ); |
||||||
|
void UartHelper_error(UartHelper_TypeDef *uarthelper ); |
||||||
|
|
||||||
|
|
||||||
|
uint16_t Get_Crc16(const char *buf, uint16_t len); |
||||||
|
uint8_t Check_Crc16(uint8_t *buf, uint16_t length);
|
||||||
|
#ifdef __cplusplus |
||||||
|
} |
||||||
|
#endif |
||||||
|
|
||||||
|
#endif |
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,153 @@ |
|||||||
|
#ifndef __UART_INTERFACE_H |
||||||
|
#define __UART_INTERFACE_H |
||||||
|
/**
|
||||||
|
* 封装不同使用类型串口 232 485 max3160 |
||||||
|
* 封装对应的 GPIO操作 |
||||||
|
*/ |
||||||
|
/* 485 3160 启用一个, 两个接口都有 MAX3160_ENABLE */ |
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus |
||||||
|
extern "C" { |
||||||
|
#endif |
||||||
|
|
||||||
|
#include <stdlib.h> |
||||||
|
#include "main.h" |
||||||
|
|
||||||
|
#define MAX485_ENABLE 0 |
||||||
|
#define MAX3160_ENABLE 1 |
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{ |
||||||
|
Uart_Status_Ready = 0x00U, |
||||||
|
Uart_Status_Sending = 0x01U, |
||||||
|
Uart_Status_Send_Cplt = 0x02U, |
||||||
|
Uart_Status_Timeout = 0x10U, |
||||||
|
Uart_Status_Error = 0x11U, |
||||||
|
} Uart_Status_TypeDef; |
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{ |
||||||
|
Uart_Interface_Default = 0x00U, |
||||||
|
Uart_Interface_485 = 0x01U, |
||||||
|
Uart_Interface_Max3160 = 0x02U, |
||||||
|
} Uart_Interface_Type_Typedef;
|
||||||
|
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{ |
||||||
|
Uart_Trans_Polling = 0x00U, |
||||||
|
Uart_Trans_IT = 0x01U, |
||||||
|
Uart_Trans_DMA = 0x02U, |
||||||
|
} Uart_Transmode_TypeDef; |
||||||
|
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{ |
||||||
|
Uart_RSMODE_232 = 0x00U, |
||||||
|
Uart_RSMODE_485 = 0x01U, |
||||||
|
} Uart_RS_Mode_TypeDef; |
||||||
|
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{ |
||||||
|
Uart_IDLE_IT_DISABLE = 0x00U, |
||||||
|
Uart_IDLE_IT_ENABLE = 0x01U, |
||||||
|
} Uart_IDLE_Enable_TypeDef; |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if MAX3160_ENABLE |
||||||
|
|
||||||
|
typedef enum{ |
||||||
|
SEL_232 = 0, |
||||||
|
SEL_485 = 1, |
||||||
|
}Max3160_Sel_TypeDef; |
||||||
|
|
||||||
|
typedef enum{ |
||||||
|
DUPLEX_FULL = 0, |
||||||
|
DUPLEX_HALF = 1, |
||||||
|
}Max3160_Duplex_TypeDef; /* 发送时切换全双工(拉低),否则回显, 接收为半双工(拉高 默认)*/ |
||||||
|
|
||||||
|
typedef enum{ |
||||||
|
DISABLE_485_SEND = 0, |
||||||
|
ENABLE_485_SEND = 1, |
||||||
|
}Max3160_DE_TypeDef; |
||||||
|
|
||||||
|
# endif |
||||||
|
|
||||||
|
#if MAX485_ENABLE |
||||||
|
typedef enum{ |
||||||
|
DISABLE_485_SEND = 0, |
||||||
|
ENABLE_485_SEND = 1, |
||||||
|
}Max_DE_TypeDef; |
||||||
|
# endif |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{ |
||||||
|
// UART_HandleTypeDef *huart;
|
||||||
|
uint8_t interface_type; /* 0: common, 1: 485 ,2:3160*/ |
||||||
|
uint8_t mode_232_485; /* 0: common, 1: 485 */ |
||||||
|
|
||||||
|
#if MAX485_ENABLE |
||||||
|
GPIO_TypeDef *de485_gpio; |
||||||
|
uint16_t de485_pin; |
||||||
|
uint8_t de485; |
||||||
|
#endif |
||||||
|
|
||||||
|
#if MAX3160_ENABLE |
||||||
|
GPIO_TypeDef *de485_gpio; |
||||||
|
uint16_t de485_pin; |
||||||
|
GPIO_TypeDef *sel_gpio; |
||||||
|
GPIO_TypeDef *dplx_gpio; |
||||||
|
uint16_t sel_pin; |
||||||
|
uint16_t dplx_pin; |
||||||
|
uint8_t sel; |
||||||
|
uint8_t dplx; |
||||||
|
#endif |
||||||
|
uint8_t trans_mode; /* 0 :polling, 1: IT 2: DMA*/ |
||||||
|
|
||||||
|
|
||||||
|
}UartInterface_TypeDef; |
||||||
|
|
||||||
|
// extern UartInterface_TypeDef *uart_helper;
|
||||||
|
|
||||||
|
UartInterface_TypeDef * UartInterface_Init( ); |
||||||
|
|
||||||
|
int UartInterface_Setup_Mode_232_485( UartInterface_TypeDef * interface, Uart_RS_Mode_TypeDef mode_232_485 ); |
||||||
|
int UartInterface_Setup_Transmod( UartInterface_TypeDef * interface, Uart_Transmode_TypeDef trans_mode ); |
||||||
|
int UartInterface_Setup_Interface_type( UartInterface_TypeDef * interface, Uart_Interface_Type_Typedef interface_type ); |
||||||
|
// int UartInterface_Setup_Woek_Mode( UartInterface_TypeDef * interface, uint8_t rs_232_485 );
|
||||||
|
|
||||||
|
void UartInterface_Set_Sel_GPIO_Pin(UartInterface_TypeDef * interface, GPIO_TypeDef *gpio, uint16_t pin); |
||||||
|
void UartInterface_Set_Dplx_GPIO_Pin(UartInterface_TypeDef * interface, GPIO_TypeDef *gpio, uint16_t pin); |
||||||
|
void UartInterface_Set_DE485_GPIO_Pin(UartInterface_TypeDef * interface, GPIO_TypeDef *gpio, uint16_t pin); |
||||||
|
|
||||||
|
void UartInterface_Set_232(UartInterface_TypeDef * interface); |
||||||
|
void UartInterface_Set_485(UartInterface_TypeDef * interface); |
||||||
|
|
||||||
|
int UartInterface_Set_GPIO_For_Transmit( UartInterface_TypeDef * interface ); |
||||||
|
int UartInterface_Set_GPIO_For_Trans_Cplt( UartInterface_TypeDef * interface ); |
||||||
|
|
||||||
|
/* 接收方式 也有三种类型 */ |
||||||
|
// int UartInterface_Start_Rcv(UartInterface_TypeDef * interface, uint8_t *buf, uint16_t size);
|
||||||
|
// void UartInterface_Set_Huart(UartInterface_TypeDef * interface, UART_HandleTypeDef *huart);
|
||||||
|
// int UartInterface_Send(UartInterface_TypeDef * interface, uint8_t *buf, uint16_t size);
|
||||||
|
// int __UartInterface_Send(UartInterface_TypeDef * interface , uint8_t *buf, uint16_t size);
|
||||||
|
#ifdef __cplusplus |
||||||
|
} |
||||||
|
#endif |
||||||
|
|
||||||
|
#endif |
||||||
|
|
||||||
|
/**
|
||||||
|
// int UartInterface_Send(UartInterface_TypeDef * interface, uint8_t *buf, uint16_t size);
|
||||||
|
// int __UartInterface_Send(UartInterface_TypeDef * interface , uint8_t *buf, uint16_t size);
|
||||||
|
|
||||||
|
// int UartInterface_Send_TxCplt_Callback( UartInterface_TypeDef * interface );
|
||||||
|
|
||||||
|
// int UartInterface_Send_Cplt(UartInterface_TypeDef * interface);
|
||||||
|
// void UartInterface_Set_tc_flag(UartInterface_TypeDef * interface);
|
||||||
|
*/ |
||||||
@ -0,0 +1,529 @@ |
|||||||
|
/**
|
||||||
|
* @file eeprom.c |
||||||
|
* @author Chen Jihang (embedded@eseaoptics.com) |
||||||
|
* @brief EEPROM驱动 |
||||||
|
* @version 1.0 |
||||||
|
* @date 2023-01-04 |
||||||
|
* |
||||||
|
* @copyright ESEA (c) 2020 |
||||||
|
* |
||||||
|
*/ |
||||||
|
|
||||||
|
// osEventFlagsId_t eepromEventHandle;
|
||||||
|
// const osEventFlagsAttr_t eepromEvent_attributes = {
|
||||||
|
// .name = "eepromEvent"
|
||||||
|
// };
|
||||||
|
|
||||||
|
|
||||||
|
#include "eeprom.h" |
||||||
|
#define pEepromI2C &hi2c1 |
||||||
|
EEPROM_TypeDef *eeprom; |
||||||
|
|
||||||
|
|
||||||
|
My_EEPROM_TypeDef my_eeprom= |
||||||
|
{ |
||||||
|
Eeprom_Init, |
||||||
|
Eeprom_DeInit, |
||||||
|
Eeprom_Port, |
||||||
|
AT24C02, |
||||||
|
EEPROM_MEM_ADDR_TYPE_Bit8, |
||||||
|
// EEPROM_MEM_ADDR_BIT_10,
|
||||||
|
0xA0, // 7+1 bit or 10 + 1 bit, EEPROM 8bit , write A0 , read A1
|
||||||
|
0, |
||||||
|
}; |
||||||
|
|
||||||
|
void Eeprom_Init() |
||||||
|
{ |
||||||
|
eeprom = (EEPROM_TypeDef *)malloc(sizeof(EEPROM_TypeDef)); |
||||||
|
if ( eeprom == NULL ) |
||||||
|
{ |
||||||
|
return NULL; |
||||||
|
} |
||||||
|
eeprom->hi2c = pEepromI2C; |
||||||
|
// eeprom->i2chelper = I2CHelper_Init( );
|
||||||
|
// I2CHelper_Set_Hi2c( eeprom->i2chelper, pEepromI2C );
|
||||||
|
Eeprom_SET_Device_Model( eeprom, my_eeprom.model ); |
||||||
|
Eeprom_SET_Device_Addr( eeprom, my_eeprom.dev_addr ); |
||||||
|
Eeprom_SET_Mem_Addr_Type( eeprom, my_eeprom.mem_addr_type ); |
||||||
|
|
||||||
|
eeprom->writeCplt = 0; |
||||||
|
eeprom->readCplt = 0; |
||||||
|
eeprom->size = 0; |
||||||
|
eeprom->is_busy = 0; |
||||||
|
eeprom->time_base = 0; |
||||||
|
eeprom->write_delay_ms = 5; |
||||||
|
eeprom->mem_addr = 0; |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
void Eeprom_DeInit( ) |
||||||
|
{ |
||||||
|
free(eeprom); |
||||||
|
} |
||||||
|
|
||||||
|
void Eeprom_Port( ) |
||||||
|
{ |
||||||
|
uint32_t i; |
||||||
|
int st; |
||||||
|
for (;;) |
||||||
|
{ |
||||||
|
/* 判断size, size 大于零才开始工作*/ |
||||||
|
if (eeprom->size == 0)
|
||||||
|
{ |
||||||
|
eeprom->send_buf = NULL; |
||||||
|
eeprom->is_busy == 0; |
||||||
|
// log_i("eeprom port func...");
|
||||||
|
osDelay(100); |
||||||
|
}; |
||||||
|
|
||||||
|
/* size> 0, 写入一个数据 */ |
||||||
|
if ( eeprom->size > 0 && eeprom->writeCplt == 0 && eeprom->is_busy == 0 ) |
||||||
|
{ |
||||||
|
eeprom->time_base = osKernelGetTickCount( ); |
||||||
|
eeprom->is_busy = 1; |
||||||
|
// log_i("eeporm write ... ");
|
||||||
|
st = HAL_I2C_Mem_Write(eeprom->hi2c, eeprom->dev_addr, AT24C02, eeprom->mem_addr_type, eeprom->send_buf, 1, eeprom->write_delay_ms); |
||||||
|
if (st != HAL_OK) { |
||||||
|
log_e(" Eeprom Write error"); |
||||||
|
eeprom->size = 0; |
||||||
|
eeprom->send_buf = NULL; |
||||||
|
eeprom->is_busy = 0;
|
||||||
|
break;
|
||||||
|
} |
||||||
|
// I2CHelper_Write( eeprom->i2chelper, eeprom->send_buf, 1 );
|
||||||
|
continue; |
||||||
|
}; |
||||||
|
|
||||||
|
/* 等待 eeprom->write_delay_ms ,写入数据*/ |
||||||
|
if ( eeprom->size > 0 && eeprom->writeCplt == 0 && eeprom->is_busy == 1 ) |
||||||
|
{ |
||||||
|
if( (osKernelGetTickCount( ) - eeprom->time_base) > eeprom->write_delay_ms) |
||||||
|
{ |
||||||
|
// log_i("eeporm write ... 5ms ");
|
||||||
|
eeprom->writeCplt = 1 ; |
||||||
|
} |
||||||
|
continue; |
||||||
|
}; |
||||||
|
|
||||||
|
/* 写完成,处理数据等待进入下一组 */ |
||||||
|
if ( eeprom->size > 0 && eeprom->writeCplt == 1 ) |
||||||
|
{ |
||||||
|
eeprom->send_buf++; |
||||||
|
eeprom->mem_addr++; |
||||||
|
eeprom->size--; |
||||||
|
eeprom->is_busy = 0;
|
||||||
|
eeprom->writeCplt = 0; |
||||||
|
continue; |
||||||
|
}; |
||||||
|
osDelay( 1); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// int Eeprom_SET_I2CHelper( EEPROM_TypeDef *eeprom, I2CHelper_TypeDef *i2chelper )
|
||||||
|
// {
|
||||||
|
// eeprom->i2chelper = i2chelper;
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
|
||||||
|
int Eeprom_SET_Device_Model(EEPROM_TypeDef *eeprom, EEPROM_MODEL_TypeDef model) |
||||||
|
{ |
||||||
|
eeprom->model = model; |
||||||
|
if (eeprom->model < AT24C04 ) |
||||||
|
{ |
||||||
|
eeprom->mem_addr_type = I2C_MEMADD_SIZE_8BIT; |
||||||
|
}else{ |
||||||
|
eeprom->mem_addr_type = I2C_MEMADD_SIZE_16BIT; |
||||||
|
} |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
int Eeprom_SET_Device_Addr(EEPROM_TypeDef *eeprom, uint8_t dev_addr) |
||||||
|
{ |
||||||
|
eeprom->dev_addr = dev_addr; |
||||||
|
// TODO: 需要对I2C 进行设置
|
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
int Eeprom_SET_Mem_Addr ( EEPROM_TypeDef *eeprom, uint16_t mem_addr ) |
||||||
|
{ |
||||||
|
eeprom->mem_addr = mem_addr; |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
int Eeprom_SET_Mem_Addr_Type(EEPROM_TypeDef *eeprom, EEPROM_MEM_ADDR_TypeDef mem_addr_type) |
||||||
|
{ |
||||||
|
eeprom->mem_addr_type = mem_addr_type; |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
int Eeprom_SET_Mem_Addr_Bit(EEPROM_TypeDef *eeprom, EEPROM_MEM_ADDR_BIT_TypeDef mem_addr_bit) |
||||||
|
{ |
||||||
|
// eeprom->mem_addr_bit = mem_addr_bit;
|
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
// int Eeprom_SET_WorkMode( EEPROM_TypeDef *eeprom, I2C_HELPER_MODE_TypeDef mode )
|
||||||
|
// {
|
||||||
|
// eeprom->mode = mode;
|
||||||
|
// I2CHelper_Set_Mode( eeprom->i2chelper, mode );
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
|
||||||
|
int Eeprom_SET_Write_Delay_ms( EEPROM_TypeDef *eeprom, uint8_t write_delay_ms) |
||||||
|
{ |
||||||
|
eeprom->write_delay_ms = write_delay_ms; |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
// int Eeprom_Transmit(EEPROM_TypeDef *eeprom, uint8_t * buf, uint16_t size)
|
||||||
|
// {
|
||||||
|
// // HAL_I2C_Master_Transmit_DMA ( eeprom->i2chelper->hi2c, eeprom->dev_addr, buf ,size );
|
||||||
|
// }
|
||||||
|
|
||||||
|
// int Eeprom_Begin_Rcv(EEPROM_TypeDef *eeprom, uint8_t * buf, uint16_t size)
|
||||||
|
// {
|
||||||
|
// // HAL_I2C_Master_Receive_IT( eeprom->i2chelper->hi2c, eeprom->dev_addr, buf ,size );
|
||||||
|
// // I2CHelper_Begin_Rcv(eeprom->i2chelper, buf, size);
|
||||||
|
|
||||||
|
// // HAL_I2C_Mem_Read(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, 1,eeprom->write_delay_ms);
|
||||||
|
// // HAL_I2C_Mem_Write(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, 1,eeprom->write_delay_ms);
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
int Eeprom_Read(EEPROM_TypeDef *eeprom, uint8_t * buf, uint16_t size) |
||||||
|
{ |
||||||
|
// osEventFlagsGet(eepromEventHandle, EEPROM_EVT_READ);
|
||||||
|
eeprom->readCplt = 0; |
||||||
|
int st; |
||||||
|
st = HAL_I2C_Mem_Read( eeprom->hi2c, eeprom->dev_addr, eeprom->mem_addr, eeprom->mem_addr_type, buf, size, 0xFFFF); |
||||||
|
if ( st != HAL_OK ) { |
||||||
|
return -1; |
||||||
|
} |
||||||
|
return 0; |
||||||
|
// HAL_I2C_Master_Transmit_IT (eeprom->hi2c, eeprom->dev_addr, buf ,size);
|
||||||
|
} |
||||||
|
|
||||||
|
// int Eeprom_Write(EEPROM_TypeDef *eeprom, uint8_t * buf, uint16_t size)
|
||||||
|
// {
|
||||||
|
// // osEventFlagsGet(eepromEventHandle, EEPROM_EVT_WRITE);
|
||||||
|
// eeprom->writeCplt = 0;
|
||||||
|
// // HAL_I2C_Master_Transmit_IT (eeprom->i2chelper->hi2c, eeprom->dev_addr, buf ,size);
|
||||||
|
// }
|
||||||
|
|
||||||
|
void Eeprom_Set_Sendbuf_Size(EEPROM_TypeDef *eeprom, uint8_t * buf, uint16_t size) |
||||||
|
{ |
||||||
|
eeprom->send_buf = buf; |
||||||
|
eeprom->size = size; |
||||||
|
return ; |
||||||
|
} |
||||||
|
|
||||||
|
int Eeprom_Test( ) |
||||||
|
{ |
||||||
|
uint8_t test_send[1] = { 0xFF }; // 不同model,地址不同 方法也不同
|
||||||
|
uint8_t test_rcv = 0; |
||||||
|
int st; |
||||||
|
|
||||||
|
// st = Eeprom_Write( eeprom, test_send, 1 );
|
||||||
|
st = HAL_I2C_Mem_Write(eeprom->hi2c, eeprom->dev_addr, AT24C02, eeprom->mem_addr_type, test_send, 1, eeprom->write_delay_ms); |
||||||
|
osDelay( 10 ); |
||||||
|
|
||||||
|
// st = Eeprom_Read( eeprom, &test_rcv, 1);
|
||||||
|
st = HAL_I2C_Mem_Read(eeprom->hi2c, eeprom->dev_addr, AT24C02, eeprom->mem_addr_type, &test_rcv, 1, eeprom->write_delay_ms); |
||||||
|
osDelay( 5 ); |
||||||
|
|
||||||
|
if ( test_rcv == 255 ){ |
||||||
|
// log_i( " Test Result : PASS " );
|
||||||
|
return 0; |
||||||
|
} |
||||||
|
// log_i( " Test Result : Error st %d val %d " , st, test_rcv );
|
||||||
|
return -1; |
||||||
|
} |
||||||
|
|
||||||
|
// //主机模式发送回调函数
|
||||||
|
// void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *I2cHandle)
|
||||||
|
// {
|
||||||
|
// if (I2cHandle == pEepromI2C)
|
||||||
|
// {
|
||||||
|
// eeprom->writeCplt =1;
|
||||||
|
// log_i("send cplt");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// //主机模式接收回调函数
|
||||||
|
// void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *I2cHandle)
|
||||||
|
// {
|
||||||
|
// if (I2cHandle == pEepromI2C)
|
||||||
|
// {
|
||||||
|
// eeprom->readCplt =1;
|
||||||
|
// log_i("rcv cplt");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
// https://blog.csdn.net/qq_35496059/article/details/101279408
|
||||||
|
// void I2C3_EV_IRQHandler(void)
|
||||||
|
// {
|
||||||
|
// /* USER CODE BEGIN I2C3_EV_IRQn 0 */
|
||||||
|
|
||||||
|
// /* USER CODE END I2C3_EV_IRQn 0 */
|
||||||
|
// loop1:
|
||||||
|
// HAL_I2C_EV_IRQHandler(&hi2c3);
|
||||||
|
// /* USER CODE BEGIN I2C3_EV_IRQn 1 */
|
||||||
|
// if((((I2C3->ISR)&0x08)>>3)==1)//判断是addr触发的中断
|
||||||
|
// {
|
||||||
|
// I2C3->ISR|=0x01;//TXE=1
|
||||||
|
// I2C3->ICR|=0x08;//清除addr
|
||||||
|
// }
|
||||||
|
|
||||||
|
// //读写处理
|
||||||
|
// {
|
||||||
|
|
||||||
|
// if((((I2C3->ISR)&0x10000)>>16)==1)//dir
|
||||||
|
// {
|
||||||
|
// int i=0;
|
||||||
|
// int j=0;
|
||||||
|
// while(((((I2C3->ISR)&0x32)>>5)==0))//detect stop
|
||||||
|
// {
|
||||||
|
// if(((((I2C3->ISR)&0x10000)>>16)==0)||((((I2C3->ISR)&0x08)>>3)==1))//addr or read
|
||||||
|
// goto loop1;
|
||||||
|
// if(((((I2C3->ISR)&0x02)>>1)==1))TXIS
|
||||||
|
// {
|
||||||
|
// if(I2C3->RXDR==0x00)
|
||||||
|
// I2C3->TXDR=ppp1[i];
|
||||||
|
// if(I2C3->RXDR==0x12)
|
||||||
|
// {
|
||||||
|
// I2C3->TXDR=ppp2[i];
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
// //[i]=I2C3->RXDR;
|
||||||
|
// i++;
|
||||||
|
|
||||||
|
// }
|
||||||
|
// if(i==21)
|
||||||
|
// {
|
||||||
|
// //21个字节 退出
|
||||||
|
// ppp2[0]++;
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
// //x=HAL_I2C_Slave_Receive(&hi2c3,ppp,2,5);
|
||||||
|
// I2C3->ICR=(I2C3->ICR)|0x32;//clear stop
|
||||||
|
|
||||||
|
// else//read
|
||||||
|
// {
|
||||||
|
// int i=0;
|
||||||
|
// while(((((I2C3->ISR)&0x32)>>5)==0))//detect stop
|
||||||
|
// {
|
||||||
|
// if(((((I2C3->ISR)&0x10000)>>16)==1)||((((I2C3->ISR)&0x08)>>3)==1))
|
||||||
|
// goto loop1;
|
||||||
|
// if(((((I2C3->ISR)&0x04)>>2)==1))//RXNE
|
||||||
|
// {
|
||||||
|
// ppp[i]=I2C3->RXDR;
|
||||||
|
// i++;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// //x=HAL_I2C_Slave_Receive(&hi2c3,ppp,2,5);
|
||||||
|
// I2C3->ICR=(I2C3->ICR)|0x32;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // I2C3->CR1|=0x08;
|
||||||
|
|
||||||
|
// // /* USER CODE END I2C3_EV_IRQn 1 */
|
||||||
|
// }
|
||||||
|
|
||||||
|
// 寄存器说明
|
||||||
|
// ISR:
|
||||||
|
// |bit23…17|ADDCODE ----|主机地址----------|
|
||||||
|
// |bit16…|DIR------------------|0读/1写------------|在addr=1时更新
|
||||||
|
// |bit15…|BUSY---------------| ---------------------|起始信号=1,检测到stop=0
|
||||||
|
// |bit5…|STOPF---------------|----------------------|检测到stop
|
||||||
|
// |bit3…|ADDR----------------|----------------------|匹配到地址
|
||||||
|
// |bit2…|RXNE----------------|----------------------|RXDR不为空
|
||||||
|
// |bit1…|TXIS------------------|-------------------- -|发送标志
|
||||||
|
// |bit0…|TXE------------------|-----------------------|TXDR为空
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// uint8_t Eeprom_SET_I2C(eeprom_t *eeprom, I2C_HandleTypeDef *i2c)
|
||||||
|
// {
|
||||||
|
// eeprom->i2c = i2c;
|
||||||
|
// eeprom->stat = HAL_I2C_STATE_READY;
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
// uint8_t Eeprom_SET_Device_Model(eeprom_t *eeprom, uint16_t model)
|
||||||
|
// {
|
||||||
|
// eeprom->model = model;
|
||||||
|
// // if (eeprom->model < AT24C16)
|
||||||
|
// // {
|
||||||
|
// // eeprom->mem_addr_type = I2C_MEMADD_SIZE_8BIT;
|
||||||
|
// // }
|
||||||
|
// // else
|
||||||
|
// // {
|
||||||
|
// // eeprom->mem_addr_type = I2C_MEMADD_SIZE_16BIT;
|
||||||
|
// // }
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// uint8_t Eeprom_SET_Device_Addr(eeprom_t *eeprom, uint8_t dev_addr)
|
||||||
|
// {
|
||||||
|
// eeprom->dev_addr = dev_addr;
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// uint8_t Eeprom_SET_Mem_Addr_Type(eeprom_t *eeprom, uint8_t mem_addr_type)
|
||||||
|
// {
|
||||||
|
// eeprom->mem_addr_type = mem_addr_type;
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// uint8_t Eeprom_SET_Workmode(eeprom_t *eeprom, uint8_t workmode)
|
||||||
|
// {
|
||||||
|
// eeprom->WORKMODE = workmode;
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// uint8_t Eeprom_Read_One_Byte(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf)
|
||||||
|
// {
|
||||||
|
// // eeprom->stat = HAL_I2C_Mem_Read_IT(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, 1);
|
||||||
|
// return HAL_I2C_Mem_Read(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, 1,eeprom->write_delay_ms);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// uint8_t Eeprom_Write_One_Byte(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf)
|
||||||
|
// {
|
||||||
|
// return HAL_I2C_Mem_Write(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, 1,eeprom->write_delay_ms);
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
// uint8_t Eeprom_Read_One_Byte_IT(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf)
|
||||||
|
// {
|
||||||
|
// // eeprom->stat = HAL_I2C_Mem_Read_IT(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, 1);
|
||||||
|
// eeprom->size = 0;
|
||||||
|
// return HAL_I2C_Mem_Read_IT(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, 1 );
|
||||||
|
// }
|
||||||
|
|
||||||
|
// uint8_t Eeprom_Write_One_Byte_IT(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf)
|
||||||
|
// {
|
||||||
|
// eeprom->size = 0;
|
||||||
|
// return HAL_I2C_Mem_Write_IT(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, 1 );
|
||||||
|
// }
|
||||||
|
|
||||||
|
// uint8_t Eeprom_Read_Multi_Byte(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf, uint16_t size, uint32_t timeout )
|
||||||
|
// {
|
||||||
|
// // eeprom->stat = HAL_I2C_Mem_Write_IT(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, size);
|
||||||
|
// return HAL_I2C_Mem_Read(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, size,timeout);
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
// uint8_t Eeprom_Write_Multi_Byte(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf, uint16_t size, uint32_t timeout )
|
||||||
|
// {
|
||||||
|
// return HAL_I2C_Mem_Write(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, size,timeout);
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
// uint8_t Eeprom_Read_Multi_Byte_IT(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf, uint16_t size )
|
||||||
|
// {
|
||||||
|
// // eeprom->stat = HAL_I2C_Mem_Write_IT(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, size);
|
||||||
|
// eeprom->stat =HAL_I2C_Mem_Read_IT(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, size );
|
||||||
|
// // LOG(" readstat %d",eeprom->stat);
|
||||||
|
// return eeprom->stat;
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
// uint8_t Eeprom_Write_Multi_Byte_IT(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf, uint16_t size )
|
||||||
|
// {
|
||||||
|
// // 写入数据前端循环调用 Eeprom_send_callback
|
||||||
|
// // return HAL_I2C_Mem_Write_IT(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, size );
|
||||||
|
// eeprom->send_buf = buf;
|
||||||
|
// eeprom->size = size;
|
||||||
|
// eeprom->mem_addr = mem_addr;
|
||||||
|
// return 0;
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * @brief EEPROM发送回调,须循环调用单字节写入
|
||||||
|
// *
|
||||||
|
// * @param eeprom EEPROM描述符
|
||||||
|
// * @return int 0
|
||||||
|
// */
|
||||||
|
// uint8_t Eeprom_send(eeprom_t *eeprom)
|
||||||
|
// {
|
||||||
|
// if (eeprom->size == 0)
|
||||||
|
// {
|
||||||
|
// eeprom->send_buf = NULL;
|
||||||
|
// }
|
||||||
|
// if (eeprom->send_buf == NULL)
|
||||||
|
// {
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
// if ( HAL_I2C_GetState(eeprom->i2c) == 1 )
|
||||||
|
// {
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
// if ( (osKernelGetTickCount() -eeprom->time_base) < eeprom->write_delay_ms )
|
||||||
|
// {
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
// if ( HAL_I2C_GetState(eeprom->i2c) == 2 )
|
||||||
|
// {
|
||||||
|
// // __HAL_I2C_CLEAR_FLAG(eeprom->i2c,I2C_FLAG_AF); // 清除非应答状态
|
||||||
|
// eeprom->i2c->State = HAL_I2C_STATE_READY;
|
||||||
|
// // i2c_clear_state(eeprom->i2c);
|
||||||
|
// eeprom->mem_addr--;
|
||||||
|
// eeprom->send_buf--;
|
||||||
|
// eeprom->size++;
|
||||||
|
// }
|
||||||
|
// if (eeprom->size == 0)
|
||||||
|
// {
|
||||||
|
// eeprom->send_buf = NULL;
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // 单个字节写入 ?? 为什么指向的地址内容发送变化了,静态声明
|
||||||
|
// // LOG( " send buf : %02x %d", *eeprom->send_buf, eeprom->send_buf);
|
||||||
|
// HAL_I2C_Mem_Write_IT(eeprom->i2c, eeprom->dev_addr, eeprom->mem_addr, eeprom->mem_addr_type, eeprom->send_buf, 1 );
|
||||||
|
// // i2c_write_memory(eeprom->i2c,eeprom->dev_addr+eeprom->page_addr,eeprom->mem_addr,eeprom->mem_addr_size,eeprom->send_buf,1);
|
||||||
|
// // eeprom->time_base = __get_tick_milliseconds();
|
||||||
|
// eeprom->time_base = osKernelGetTickCount();
|
||||||
|
// eeprom->mem_addr++;
|
||||||
|
// eeprom->send_buf++;
|
||||||
|
// eeprom->size--;
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// void Eeprom_send_callback(eeprom_t *eeprom)
|
||||||
|
// {
|
||||||
|
// Eeprom_send(eeprom);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// uint8_t Eeprom_get_state(eeprom_t *eeprom)
|
||||||
|
// {
|
||||||
|
// if (eeprom->send_buf != NULL)
|
||||||
|
// {
|
||||||
|
// return 1;
|
||||||
|
// }
|
||||||
|
// if ( HAL_I2C_GetState(eeprom->i2c) == HAL_I2C_STATE_READY )
|
||||||
|
// {
|
||||||
|
// return 0;
|
||||||
|
// };
|
||||||
|
// return 2;
|
||||||
|
// }
|
||||||
@ -0,0 +1,142 @@ |
|||||||
|
#include "i2c_helper.h" |
||||||
|
|
||||||
|
// static I2C_HandleTypeDef *pADS1115_I2C = &hi2c1;
|
||||||
|
|
||||||
|
// osEventFlagsId_t i2chelperEventHandle;
|
||||||
|
// const osEventFlagsAttr_t i2chelperEvent_attributes = {
|
||||||
|
// .name = "i2chelperEvent"
|
||||||
|
// };
|
||||||
|
|
||||||
|
I2CHelper_TypeDef * I2CHelper_Init( ) |
||||||
|
{ |
||||||
|
I2CHelper_TypeDef *Handle = (I2CHelper_TypeDef *)malloc(sizeof(I2CHelper_TypeDef)); |
||||||
|
if (Handle == NULL) |
||||||
|
{ |
||||||
|
return NULL; |
||||||
|
} |
||||||
|
// Handle->delaytime_trans_byte = 0;
|
||||||
|
return Handle; |
||||||
|
} |
||||||
|
void I2CHelper_Set_Hi2c( I2CHelper_TypeDef *i2chelper, I2C_HandleTypeDef * hi2c ) |
||||||
|
{ |
||||||
|
i2chelper->hi2c = hi2c; |
||||||
|
} |
||||||
|
void I2CHelper_Set_Mode( I2CHelper_TypeDef *i2chelper, I2C_HELPER_MODE_TypeDef mode ) |
||||||
|
{ |
||||||
|
i2chelper->mode = mode; |
||||||
|
} |
||||||
|
void I2CHelper_Set_Trans_Type( I2CHelper_TypeDef *i2chelper, I2C_HELPER_TRANS_TypeDef trans_type ) |
||||||
|
{ |
||||||
|
i2chelper->trans_type = trans_type; |
||||||
|
} |
||||||
|
void I2CHelper_Set_Rcv_Type( I2CHelper_TypeDef *i2chelper, I2C_HELPER_RCV_TypeDef rcv_type ) |
||||||
|
{ |
||||||
|
i2chelper->rcv_type = rcv_type; |
||||||
|
} |
||||||
|
|
||||||
|
int I2CHelper_Set_callback_func_obj( I2CHelper_TypeDef *i2chelper, void * obj, it_callback callback ) |
||||||
|
{ |
||||||
|
i2chelper->obj = obj; |
||||||
|
i2chelper->callback = callback; |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
void I2CHelper_Set_rcv_buf( I2CHelper_TypeDef *i2chelper, uint8_t *buf, uint32_t buf_size ) |
||||||
|
{ |
||||||
|
i2chelper->receive_buf = buf; |
||||||
|
i2chelper->receive_size = buf_size; |
||||||
|
i2chelper->receive_data_con = 0; |
||||||
|
|
||||||
|
} |
||||||
|
void I2CHelper_Set_Trans_Buf( I2CHelper_TypeDef *i2chelper, uint8_t *buf, uint32_t buf_size ) |
||||||
|
{ |
||||||
|
i2chelper->trans_buf = buf; |
||||||
|
i2chelper->trans_size = buf_size; |
||||||
|
i2chelper->trans_data_con = 0; |
||||||
|
} |
||||||
|
|
||||||
|
int I2CHelper_Write( I2CHelper_TypeDef *i2chelper, uint8_t * buf, uint16_t size) |
||||||
|
{ |
||||||
|
// 考虑主从机模式
|
||||||
|
int st = -1; |
||||||
|
switch ( i2chelper->mode == I2C_HELPER_MODE_MASTER ) |
||||||
|
{ |
||||||
|
case I2C_HELPER_MODE_MASTER: |
||||||
|
if ( i2chelper->trans_type == I2C_HELPER_TRANS_POLLING ) |
||||||
|
{ |
||||||
|
st = HAL_I2C_Master_Transmit( i2chelper->hi2c, i2chelper->i2c_write_address |
||||||
|
, buf, size, 0xFFFF ); |
||||||
|
} |
||||||
|
if ( i2chelper->trans_type == I2C_HELPER_TRANS_IT ) |
||||||
|
{ |
||||||
|
// st = HAL_I2C_Master_Transmit_IT( i2chelper->hi2c, i2chelper->i2c_write_address
|
||||||
|
// , buf, size );
|
||||||
|
st = HAL_I2C_Master_Transmit_IT( i2chelper->hi2c, i2chelper->i2c_write_address, buf,size );
|
||||||
|
} |
||||||
|
if ( i2chelper->trans_type == I2C_HELPER_TRANS_DMA ) |
||||||
|
{ |
||||||
|
// st = HAL_I2C_Master_Transmit_DMA( i2chelper->hi2c, i2chelper->i2c_write_address
|
||||||
|
// , buf, size );
|
||||||
|
st = HAL_I2C_Master_Transmit_DMA( i2chelper->hi2c, i2chelper->i2c_write_address, buf, size );
|
||||||
|
} |
||||||
|
break; |
||||||
|
case I2C_HELPER_MODE_SLAVE: |
||||||
|
break;
|
||||||
|
default: |
||||||
|
break; |
||||||
|
} |
||||||
|
return st; |
||||||
|
} |
||||||
|
|
||||||
|
int I2CHelper_Read(I2CHelper_TypeDef *i2chelper, uint8_t * buf, uint16_t size) |
||||||
|
{ |
||||||
|
int st = -1; |
||||||
|
switch ( i2chelper->mode == I2C_HELPER_MODE_MASTER ) |
||||||
|
{ |
||||||
|
case I2C_HELPER_MODE_MASTER: |
||||||
|
if ( i2chelper->rcv_type == I2C_HELPER_TRANS_POLLING ) |
||||||
|
{ |
||||||
|
st = HAL_I2C_Master_Receive( i2chelper->hi2c, i2chelper->i2c_write_address |
||||||
|
, buf, size, 0xFFFF ); |
||||||
|
} |
||||||
|
if ( i2chelper->rcv_type == I2C_HELPER_TRANS_IT ) |
||||||
|
{ |
||||||
|
// st = HAL_I2C_Master_Transmit_IT( i2chelper->hi2c, i2chelper->i2c_write_address
|
||||||
|
// , buf, size );
|
||||||
|
st = HAL_I2C_Master_Receive_IT( i2chelper->hi2c, i2chelper->i2c_write_address |
||||||
|
, buf, size );
|
||||||
|
} |
||||||
|
if ( i2chelper->rcv_type == I2C_HELPER_TRANS_DMA ) |
||||||
|
{ |
||||||
|
// st = HAL_I2C_Master_Transmit_DMA( i2chelper->hi2c, i2chelper->i2c_write_address
|
||||||
|
// , buf, size );
|
||||||
|
st = HAL_I2C_Master_Receive_DMA( i2chelper->hi2c, i2chelper->i2c_write_address |
||||||
|
, buf, size );
|
||||||
|
} |
||||||
|
break; |
||||||
|
case I2C_HELPER_MODE_SLAVE: |
||||||
|
break;
|
||||||
|
default: |
||||||
|
break; |
||||||
|
} |
||||||
|
return st; |
||||||
|
} |
||||||
|
|
||||||
|
int I2CHelper_Flags_Set(I2CHelper_TypeDef *i2chelper, I2C_HELPER_Event_TypeDef evt_type ) |
||||||
|
{ |
||||||
|
return osEventFlagsSet(i2chelper, evt_type); |
||||||
|
} |
||||||
|
|
||||||
|
// int I2CHelper_Flags_Clear(I2CHelper_TypeDef *i2chelper, I2C_HELPER_Event_TypeDef evt_type )
|
||||||
|
// {
|
||||||
|
// return osEventFlagsClear(i2chelper, evt_type);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// int I2CHelper_Flags_Wait(I2CHelper_TypeDef *i2chelper, uint32_t delay )
|
||||||
|
// {
|
||||||
|
// return osEventFlagsWait (
|
||||||
|
// i2chelperEventHandle
|
||||||
|
// , I2C_HELPER_Event_READY|I2C_HELPER_Event_INIT|I2C_HELPER_Event_TRANS_ONLY|I2C_HELPER_Event_DATA_RCV
|
||||||
|
// , 0
|
||||||
|
// , delay );
|
||||||
|
// }
|
||||||
@ -0,0 +1,147 @@ |
|||||||
|
#include "spi_helper.h" |
||||||
|
|
||||||
|
#if 0
|
||||||
|
// static I2C_HandleTypeDef *pADS1115_I2C = &hi2c1;
|
||||||
|
|
||||||
|
// osEventFlagsId_t spihelperEventHandle;
|
||||||
|
// const osEventFlagsAttr_t spihelperEvent_attributes = {
|
||||||
|
// .name = "spihelperEvent"
|
||||||
|
// };
|
||||||
|
|
||||||
|
SPIHelper_TypeDef * SPIHelper_Init( ) |
||||||
|
{ |
||||||
|
SPIHelper_TypeDef *Handle = (SPIHelper_TypeDef *)malloc(sizeof(SPIHelper_TypeDef)); |
||||||
|
if (Handle == NULL) |
||||||
|
{ |
||||||
|
return NULL; |
||||||
|
} |
||||||
|
// Handle->delaytime_trans_byte = 0;
|
||||||
|
return Handle; |
||||||
|
} |
||||||
|
void SPIHelper_Set_hspi( SPIHelper_TypeDef *spihelper, SPI_HandleTypeDef * hspi ) |
||||||
|
{ |
||||||
|
spihelper->hspi = hspi; |
||||||
|
} |
||||||
|
void SPIHelper_Set_Mode( SPIHelper_TypeDef *spihelper, SPI_HELPER_MODE_TypeDef mode ) |
||||||
|
{ |
||||||
|
spihelper->mode = mode; |
||||||
|
} |
||||||
|
void SPIHelper_Set_Trans_Type( SPIHelper_TypeDef *spihelper, SPI_HELPER_TRANS_TypeDef trans_type ) |
||||||
|
{ |
||||||
|
spihelper->trans_type = trans_type; |
||||||
|
} |
||||||
|
void SPIHelper_Set_Rcv_Type( SPIHelper_TypeDef *spihelper, SPI_HELPER_RCV_TypeDef rcv_type ) |
||||||
|
{ |
||||||
|
spihelper->rcv_type = rcv_type; |
||||||
|
} |
||||||
|
|
||||||
|
int SPIHelper_Set_callback_func_obj( SPIHelper_TypeDef *spihelper, void * obj, it_callback callback ) |
||||||
|
{ |
||||||
|
spihelper->obj = obj; |
||||||
|
spihelper->callback = callback; |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
void SPIHelper_Set_rcv_buf( SPIHelper_TypeDef *spihelper, uint8_t *buf, uint32_t buf_size ) |
||||||
|
{ |
||||||
|
spihelper->receive_buf = buf; |
||||||
|
spihelper->receive_size = buf_size; |
||||||
|
spihelper->receive_data_con = 0; |
||||||
|
|
||||||
|
} |
||||||
|
void SPIHelper_Set_Trans_Buf( SPIHelper_TypeDef *spihelper, uint8_t *buf, uint32_t buf_size ) |
||||||
|
{ |
||||||
|
spihelper->trans_buf = buf; |
||||||
|
spihelper->trans_size = buf_size; |
||||||
|
spihelper->trans_data_con = 0; |
||||||
|
} |
||||||
|
|
||||||
|
int SPIHelper_Transmit( SPIHelper_TypeDef *spihelper, uint8_t * buf, uint16_t size) |
||||||
|
{ |
||||||
|
// 考虑主从机模式
|
||||||
|
int st = -1; |
||||||
|
// switch ( spihelper->mode == SPI_HELPER_MODE_MASTER )
|
||||||
|
// {
|
||||||
|
// case SPI_HELPER_MODE_MASTER:
|
||||||
|
// if ( spihelper->trans_type == SPI_HELPER_TRANS_POLLING )
|
||||||
|
// {
|
||||||
|
// st = HAL_I2C_Master_Transmit( spihelper->hi2c, spihelper->i2c_write_address
|
||||||
|
// , buf, size, 0xFFFF );
|
||||||
|
// }
|
||||||
|
// if ( spihelper->trans_type == SPI_HELPER_TRANS_IT )
|
||||||
|
// {
|
||||||
|
// // st = HAL_I2C_Master_Transmit_IT( spihelper->hi2c, spihelper->i2c_write_address
|
||||||
|
// // , buf, size );
|
||||||
|
// st = HAL_I2C_Master_Seq_Transmit_IT( spihelper->hi2c, spihelper->i2c_write_address
|
||||||
|
// , buf, size, I2C_FIRST_FRAME );
|
||||||
|
// }
|
||||||
|
// if ( spihelper->trans_type == SPI_HELPER_TRANS_DMA )
|
||||||
|
// {
|
||||||
|
// // st = HAL_I2C_Master_Transmit_DMA( spihelper->hi2c, spihelper->i2c_write_address
|
||||||
|
// // , buf, size );
|
||||||
|
// st = HAL_I2C_Master_Seq_Transmit_DMA( spihelper->hi2c, spihelper->i2c_write_address
|
||||||
|
// , buf, size, I2C_FIRST_FRAME );
|
||||||
|
|
||||||
|
// }
|
||||||
|
// break;
|
||||||
|
// case SPI_HELPER_MODE_SLAVE:
|
||||||
|
// break;
|
||||||
|
// default:
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
return st; |
||||||
|
} |
||||||
|
int SPIHelper_Begin_Rcv(SPIHelper_TypeDef *spihelper, uint8_t * buf, uint16_t size) |
||||||
|
{ |
||||||
|
int st = -1; |
||||||
|
// switch ( spihelper->mode == SPI_HELPER_MODE_MASTER )
|
||||||
|
// {
|
||||||
|
// case SPI_HELPER_MODE_MASTER:
|
||||||
|
// if ( spihelper->rcv_type == SPI_HELPER_TRANS_POLLING )
|
||||||
|
// {
|
||||||
|
// st = HAL_I2C_Master_Receive( spihelper->hi2c, spihelper->i2c_write_address
|
||||||
|
// , buf, size, 0xFFFF );
|
||||||
|
// }
|
||||||
|
// if ( spihelper->rcv_type == SPI_HELPER_TRANS_IT )
|
||||||
|
// {
|
||||||
|
// // st = HAL_I2C_Master_Transmit_IT( spihelper->hi2c, spihelper->i2c_write_address
|
||||||
|
// // , buf, size );
|
||||||
|
// st = HAL_I2C_Master_Seq_Receive_IT( spihelper->hi2c, spihelper->i2c_write_address
|
||||||
|
// , buf, size, I2C_FIRST_FRAME );
|
||||||
|
// }
|
||||||
|
// if ( spihelper->rcv_type == SPI_HELPER_TRANS_DMA )
|
||||||
|
// {
|
||||||
|
// // st = HAL_I2C_Master_Transmit_DMA( spihelper->hi2c, spihelper->i2c_write_address
|
||||||
|
// // , buf, size );
|
||||||
|
// st = HAL_I2C_Master_Seq_Receive_DMA( spihelper->hi2c, spihelper->i2c_write_address
|
||||||
|
// , buf, size, I2C_FIRST_FRAME );
|
||||||
|
// }
|
||||||
|
// break;
|
||||||
|
// case SPI_HELPER_MODE_SLAVE:
|
||||||
|
// break;
|
||||||
|
// default:
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
return st; |
||||||
|
} |
||||||
|
|
||||||
|
int SPIHelper_Flags_Set(SPIHelper_TypeDef *spihelper, SPI_HELPER_Event_TypeDef evt_type ) |
||||||
|
{ |
||||||
|
return osEventFlagsSet(spihelper, evt_type); |
||||||
|
} |
||||||
|
|
||||||
|
// int SPIHelper_Flags_Clear(SPIHelper_TypeDef *spihelper, SPI_HELPER_Event_TypeDef evt_type )
|
||||||
|
// {
|
||||||
|
// return osEventFlagsClear(spihelper, evt_type);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// int SPIHelper_Flags_Wait(SPIHelper_TypeDef *spihelper, uint32_t delay )
|
||||||
|
// {
|
||||||
|
// return osEventFlagsWait (
|
||||||
|
// spihelperEventHandle
|
||||||
|
// , SPI_HELPER_Event_READY|SPI_HELPER_Event_INIT|SPI_HELPER_Event_TRANS_ONLY|SPI_HELPER_Event_DATA_RCV
|
||||||
|
// , 0
|
||||||
|
// , delay );
|
||||||
|
// }
|
||||||
|
|
||||||
|
#endif |
||||||
@ -0,0 +1,315 @@ |
|||||||
|
#include "uart_helper.h" |
||||||
|
#include "elog.h" |
||||||
|
|
||||||
|
|
||||||
|
UartHelper_TypeDef * UartHelper_Init( ) |
||||||
|
{ |
||||||
|
UartHelper_TypeDef *Handle = (UartHelper_TypeDef *)malloc(sizeof(UartHelper_TypeDef)); |
||||||
|
if (Handle == NULL) |
||||||
|
{ |
||||||
|
return NULL; |
||||||
|
} |
||||||
|
|
||||||
|
// Handle->interface = UartInterface_Init();
|
||||||
|
Handle->interface = UartInterface_Init(); |
||||||
|
// Handle->interface_type = 0;
|
||||||
|
|
||||||
|
Handle->interface_type = 0; /* 0: common, 1: 485 ,2:3160*/ |
||||||
|
Handle->mode_232_485 = 0; /* 0: common, 1: 485 */ |
||||||
|
Handle->trans_type = 2; /* 0 :polling, 1: IT 2: DMA*/ |
||||||
|
Handle->rcv_type = 2; /* 0 :polling, 1: IT 2: DMA*/ |
||||||
|
Handle->idle_enable_disable = 1; /* 0 不开启空闲中断 , 1 开启空闲中断 */ |
||||||
|
Handle->trans_mode = 2; /* 0 :polling, 1: IT 2: DMA*/ |
||||||
|
Handle->status = Uart_Status_Ready; /* 0 :polling, 1: IT 2: DMA*/ |
||||||
|
Handle->huart = NULL;
|
||||||
|
Handle->obj = NULL;
|
||||||
|
Handle->callback = NULL;
|
||||||
|
// Handle->timeout_enable = 0;
|
||||||
|
// Handle->timeout_ms = 0;
|
||||||
|
// Handle->timebase_ticks = 0;
|
||||||
|
return Handle; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
void UartHelper_Set_Interface( UartHelper_TypeDef *uarthelper, UartInterface_TypeDef * interface ) |
||||||
|
{ |
||||||
|
uarthelper->interface = interface; |
||||||
|
} |
||||||
|
void UartHelper_Set_Huart( UartHelper_TypeDef *uarthelper, UART_HandleTypeDef * huart ) |
||||||
|
{ |
||||||
|
uarthelper->huart = huart; |
||||||
|
} |
||||||
|
void UartHelper_Set_Interface_Type( UartHelper_TypeDef *uarthelper, Uart_Interface_Type_Typedef interface_type ) |
||||||
|
{ |
||||||
|
uarthelper->interface_type = interface_type; |
||||||
|
} |
||||||
|
void UartHelper_Set_Trans_Type( UartHelper_TypeDef *uarthelper, Uart_Transmode_TypeDef trans_type ) |
||||||
|
{ |
||||||
|
uarthelper->trans_type = trans_type; |
||||||
|
} |
||||||
|
void UartHelper_Set_Rcv_Type( UartHelper_TypeDef *uarthelper, Uart_Transmode_TypeDef rcv_type ) |
||||||
|
{ |
||||||
|
uarthelper->rcv_type = rcv_type; |
||||||
|
} |
||||||
|
void UartHelper_Set_Idle_Enable( UartHelper_TypeDef *uarthelper, Uart_IDLE_Enable_TypeDef idle_enable_disable ) |
||||||
|
{ |
||||||
|
uarthelper->idle_enable_disable = idle_enable_disable; |
||||||
|
} |
||||||
|
void UartHelper_Set_TransMode( UartHelper_TypeDef *uarthelper, Uart_Transmode_TypeDef trans_mode ) |
||||||
|
{ |
||||||
|
uarthelper->trans_mode = trans_mode; |
||||||
|
} |
||||||
|
void UartHelper_Set_RsMode_232_485( UartHelper_TypeDef *uarthelper, Uart_RS_Mode_TypeDef mode_232_485 ) |
||||||
|
{ |
||||||
|
uarthelper->mode_232_485 = mode_232_485; |
||||||
|
UartInterface_Setup_Mode_232_485( uarthelper->interface, uarthelper->mode_232_485); |
||||||
|
} |
||||||
|
|
||||||
|
// void UartHelper_Set_timeout( UartHelper_TypeDef *uarthelper, uint32_t timeout_ms )
|
||||||
|
// {
|
||||||
|
// uarthelper->timeout_ms = timeout_ms;
|
||||||
|
// uarthelper->timeout_enable = 1;
|
||||||
|
// }
|
||||||
|
|
||||||
|
int UartHelper_Set_callback_func_obj( UartHelper_TypeDef *uarthelper, void * obj, it_callback callback ) |
||||||
|
{ |
||||||
|
if(uarthelper==NULL || callback==NULL || obj==NULL){ |
||||||
|
return -1; |
||||||
|
} |
||||||
|
uarthelper->callback =callback; |
||||||
|
uarthelper->obj =obj; |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
void UartHelper_Set_rcv_buf( UartHelper_TypeDef *uarthelper, uint8_t *buf, uint32_t buf_size ) |
||||||
|
{ |
||||||
|
uarthelper->receive_buf = buf; |
||||||
|
uarthelper->receive_buf_half_len = buf_size/2; |
||||||
|
} |
||||||
|
|
||||||
|
void UartHelper_Set_Trans_Buf( UartHelper_TypeDef *uarthelper, uint8_t *buf, uint32_t buf_size ) |
||||||
|
{ |
||||||
|
uarthelper->trans_buf = buf; |
||||||
|
uarthelper->trans_size = buf_size; |
||||||
|
} |
||||||
|
|
||||||
|
int UartHelper_Transmit( UartHelper_TypeDef *uarthelper, uint8_t * buf, uint16_t size) |
||||||
|
{ |
||||||
|
// log_i( "SensorSend size_ " );
|
||||||
|
// set gpio
|
||||||
|
UartInterface_Set_GPIO_For_Transmit( uarthelper->interface ); |
||||||
|
// it idle start
|
||||||
|
// if ( uarthelper->idle_enable_disable == 1 )
|
||||||
|
// {
|
||||||
|
// log_i( "start idle .... ");
|
||||||
|
// __HAL_UART_ENABLE_IT(uarthelper->huart, UART_IT_IDLE);
|
||||||
|
// }
|
||||||
|
|
||||||
|
/* 开启 transmit */ |
||||||
|
if (buf!=NULL ) |
||||||
|
{ |
||||||
|
uarthelper->status = Uart_Status_Sending; |
||||||
|
if ( uarthelper->trans_type == 0 ) |
||||||
|
return HAL_UART_Transmit( uarthelper->huart, buf, size ,0x0FFF); |
||||||
|
if ( uarthelper->trans_type == 1 ) |
||||||
|
return HAL_UART_Transmit_IT( uarthelper->huart, buf, size ); |
||||||
|
if ( uarthelper->trans_type == 2 ) |
||||||
|
return HAL_UART_Transmit_DMA( uarthelper->huart, buf, size ); |
||||||
|
} |
||||||
|
if (buf==NULL && uarthelper->trans_buf !=NULL) |
||||||
|
{ |
||||||
|
uarthelper->status = Uart_Status_Sending; |
||||||
|
|
||||||
|
if ( uarthelper->trans_type == 0 ) |
||||||
|
return HAL_UART_Transmit( uarthelper->huart, uarthelper->trans_buf, uarthelper->trans_size ,0x0FFF); |
||||||
|
if ( uarthelper->trans_type == 1 ) |
||||||
|
return HAL_UART_Transmit_IT( uarthelper->huart, uarthelper->trans_buf, uarthelper->trans_size); |
||||||
|
if ( uarthelper->trans_type == 2 ) |
||||||
|
return HAL_UART_Transmit_DMA( uarthelper->huart, uarthelper->trans_buf, uarthelper->trans_size); |
||||||
|
} |
||||||
|
return -1; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
int UartHelper_Begin_Rcv(UartHelper_TypeDef *uarthelper, uint8_t * buf, uint16_t size) |
||||||
|
{ |
||||||
|
/* 是否开启空闲中断*/ |
||||||
|
if ( uarthelper->idle_enable_disable == 1 ) |
||||||
|
{ |
||||||
|
__HAL_UART_ENABLE_IT( uarthelper->huart, UART_IT_IDLE ); |
||||||
|
} |
||||||
|
|
||||||
|
if ( uarthelper->rcv_type == 0 ) |
||||||
|
{ |
||||||
|
// TODO 发生错误怎么处理
|
||||||
|
HAL_UART_Receive( uarthelper->huart, buf, size ,0X0FFF); |
||||||
|
} |
||||||
|
|
||||||
|
if ( uarthelper->rcv_type == 1 ) |
||||||
|
{ |
||||||
|
HAL_UART_Receive_IT( uarthelper->huart, buf, size); |
||||||
|
} |
||||||
|
|
||||||
|
if ( uarthelper->rcv_type == 2 ) |
||||||
|
{ |
||||||
|
// log_i( "start dma rcv.... . ");
|
||||||
|
HAL_UART_Receive_DMA( uarthelper->huart, buf, size); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
void UartHelper_Set_GPIO_For_Trans_Cplt( UartHelper_TypeDef *uarthelper ) |
||||||
|
{ |
||||||
|
uarthelper->status = Uart_Status_Ready; |
||||||
|
// log_i(" UartHelper_Set_GPIO_For_Trans_Cplt ... %d %d", uarthelper->interface_type, uarthelper->mode_232_485);
|
||||||
|
if (uarthelper->interface_type != Uart_Interface_Default && uarthelper->mode_232_485 ==Uart_RSMODE_485) |
||||||
|
{ |
||||||
|
// log_i(" UartHelper_Set_GPIO_For_Trans_Cplt ... 111111");
|
||||||
|
UartHelper_Set_GPIO_For_Trans_Cplt( uarthelper->interface ); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void UartHelper_Rcv_Cplt_Callback( UartHelper_TypeDef *uarthelper ) |
||||||
|
{ |
||||||
|
// TODO 超时 --> 尽量用空闲中断代替 接收指定长度完成中断
|
||||||
|
|
||||||
|
// TODO 拷贝数据
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
void UartHelper_Rcv_Idle_Callback( UartHelper_TypeDef *uarthelper ) |
||||||
|
{ |
||||||
|
/* 搬运 数据到 kfifo*/ |
||||||
|
|
||||||
|
log_i("SC6....huart3 IDLE...."); |
||||||
|
|
||||||
|
uint16_t count = __HAL_DMA_GET_COUNTER( uarthelper->huart->hdmarx ); |
||||||
|
uint16_t data_length = 2*uarthelper->receive_data_size - count;
|
||||||
|
|
||||||
|
// if (count != 0 && data_length != 0)
|
||||||
|
if ( data_length != 0 ) |
||||||
|
{ |
||||||
|
// TODO 拷贝数据 最后一位 datalenth-1
|
||||||
|
HAL_UART_DMAStop( uarthelper->huart ); |
||||||
|
uarthelper->callback( uarthelper->obj, uarthelper->receive_buf, data_length); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
void UartHelper_Rcv_DMA_Half_Callback( UartHelper_TypeDef *uarthelper ) |
||||||
|
{ |
||||||
|
/* 循环模式才有 半满中断 */ |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
int UartHelper_copy(UartHelper_TypeDef *uarthelper,uint8_t *buf,uint32_t buf_size) |
||||||
|
{ |
||||||
|
int data_len; |
||||||
|
if(uarthelper==NULL || buf==NULL){ |
||||||
|
return -1; |
||||||
|
} |
||||||
|
data_len = uarthelper->receive_data_size; |
||||||
|
if(buf_size<data_len){ |
||||||
|
return -2; |
||||||
|
} |
||||||
|
if(data_len!=0){ |
||||||
|
// TODO
|
||||||
|
// memcpy(buf,uart_get_receive_buff(uart_buf),data_len);
|
||||||
|
uarthelper->receive_data_size=0; |
||||||
|
} |
||||||
|
return data_len; |
||||||
|
|
||||||
|
} |
||||||
|
int UartHelper_isbusy(UartHelper_TypeDef *uarthelper ) |
||||||
|
{ |
||||||
|
if (uarthelper->status==Uart_Status_Sending) |
||||||
|
return 1; |
||||||
|
return 0; |
||||||
|
} |
||||||
|
void UartHelper_error(UartHelper_TypeDef *uarthelper ) |
||||||
|
{ |
||||||
|
while(1);
|
||||||
|
} |
||||||
|
|
||||||
|
uint16_t Get_Crc16(const char *buf, uint16_t len) |
||||||
|
{ |
||||||
|
int crc = 0xffff; |
||||||
|
for (int i = 0; i < len; i++) |
||||||
|
{ |
||||||
|
crc ^= buf[i]; |
||||||
|
for (int j = 0; j < 8; j++) |
||||||
|
{ |
||||||
|
if (crc & 1 == 1) |
||||||
|
{ |
||||||
|
crc >>= 1; |
||||||
|
crc ^= 0xa001; |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
crc >>= 1; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
uint8_t cs1 = crc & 0xff; // 校验码的低字节
|
||||||
|
uint8_t cs2 = (crc & 0xff00) >> 8; // 校验码的高字节
|
||||||
|
return crc; |
||||||
|
}; |
||||||
|
|
||||||
|
|
||||||
|
uint8_t Check_Crc16(uint8_t *buf, uint16_t length){
|
||||||
|
uint16_t len = length-2; |
||||||
|
int crc = 0xffff; |
||||||
|
for (int i = 0; i < len; i++) |
||||||
|
{ |
||||||
|
crc ^= buf[i]; |
||||||
|
for (int j = 0; j < 8; j++) |
||||||
|
{ |
||||||
|
if (crc & 1 == 1) |
||||||
|
{ |
||||||
|
crc >>= 1; |
||||||
|
crc ^= 0xa001; |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
crc >>= 1; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
uint8_t cs1 = crc & 0xff; // 校验码的低字节
|
||||||
|
uint8_t cs2 = (crc & 0xff00) >> 8; // 校验码的高字节
|
||||||
|
log_i( " %d %d %d ",crc ,cs1, cs2 ) ; |
||||||
|
log_i( " %d %d %d ",crc ,buf[length-2], buf[length-1] ) ; |
||||||
|
|
||||||
|
if ( (crc & 0xff) == buf[length-2] && ((crc & 0xff00) >> 8) == buf[length-1]) |
||||||
|
{ |
||||||
|
return 1; |
||||||
|
} |
||||||
|
else
|
||||||
|
{ |
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
// // HAL_UART_DMAStop HAL_UART_Receive_DMA 成对使用,可从指定指针开始
|
||||||
|
// // HAL_UART_DMAPause HAL_UART_DMAResume 成对使用
|
||||||
|
// HAL_UART_DMAStop( sc6->huart );
|
||||||
|
// memcpy(sc6->SC6_Data_Buf, sc6->SC6_Raw_Buf, data_length);
|
||||||
|
// sc6->size_received = data_length;
|
||||||
|
// log_i(" IDLE.... count %d data_length %d ",count,data_length );
|
||||||
|
// log_i(" IDLE.... -> %02X %02X %02X %02X ", sc6->SC6_Data_Buf[0] , sc6->SC6_Data_Buf[1], sc6->SC6_Data_Buf[2] , sc6->SC6_Data_Buf[3]);
|
||||||
|
// log_i(" IDLE.... -> %02X %02X %02X %02X ",
|
||||||
|
// sc6->SC6_Data_Buf[data_length] , sc6->SC6_Data_Buf[data_length-1], sc6->SC6_Data_Buf[data_length-2] , sc6->SC6_Data_Buf[data_length-3]);
|
||||||
|
// log_i(" IDLE.... -> %s ", sc6->SC6_Data_Buf );
|
||||||
|
// // TODO数据清零 DMA指针指向开始的地方 或双缓冲
|
||||||
|
// // memset(sc6->SC6_Data_Buf, 0, sizeof(sc6->SC6_Data_Buf));
|
||||||
|
// memset(sc6->SC6_Raw_Buf, 0, sizeof(sc6->SC6_Raw_Buf));
|
||||||
|
// // HAL_UART_DMAStop( sc6->myuart->huart );
|
||||||
|
// // SC6_Begin_Rcv( sc6, sc6->SC6_Raw_Buf, sizeof(sc6->SC6_Raw_Buf));
|
||||||
|
// __HAL_UART_ENABLE_IT( sc6->huart, UART_IT_IDLE);
|
||||||
|
// HAL_UART_Receive_DMA( sc6->huart, sc6->SC6_Raw_Buf, sizeof(sc6->SC6_Raw_Buf));
|
||||||
|
// // HAL_UART_DMAResume( sc6->myuart->huart );
|
||||||
|
|
||||||
|
/* 再次开启DMA接收 重新接收 */ |
||||||
|
// HAL_UART_Receive_DMA(&UartHandle, UartHandle.pRxBuffPtr, UartHandle.RxXferSize);
|
||||||
@ -0,0 +1,241 @@ |
|||||||
|
#include "uart_interface.h" |
||||||
|
#include "elog.h" |
||||||
|
|
||||||
|
UartInterface_TypeDef * UartInterface_Init( ) |
||||||
|
{ |
||||||
|
UartInterface_TypeDef *Handle = (UartInterface_TypeDef *)malloc(sizeof(UartInterface_TypeDef)); |
||||||
|
if (Handle == NULL) |
||||||
|
{ |
||||||
|
return NULL; |
||||||
|
} |
||||||
|
|
||||||
|
// Handle->send_status = 0;
|
||||||
|
Handle->interface_type = 0; |
||||||
|
|
||||||
|
#if MAX485_ENABLE |
||||||
|
Handle->de485_gpio = NULL; |
||||||
|
Handle->interface_type = 1; |
||||||
|
#endif |
||||||
|
|
||||||
|
#if MAX3160_ENABLE |
||||||
|
Handle->de485_gpio = NULL; |
||||||
|
Handle->sel_gpio = NULL; |
||||||
|
Handle->dplx_gpio = NULL; |
||||||
|
Handle->interface_type = 2; |
||||||
|
#endif |
||||||
|
|
||||||
|
return Handle; |
||||||
|
} |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief interface-> 0:default, 1:485, 2:3160
|
||||||
|
* @param [in] myuart
|
||||||
|
* @param [in] interface
|
||||||
|
* @return int
|
||||||
|
*
|
||||||
|
* @details
|
||||||
|
*/ |
||||||
|
int UartInterface_Setup_Interface_type( UartInterface_TypeDef * interface, Uart_Interface_Type_Typedef interface_type ) |
||||||
|
{ |
||||||
|
interface->interface_type = interface_type; |
||||||
|
return 0;
|
||||||
|
} |
||||||
|
|
||||||
|
int UartInterface_Setup_Mode_232_485( UartInterface_TypeDef * interface, Uart_RS_Mode_TypeDef mode_232_485 ) |
||||||
|
{ |
||||||
|
interface->mode_232_485 = mode_232_485; |
||||||
|
if (interface->interface_type == 0) |
||||||
|
UartInterface_Set_232( interface); |
||||||
|
if (interface->interface_type == 1) |
||||||
|
UartInterface_Set_485( interface); |
||||||
|
if (interface->interface_type ==2 && interface->mode_232_485 ==Uart_RSMODE_232) |
||||||
|
UartInterface_Set_232( interface); |
||||||
|
if (interface->interface_type ==2 && interface->mode_232_485 ==Uart_RSMODE_485) |
||||||
|
UartInterface_Set_485( interface); |
||||||
|
|
||||||
|
return 0;
|
||||||
|
} |
||||||
|
void UartInterface_Set_Sel_GPIO_Pin(UartInterface_TypeDef * interface, GPIO_TypeDef *gpio, uint16_t pin) |
||||||
|
{ |
||||||
|
if (gpio!=NULL && pin>=0) |
||||||
|
{ |
||||||
|
#if MAX3160_ENABLE |
||||||
|
interface->sel_gpio = gpio; |
||||||
|
interface->sel_pin = pin;
|
||||||
|
#endif |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
void UartInterface_Set_Dplx_GPIO_Pin(UartInterface_TypeDef * interface, GPIO_TypeDef *gpio, uint16_t pin) |
||||||
|
{ |
||||||
|
if (gpio!=NULL && pin>=0) |
||||||
|
{ |
||||||
|
#if MAX3160_ENABLE |
||||||
|
interface->dplx_gpio = gpio; |
||||||
|
interface->dplx_pin = pin;
|
||||||
|
#endif |
||||||
|
} |
||||||
|
// #if MAX3160_ENABLE
|
||||||
|
// interface->dplx_gpio = gpio;
|
||||||
|
// interface->dplx_pin = pin;
|
||||||
|
// #endif
|
||||||
|
} |
||||||
|
|
||||||
|
void UartInterface_Set_DE485_GPIO_Pin(UartInterface_TypeDef * interface, GPIO_TypeDef *gpio, uint16_t pin) |
||||||
|
{ |
||||||
|
if (gpio!=NULL && pin>=0) |
||||||
|
{ |
||||||
|
#if MAX3160_ENABLE |
||||||
|
interface->de485_gpio = gpio; |
||||||
|
interface->de485_pin = pin;
|
||||||
|
#endif |
||||||
|
#if MAX485_ENABLE |
||||||
|
interface->de485_gpio = gpio; |
||||||
|
interface->de485_pin = pin;
|
||||||
|
#endif |
||||||
|
} |
||||||
|
// interface->de485_gpio = gpio;
|
||||||
|
// interface->de485_pin = pin;
|
||||||
|
} |
||||||
|
|
||||||
|
void UartInterface_Set_232(UartInterface_TypeDef * interface) |
||||||
|
{ |
||||||
|
interface->mode_232_485 = Uart_RSMODE_232; |
||||||
|
#if MAX3160_ENABLE |
||||||
|
if (interface->sel_gpio != NULL) |
||||||
|
HAL_GPIO_WritePin(interface->dplx_gpio, interface->dplx_pin , DUPLEX_FULL); |
||||||
|
interface->sel = SEL_232; |
||||||
|
if (interface->sel_gpio != NULL) |
||||||
|
HAL_GPIO_WritePin( interface->sel_gpio, interface->sel_pin, interface->sel ); |
||||||
|
#endif |
||||||
|
// interface->mode_232_485 = 0;
|
||||||
|
} |
||||||
|
|
||||||
|
void UartInterface_Set_485(UartInterface_TypeDef * interface) |
||||||
|
{ |
||||||
|
interface->mode_232_485 = Uart_RSMODE_485; |
||||||
|
|
||||||
|
// log_i(".......set 485 ");
|
||||||
|
|
||||||
|
#if MAX3160_ENABLE |
||||||
|
interface->sel = SEL_485; |
||||||
|
if (interface->sel_gpio != NULL) |
||||||
|
// log_i(".......set 485 set dplx ");
|
||||||
|
HAL_GPIO_WritePin(interface->dplx_gpio, interface->dplx_pin , DUPLEX_HALF); |
||||||
|
if (interface->de485_gpio != NULL) |
||||||
|
// log_i(".......set 485 set de ");
|
||||||
|
HAL_GPIO_WritePin( interface->de485_gpio, interface->de485_pin, DISABLE_485_SEND ); |
||||||
|
if (interface->sel_gpio != NULL) |
||||||
|
// log_i(".......set 485 set sel... ");
|
||||||
|
HAL_GPIO_WritePin( interface->sel_gpio, interface->sel_pin, interface->sel ); |
||||||
|
// log_i(" UartInterface_Set_485 222 interface->sel : %d duplex: %d ",interface->sel , HAL_GPIO_ReadPin(interface->dplx_gpio,interface->dplx_pin) );
|
||||||
|
#endif |
||||||
|
|
||||||
|
#if MAX485_ENABLE |
||||||
|
if (interface->de485_gpio != NULL) |
||||||
|
// log_i(".......set 485 set de ");
|
||||||
|
HAL_GPIO_WritePin( interface->de485_gpio, interface->de485_pin, DISABLE_485_SEND ); |
||||||
|
|
||||||
|
#endif |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 发送前操作 GPIO |
||||||
|
* @param [in] myuart
|
||||||
|
* @return int
|
||||||
|
*
|
||||||
|
* @details
|
||||||
|
*/ |
||||||
|
int UartInterface_Set_GPIO_For_Transmit( UartInterface_TypeDef * interface ) |
||||||
|
// int UartInterface_Send_TxPrepare_Callback( UartInterface_TypeDef * interface )
|
||||||
|
{ |
||||||
|
#if MAX3160_ENABLE |
||||||
|
if (interface->mode_232_485 == 0)
|
||||||
|
{ |
||||||
|
HAL_GPIO_WritePin(interface->dplx_gpio, interface->dplx_pin , DUPLEX_FULL); |
||||||
|
|
||||||
|
}; |
||||||
|
if ( interface->interface_type == 2 && interface->mode_232_485 == 1 ) |
||||||
|
{ |
||||||
|
// log_i( " ---- UartInterface_Set_GPIO_For_Transmit " );
|
||||||
|
HAL_GPIO_WritePin(interface->dplx_gpio, interface->dplx_pin , DUPLEX_FULL); // 全双工启动发送
|
||||||
|
HAL_GPIO_WritePin(interface->de485_gpio, interface->de485_pin, ENABLE_485_SEND);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif |
||||||
|
#if MAX485_ENABLE |
||||||
|
if (interface->interface_type == 1) |
||||||
|
{ |
||||||
|
HAL_GPIO_WritePin(interface->de485_gpio, interface->de485_pin, ENABLE_485_SEND);
|
||||||
|
} |
||||||
|
#endif |
||||||
|
return 0; |
||||||
|
|
||||||
|
// #if MAX3160_ENABLE
|
||||||
|
// if (interface->interface_type == 2 && )
|
||||||
|
// {
|
||||||
|
// switch (interface->sel)
|
||||||
|
// {
|
||||||
|
// case SEL_232:
|
||||||
|
// HAL_GPIO_WritePin(interface->dplx_gpio, interface->dplx_pin , DUPLEX_FULL);
|
||||||
|
// // return __UartInterface_Send(myuart,buf,size);
|
||||||
|
// break;
|
||||||
|
// case SEL_485:
|
||||||
|
// log_i(" 485 mode writepin...... ");
|
||||||
|
// HAL_GPIO_WritePin(interface->dplx_gpio, interface->dplx_pin , DUPLEX_FULL);
|
||||||
|
// HAL_GPIO_WritePin( interface->de485_gpio, interface->de485_pin, ENABLE_485_SEND);
|
||||||
|
// // return __UartInterface_Send(myuart,buf,size);
|
||||||
|
// break;
|
||||||
|
// default:
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
// #if MAX485_ENABLE
|
||||||
|
// if (interface->interface_type == 1)
|
||||||
|
// {
|
||||||
|
// HAL_GPIO_WritePin(interface->dplx_gpio, interface->dplx_pin , DUPLEX_FULL);
|
||||||
|
// HAL_GPIO_WritePin( interface->de485_gpio, interface->de485_pin, ENABLE_485_SEND); // return __Max3160_Send(max3160,buf,size);
|
||||||
|
// }
|
||||||
|
// #endif
|
||||||
|
} |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 发送完成后操作 GPIO |
||||||
|
* @param [in] myuart
|
||||||
|
* @return int
|
||||||
|
*
|
||||||
|
* @details
|
||||||
|
*/ |
||||||
|
// 接收完成,切换到接收状态, 全双工接收
|
||||||
|
int UartInterface_Set_GPIO_For_Trans_Cplt( UartInterface_TypeDef * interface ) |
||||||
|
{ |
||||||
|
// interface->send_status = 0;
|
||||||
|
|
||||||
|
#if MAX3160_ENABLE |
||||||
|
if ( interface->interface_type == 2 && interface->mode_232_485 == 1) |
||||||
|
{ |
||||||
|
HAL_GPIO_WritePin(interface->dplx_gpio, interface->dplx_pin , DUPLEX_HALF); // 半双工接收
|
||||||
|
HAL_GPIO_WritePin(interface->de485_gpio, interface->de485_pin, DISABLE_485_SEND);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (interface->mode_232_485 == 0) return -1; |
||||||
|
#endif |
||||||
|
#if MAX485_ENABLE |
||||||
|
if (interface->interface_type == 1) |
||||||
|
{ |
||||||
|
HAL_GPIO_WritePin(interface->de485_gpio, interface->de485_pin, DISABLE_485_SEND);
|
||||||
|
return 0; |
||||||
|
} |
||||||
|
if (interface->mode_232_485 == 0) return -1; |
||||||
|
#endif |
||||||
|
|
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
@ -0,0 +1,55 @@ |
|||||||
|
/* USER CODE BEGIN Header */ |
||||||
|
/**
|
||||||
|
****************************************************************************** |
||||||
|
* @file usb_otg.h |
||||||
|
* @brief This file contains all the function prototypes for |
||||||
|
* the usb_otg.c file |
||||||
|
****************************************************************************** |
||||||
|
* @attention |
||||||
|
* |
||||||
|
* Copyright (c) 2023 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 */ |
||||||
|
/* Define to prevent recursive inclusion -------------------------------------*/ |
||||||
|
#ifndef __USB_OTG_H__ |
||||||
|
#define __USB_OTG_H__ |
||||||
|
|
||||||
|
#ifdef __cplusplus |
||||||
|
extern "C" { |
||||||
|
#endif |
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/ |
||||||
|
#include "main.h" |
||||||
|
|
||||||
|
/* USER CODE BEGIN Includes */ |
||||||
|
|
||||||
|
/* USER CODE END Includes */ |
||||||
|
|
||||||
|
extern PCD_HandleTypeDef hpcd_USB_OTG_FS; |
||||||
|
|
||||||
|
extern PCD_HandleTypeDef hpcd_USB_OTG_HS; |
||||||
|
|
||||||
|
/* USER CODE BEGIN Private defines */ |
||||||
|
|
||||||
|
/* USER CODE END Private defines */ |
||||||
|
|
||||||
|
void MX_USB_OTG_FS_PCD_Init(void); |
||||||
|
void MX_USB_OTG_HS_PCD_Init(void); |
||||||
|
|
||||||
|
/* USER CODE BEGIN Prototypes */ |
||||||
|
|
||||||
|
/* USER CODE END Prototypes */ |
||||||
|
|
||||||
|
#ifdef __cplusplus |
||||||
|
} |
||||||
|
#endif |
||||||
|
|
||||||
|
#endif /* __USB_OTG_H__ */ |
||||||
|
|
||||||
@ -0,0 +1,191 @@ |
|||||||
|
/* USER CODE BEGIN Header */ |
||||||
|
/**
|
||||||
|
****************************************************************************** |
||||||
|
* @file usb_otg.c |
||||||
|
* @brief This file provides code for the configuration |
||||||
|
* of the USB_OTG instances. |
||||||
|
****************************************************************************** |
||||||
|
* @attention |
||||||
|
* |
||||||
|
* Copyright (c) 2023 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 "usb_otg.h" |
||||||
|
|
||||||
|
/* USER CODE BEGIN 0 */ |
||||||
|
|
||||||
|
/* USER CODE END 0 */ |
||||||
|
|
||||||
|
PCD_HandleTypeDef hpcd_USB_OTG_FS; |
||||||
|
PCD_HandleTypeDef hpcd_USB_OTG_HS; |
||||||
|
|
||||||
|
/* USB_OTG_FS init function */ |
||||||
|
|
||||||
|
void MX_USB_OTG_FS_PCD_Init(void) |
||||||
|
{ |
||||||
|
|
||||||
|
/* USER CODE BEGIN USB_OTG_FS_Init 0 */ |
||||||
|
|
||||||
|
/* USER CODE END USB_OTG_FS_Init 0 */ |
||||||
|
|
||||||
|
/* USER CODE BEGIN USB_OTG_FS_Init 1 */ |
||||||
|
|
||||||
|
/* USER CODE END USB_OTG_FS_Init 1 */ |
||||||
|
hpcd_USB_OTG_FS.Instance = USB_OTG_FS; |
||||||
|
hpcd_USB_OTG_FS.Init.dev_endpoints = 4; |
||||||
|
hpcd_USB_OTG_FS.Init.speed = PCD_SPEED_FULL; |
||||||
|
hpcd_USB_OTG_FS.Init.dma_enable = DISABLE; |
||||||
|
hpcd_USB_OTG_FS.Init.phy_itface = PCD_PHY_EMBEDDED; |
||||||
|
hpcd_USB_OTG_FS.Init.Sof_enable = DISABLE; |
||||||
|
hpcd_USB_OTG_FS.Init.low_power_enable = DISABLE; |
||||||
|
hpcd_USB_OTG_FS.Init.lpm_enable = DISABLE; |
||||||
|
hpcd_USB_OTG_FS.Init.vbus_sensing_enable = DISABLE; |
||||||
|
hpcd_USB_OTG_FS.Init.use_dedicated_ep1 = DISABLE; |
||||||
|
if (HAL_PCD_Init(&hpcd_USB_OTG_FS) != HAL_OK) |
||||||
|
{ |
||||||
|
Error_Handler(); |
||||||
|
} |
||||||
|
/* USER CODE BEGIN USB_OTG_FS_Init 2 */ |
||||||
|
|
||||||
|
/* USER CODE END USB_OTG_FS_Init 2 */ |
||||||
|
|
||||||
|
} |
||||||
|
/* USB_OTG_HS init function */ |
||||||
|
|
||||||
|
void MX_USB_OTG_HS_PCD_Init(void) |
||||||
|
{ |
||||||
|
|
||||||
|
/* USER CODE BEGIN USB_OTG_HS_Init 0 */ |
||||||
|
|
||||||
|
/* USER CODE END USB_OTG_HS_Init 0 */ |
||||||
|
|
||||||
|
/* USER CODE BEGIN USB_OTG_HS_Init 1 */ |
||||||
|
|
||||||
|
/* USER CODE END USB_OTG_HS_Init 1 */ |
||||||
|
hpcd_USB_OTG_HS.Instance = USB_OTG_HS; |
||||||
|
hpcd_USB_OTG_HS.Init.dev_endpoints = 6; |
||||||
|
hpcd_USB_OTG_HS.Init.speed = PCD_SPEED_FULL; |
||||||
|
hpcd_USB_OTG_HS.Init.dma_enable = DISABLE; |
||||||
|
hpcd_USB_OTG_HS.Init.phy_itface = USB_OTG_EMBEDDED_PHY; |
||||||
|
hpcd_USB_OTG_HS.Init.Sof_enable = DISABLE; |
||||||
|
hpcd_USB_OTG_HS.Init.low_power_enable = DISABLE; |
||||||
|
hpcd_USB_OTG_HS.Init.lpm_enable = DISABLE; |
||||||
|
hpcd_USB_OTG_HS.Init.vbus_sensing_enable = DISABLE; |
||||||
|
hpcd_USB_OTG_HS.Init.use_dedicated_ep1 = DISABLE; |
||||||
|
hpcd_USB_OTG_HS.Init.use_external_vbus = DISABLE; |
||||||
|
if (HAL_PCD_Init(&hpcd_USB_OTG_HS) != HAL_OK) |
||||||
|
{ |
||||||
|
Error_Handler(); |
||||||
|
} |
||||||
|
/* USER CODE BEGIN USB_OTG_HS_Init 2 */ |
||||||
|
|
||||||
|
/* USER CODE END USB_OTG_HS_Init 2 */ |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle) |
||||||
|
{ |
||||||
|
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct = {0}; |
||||||
|
if(pcdHandle->Instance==USB_OTG_FS) |
||||||
|
{ |
||||||
|
/* USER CODE BEGIN USB_OTG_FS_MspInit 0 */ |
||||||
|
|
||||||
|
/* USER CODE END USB_OTG_FS_MspInit 0 */ |
||||||
|
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE(); |
||||||
|
/**USB_OTG_FS GPIO Configuration
|
||||||
|
PA11 ------> USB_OTG_FS_DM |
||||||
|
PA12 ------> USB_OTG_FS_DP |
||||||
|
*/ |
||||||
|
GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12; |
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL; |
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; |
||||||
|
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS; |
||||||
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
||||||
|
|
||||||
|
/* USB_OTG_FS clock enable */ |
||||||
|
__HAL_RCC_USB_OTG_FS_CLK_ENABLE(); |
||||||
|
/* USER CODE BEGIN USB_OTG_FS_MspInit 1 */ |
||||||
|
|
||||||
|
/* USER CODE END USB_OTG_FS_MspInit 1 */ |
||||||
|
} |
||||||
|
else if(pcdHandle->Instance==USB_OTG_HS) |
||||||
|
{ |
||||||
|
/* USER CODE BEGIN USB_OTG_HS_MspInit 0 */ |
||||||
|
|
||||||
|
/* USER CODE END USB_OTG_HS_MspInit 0 */ |
||||||
|
|
||||||
|
__HAL_RCC_GPIOB_CLK_ENABLE(); |
||||||
|
/**USB_OTG_HS GPIO Configuration
|
||||||
|
PB14 ------> USB_OTG_HS_DM |
||||||
|
PB15 ------> USB_OTG_HS_DP |
||||||
|
*/ |
||||||
|
GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15; |
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL; |
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; |
||||||
|
GPIO_InitStruct.Alternate = GPIO_AF12_OTG_HS_FS; |
||||||
|
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
||||||
|
|
||||||
|
/* USB_OTG_HS clock enable */ |
||||||
|
__HAL_RCC_USB_OTG_HS_CLK_ENABLE(); |
||||||
|
/* USER CODE BEGIN USB_OTG_HS_MspInit 1 */ |
||||||
|
|
||||||
|
/* USER CODE END USB_OTG_HS_MspInit 1 */ |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle) |
||||||
|
{ |
||||||
|
|
||||||
|
if(pcdHandle->Instance==USB_OTG_FS) |
||||||
|
{ |
||||||
|
/* USER CODE BEGIN USB_OTG_FS_MspDeInit 0 */ |
||||||
|
|
||||||
|
/* USER CODE END USB_OTG_FS_MspDeInit 0 */ |
||||||
|
/* Peripheral clock disable */ |
||||||
|
__HAL_RCC_USB_OTG_FS_CLK_DISABLE(); |
||||||
|
|
||||||
|
/**USB_OTG_FS GPIO Configuration
|
||||||
|
PA11 ------> USB_OTG_FS_DM |
||||||
|
PA12 ------> USB_OTG_FS_DP |
||||||
|
*/ |
||||||
|
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_11|GPIO_PIN_12); |
||||||
|
|
||||||
|
/* USER CODE BEGIN USB_OTG_FS_MspDeInit 1 */ |
||||||
|
|
||||||
|
/* USER CODE END USB_OTG_FS_MspDeInit 1 */ |
||||||
|
} |
||||||
|
else if(pcdHandle->Instance==USB_OTG_HS) |
||||||
|
{ |
||||||
|
/* USER CODE BEGIN USB_OTG_HS_MspDeInit 0 */ |
||||||
|
|
||||||
|
/* USER CODE END USB_OTG_HS_MspDeInit 0 */ |
||||||
|
/* Peripheral clock disable */ |
||||||
|
__HAL_RCC_USB_OTG_HS_CLK_DISABLE(); |
||||||
|
|
||||||
|
/**USB_OTG_HS GPIO Configuration
|
||||||
|
PB14 ------> USB_OTG_HS_DM |
||||||
|
PB15 ------> USB_OTG_HS_DP |
||||||
|
*/ |
||||||
|
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_14|GPIO_PIN_15); |
||||||
|
|
||||||
|
/* USER CODE BEGIN USB_OTG_HS_MspDeInit 1 */ |
||||||
|
|
||||||
|
/* USER CODE END USB_OTG_HS_MspDeInit 1 */ |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/* USER CODE BEGIN 1 */ |
||||||
|
|
||||||
|
/* USER CODE END 1 */ |
||||||
@ -0,0 +1,3 @@ |
|||||||
|
# Copyright (c) 2016 STMicroelectronics |
||||||
|
|
||||||
|
This software component is licensed by STMicroelectronics under the **BSD-3-Clause** license. You may not use this file except in compliance with this license. You may obtain a copy of the license [here](https://opensource.org/licenses/BSD-3-Clause). |
||||||
@ -0,0 +1,475 @@ |
|||||||
|
#MicroXplorer Configuration settings - do not modify |
||||||
|
CAD.formats= |
||||||
|
CAD.pinconfig= |
||||||
|
CAD.provider= |
||||||
|
Dma.Request0=USART1_RX |
||||||
|
Dma.Request1=USART1_TX |
||||||
|
Dma.Request2=USART2_RX |
||||||
|
Dma.Request3=USART2_TX |
||||||
|
Dma.Request4=USART3_RX |
||||||
|
Dma.Request5=USART3_TX |
||||||
|
Dma.Request6=SDIO_RX |
||||||
|
Dma.Request7=SDIO_TX |
||||||
|
Dma.RequestsNb=8 |
||||||
|
Dma.SDIO_RX.6.Direction=DMA_PERIPH_TO_MEMORY |
||||||
|
Dma.SDIO_RX.6.FIFOMode=DMA_FIFOMODE_ENABLE |
||||||
|
Dma.SDIO_RX.6.FIFOThreshold=DMA_FIFO_THRESHOLD_FULL |
||||||
|
Dma.SDIO_RX.6.Instance=DMA2_Stream3 |
||||||
|
Dma.SDIO_RX.6.MemBurst=DMA_MBURST_INC4 |
||||||
|
Dma.SDIO_RX.6.MemDataAlignment=DMA_MDATAALIGN_WORD |
||||||
|
Dma.SDIO_RX.6.MemInc=DMA_MINC_ENABLE |
||||||
|
Dma.SDIO_RX.6.Mode=DMA_PFCTRL |
||||||
|
Dma.SDIO_RX.6.PeriphBurst=DMA_PBURST_INC4 |
||||||
|
Dma.SDIO_RX.6.PeriphDataAlignment=DMA_PDATAALIGN_WORD |
||||||
|
Dma.SDIO_RX.6.PeriphInc=DMA_PINC_DISABLE |
||||||
|
Dma.SDIO_RX.6.Priority=DMA_PRIORITY_LOW |
||||||
|
Dma.SDIO_RX.6.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode,FIFOThreshold,MemBurst,PeriphBurst |
||||||
|
Dma.SDIO_TX.7.Direction=DMA_MEMORY_TO_PERIPH |
||||||
|
Dma.SDIO_TX.7.FIFOMode=DMA_FIFOMODE_ENABLE |
||||||
|
Dma.SDIO_TX.7.FIFOThreshold=DMA_FIFO_THRESHOLD_FULL |
||||||
|
Dma.SDIO_TX.7.Instance=DMA2_Stream6 |
||||||
|
Dma.SDIO_TX.7.MemBurst=DMA_MBURST_INC4 |
||||||
|
Dma.SDIO_TX.7.MemDataAlignment=DMA_MDATAALIGN_WORD |
||||||
|
Dma.SDIO_TX.7.MemInc=DMA_MINC_ENABLE |
||||||
|
Dma.SDIO_TX.7.Mode=DMA_PFCTRL |
||||||
|
Dma.SDIO_TX.7.PeriphBurst=DMA_PBURST_INC4 |
||||||
|
Dma.SDIO_TX.7.PeriphDataAlignment=DMA_PDATAALIGN_WORD |
||||||
|
Dma.SDIO_TX.7.PeriphInc=DMA_PINC_DISABLE |
||||||
|
Dma.SDIO_TX.7.Priority=DMA_PRIORITY_LOW |
||||||
|
Dma.SDIO_TX.7.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode,FIFOThreshold,MemBurst,PeriphBurst |
||||||
|
Dma.USART1_RX.0.Direction=DMA_PERIPH_TO_MEMORY |
||||||
|
Dma.USART1_RX.0.FIFOMode=DMA_FIFOMODE_DISABLE |
||||||
|
Dma.USART1_RX.0.Instance=DMA2_Stream2 |
||||||
|
Dma.USART1_RX.0.MemDataAlignment=DMA_MDATAALIGN_BYTE |
||||||
|
Dma.USART1_RX.0.MemInc=DMA_MINC_ENABLE |
||||||
|
Dma.USART1_RX.0.Mode=DMA_NORMAL |
||||||
|
Dma.USART1_RX.0.PeriphDataAlignment=DMA_PDATAALIGN_BYTE |
||||||
|
Dma.USART1_RX.0.PeriphInc=DMA_PINC_DISABLE |
||||||
|
Dma.USART1_RX.0.Priority=DMA_PRIORITY_LOW |
||||||
|
Dma.USART1_RX.0.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode |
||||||
|
Dma.USART1_TX.1.Direction=DMA_MEMORY_TO_PERIPH |
||||||
|
Dma.USART1_TX.1.FIFOMode=DMA_FIFOMODE_DISABLE |
||||||
|
Dma.USART1_TX.1.Instance=DMA2_Stream7 |
||||||
|
Dma.USART1_TX.1.MemDataAlignment=DMA_MDATAALIGN_BYTE |
||||||
|
Dma.USART1_TX.1.MemInc=DMA_MINC_ENABLE |
||||||
|
Dma.USART1_TX.1.Mode=DMA_NORMAL |
||||||
|
Dma.USART1_TX.1.PeriphDataAlignment=DMA_PDATAALIGN_BYTE |
||||||
|
Dma.USART1_TX.1.PeriphInc=DMA_PINC_DISABLE |
||||||
|
Dma.USART1_TX.1.Priority=DMA_PRIORITY_LOW |
||||||
|
Dma.USART1_TX.1.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode |
||||||
|
Dma.USART2_RX.2.Direction=DMA_PERIPH_TO_MEMORY |
||||||
|
Dma.USART2_RX.2.FIFOMode=DMA_FIFOMODE_DISABLE |
||||||
|
Dma.USART2_RX.2.Instance=DMA1_Stream5 |
||||||
|
Dma.USART2_RX.2.MemDataAlignment=DMA_MDATAALIGN_BYTE |
||||||
|
Dma.USART2_RX.2.MemInc=DMA_MINC_ENABLE |
||||||
|
Dma.USART2_RX.2.Mode=DMA_NORMAL |
||||||
|
Dma.USART2_RX.2.PeriphDataAlignment=DMA_PDATAALIGN_BYTE |
||||||
|
Dma.USART2_RX.2.PeriphInc=DMA_PINC_DISABLE |
||||||
|
Dma.USART2_RX.2.Priority=DMA_PRIORITY_LOW |
||||||
|
Dma.USART2_RX.2.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode |
||||||
|
Dma.USART2_TX.3.Direction=DMA_MEMORY_TO_PERIPH |
||||||
|
Dma.USART2_TX.3.FIFOMode=DMA_FIFOMODE_DISABLE |
||||||
|
Dma.USART2_TX.3.Instance=DMA1_Stream6 |
||||||
|
Dma.USART2_TX.3.MemDataAlignment=DMA_MDATAALIGN_BYTE |
||||||
|
Dma.USART2_TX.3.MemInc=DMA_MINC_ENABLE |
||||||
|
Dma.USART2_TX.3.Mode=DMA_NORMAL |
||||||
|
Dma.USART2_TX.3.PeriphDataAlignment=DMA_PDATAALIGN_BYTE |
||||||
|
Dma.USART2_TX.3.PeriphInc=DMA_PINC_DISABLE |
||||||
|
Dma.USART2_TX.3.Priority=DMA_PRIORITY_LOW |
||||||
|
Dma.USART2_TX.3.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode |
||||||
|
Dma.USART3_RX.4.Direction=DMA_PERIPH_TO_MEMORY |
||||||
|
Dma.USART3_RX.4.FIFOMode=DMA_FIFOMODE_DISABLE |
||||||
|
Dma.USART3_RX.4.Instance=DMA1_Stream1 |
||||||
|
Dma.USART3_RX.4.MemDataAlignment=DMA_MDATAALIGN_BYTE |
||||||
|
Dma.USART3_RX.4.MemInc=DMA_MINC_ENABLE |
||||||
|
Dma.USART3_RX.4.Mode=DMA_NORMAL |
||||||
|
Dma.USART3_RX.4.PeriphDataAlignment=DMA_PDATAALIGN_BYTE |
||||||
|
Dma.USART3_RX.4.PeriphInc=DMA_PINC_DISABLE |
||||||
|
Dma.USART3_RX.4.Priority=DMA_PRIORITY_LOW |
||||||
|
Dma.USART3_RX.4.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode |
||||||
|
Dma.USART3_TX.5.Direction=DMA_MEMORY_TO_PERIPH |
||||||
|
Dma.USART3_TX.5.FIFOMode=DMA_FIFOMODE_DISABLE |
||||||
|
Dma.USART3_TX.5.Instance=DMA1_Stream3 |
||||||
|
Dma.USART3_TX.5.MemDataAlignment=DMA_MDATAALIGN_BYTE |
||||||
|
Dma.USART3_TX.5.MemInc=DMA_MINC_ENABLE |
||||||
|
Dma.USART3_TX.5.Mode=DMA_NORMAL |
||||||
|
Dma.USART3_TX.5.PeriphDataAlignment=DMA_PDATAALIGN_BYTE |
||||||
|
Dma.USART3_TX.5.PeriphInc=DMA_PINC_DISABLE |
||||||
|
Dma.USART3_TX.5.Priority=DMA_PRIORITY_LOW |
||||||
|
Dma.USART3_TX.5.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode |
||||||
|
FATFS.BSP.number=1 |
||||||
|
FATFS.IPParameters=_CODE_PAGE,_USE_LFN,_USE_LABEL,_MAX_SS,_FS_EXFAT |
||||||
|
FATFS._CODE_PAGE=936 |
||||||
|
FATFS._FS_EXFAT=1 |
||||||
|
FATFS._MAX_SS=4096 |
||||||
|
FATFS._USE_LABEL=1 |
||||||
|
FATFS._USE_LFN=2 |
||||||
|
FATFS0.BSP.STBoard=false |
||||||
|
FATFS0.BSP.api=Unknown |
||||||
|
FATFS0.BSP.component= |
||||||
|
FATFS0.BSP.condition= |
||||||
|
FATFS0.BSP.instance=PA15 |
||||||
|
FATFS0.BSP.ip=GPIO |
||||||
|
FATFS0.BSP.mode=Input |
||||||
|
FATFS0.BSP.name=Detect_SDIO |
||||||
|
FATFS0.BSP.semaphore= |
||||||
|
FATFS0.BSP.solution=PA15 |
||||||
|
FREERTOS.FootprintOK=true |
||||||
|
FREERTOS.IPParameters=Tasks01,FootprintOK,configCHECK_FOR_STACK_OVERFLOW,configUSE_IDLE_HOOK,configUSE_TICK_HOOK |
||||||
|
FREERTOS.Tasks01=defaultTask,24,1024,StartDefaultTask,As weak,NULL,Dynamic,NULL,NULL |
||||||
|
FREERTOS.configCHECK_FOR_STACK_OVERFLOW=2 |
||||||
|
FREERTOS.configUSE_IDLE_HOOK=1 |
||||||
|
FREERTOS.configUSE_TICK_HOOK=1 |
||||||
|
File.Version=6 |
||||||
|
GPIO.groupedBy=Group By Peripherals |
||||||
|
KeepUserPlacement=false |
||||||
|
Mcu.CPN=STM32F407ZET6 |
||||||
|
Mcu.Family=STM32F4 |
||||||
|
Mcu.IP0=DMA |
||||||
|
Mcu.IP1=FATFS |
||||||
|
Mcu.IP10=UART4 |
||||||
|
Mcu.IP11=USART1 |
||||||
|
Mcu.IP12=USART2 |
||||||
|
Mcu.IP13=USART3 |
||||||
|
Mcu.IP14=USART6 |
||||||
|
Mcu.IP15=USB_DEVICE |
||||||
|
Mcu.IP16=USB_OTG_HS |
||||||
|
Mcu.IP2=FREERTOS |
||||||
|
Mcu.IP3=I2C1 |
||||||
|
Mcu.IP4=NVIC |
||||||
|
Mcu.IP5=RCC |
||||||
|
Mcu.IP6=SDIO |
||||||
|
Mcu.IP7=SYS |
||||||
|
Mcu.IP8=TIM2 |
||||||
|
Mcu.IP9=TIM7 |
||||||
|
Mcu.IPNb=17 |
||||||
|
Mcu.Name=STM32F407Z(E-G)Tx |
||||||
|
Mcu.Package=LQFP144 |
||||||
|
Mcu.Pin0=PE4 |
||||||
|
Mcu.Pin1=PE5 |
||||||
|
Mcu.Pin10=PA4 |
||||||
|
Mcu.Pin11=PA6 |
||||||
|
Mcu.Pin12=PA7 |
||||||
|
Mcu.Pin13=PB2 |
||||||
|
Mcu.Pin14=PE12 |
||||||
|
Mcu.Pin15=PE13 |
||||||
|
Mcu.Pin16=PE14 |
||||||
|
Mcu.Pin17=PE15 |
||||||
|
Mcu.Pin18=PB10 |
||||||
|
Mcu.Pin19=PB11 |
||||||
|
Mcu.Pin2=PE6 |
||||||
|
Mcu.Pin20=PB14 |
||||||
|
Mcu.Pin21=PB15 |
||||||
|
Mcu.Pin22=PG4 |
||||||
|
Mcu.Pin23=PG5 |
||||||
|
Mcu.Pin24=PC6 |
||||||
|
Mcu.Pin25=PC7 |
||||||
|
Mcu.Pin26=PC8 |
||||||
|
Mcu.Pin27=PC9 |
||||||
|
Mcu.Pin28=PA9 |
||||||
|
Mcu.Pin29=PA10 |
||||||
|
Mcu.Pin3=PF0 |
||||||
|
Mcu.Pin30=PA13 |
||||||
|
Mcu.Pin31=PA14 |
||||||
|
Mcu.Pin32=PA15 |
||||||
|
Mcu.Pin33=PC10 |
||||||
|
Mcu.Pin34=PC11 |
||||||
|
Mcu.Pin35=PC12 |
||||||
|
Mcu.Pin36=PD2 |
||||||
|
Mcu.Pin37=PB4 |
||||||
|
Mcu.Pin38=PB5 |
||||||
|
Mcu.Pin39=PB6 |
||||||
|
Mcu.Pin4=PH0-OSC_IN |
||||||
|
Mcu.Pin40=PB7 |
||||||
|
Mcu.Pin41=PE0 |
||||||
|
Mcu.Pin42=PE1 |
||||||
|
Mcu.Pin43=VP_FATFS_VS_SDIO |
||||||
|
Mcu.Pin44=VP_FREERTOS_VS_CMSIS_V2 |
||||||
|
Mcu.Pin45=VP_SYS_VS_tim6 |
||||||
|
Mcu.Pin46=VP_TIM2_VS_ClockSourceINT |
||||||
|
Mcu.Pin47=VP_TIM7_VS_ClockSourceINT |
||||||
|
Mcu.Pin48=VP_USB_DEVICE_VS_USB_DEVICE_MSC_HS |
||||||
|
Mcu.Pin5=PH1-OSC_OUT |
||||||
|
Mcu.Pin6=PA0-WKUP |
||||||
|
Mcu.Pin7=PA1 |
||||||
|
Mcu.Pin8=PA2 |
||||||
|
Mcu.Pin9=PA3 |
||||||
|
Mcu.PinsNb=49 |
||||||
|
Mcu.ThirdPartyNb=0 |
||||||
|
Mcu.UserConstants= |
||||||
|
Mcu.UserName=STM32F407ZETx |
||||||
|
MxCube.Version=6.8.1 |
||||||
|
MxDb.Version=DB.6.0.81 |
||||||
|
NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false |
||||||
|
NVIC.DMA1_Stream1_IRQn=true\:5\:0\:false\:false\:true\:true\:false\:true\:true |
||||||
|
NVIC.DMA1_Stream3_IRQn=true\:5\:0\:false\:false\:true\:true\:false\:true\:true |
||||||
|
NVIC.DMA1_Stream5_IRQn=true\:5\:0\:false\:false\:true\:true\:false\:true\:true |
||||||
|
NVIC.DMA1_Stream6_IRQn=true\:5\:0\:false\:false\:true\:true\:false\:true\:true |
||||||
|
NVIC.DMA2_Stream2_IRQn=true\:5\:0\:false\:false\:true\:true\:false\:true\:true |
||||||
|
NVIC.DMA2_Stream3_IRQn=true\:10\:0\:true\:false\:true\:true\:false\:true\:true |
||||||
|
NVIC.DMA2_Stream6_IRQn=true\:10\:0\:true\:false\:true\:true\:false\:true\:true |
||||||
|
NVIC.DMA2_Stream7_IRQn=true\:5\:0\:false\:false\:true\:true\:false\:true\:true |
||||||
|
NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false |
||||||
|
NVIC.ForceEnableDMAVector=true |
||||||
|
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false |
||||||
|
NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false |
||||||
|
NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false |
||||||
|
NVIC.OTG_HS_IRQn=true\:11\:0\:true\:false\:true\:true\:false\:true\:true |
||||||
|
NVIC.PendSV_IRQn=true\:15\:0\:false\:false\:false\:true\:false\:false\:false |
||||||
|
NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 |
||||||
|
NVIC.SDIO_IRQn=true\:9\:0\:true\:false\:true\:true\:true\:true\:true |
||||||
|
NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:false\:false\:false\:false\:false |
||||||
|
NVIC.SavedPendsvIrqHandlerGenerated=true |
||||||
|
NVIC.SavedSvcallIrqHandlerGenerated=true |
||||||
|
NVIC.SavedSystickIrqHandlerGenerated=true |
||||||
|
NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:false\:true\:false\:true\:false |
||||||
|
NVIC.TIM2_IRQn=true\:5\:0\:false\:false\:false\:true\:true\:true\:true |
||||||
|
NVIC.TIM6_DAC_IRQn=true\:15\:0\:false\:false\:true\:false\:false\:true\:true |
||||||
|
NVIC.TIM7_IRQn=true\:5\:0\:false\:false\:false\:true\:true\:true\:true |
||||||
|
NVIC.TimeBase=TIM6_DAC_IRQn |
||||||
|
NVIC.TimeBaseIP=TIM6 |
||||||
|
NVIC.UART4_IRQn=true\:5\:0\:false\:false\:false\:true\:true\:true\:true |
||||||
|
NVIC.USART1_IRQn=true\:5\:0\:false\:false\:false\:true\:true\:true\:true |
||||||
|
NVIC.USART2_IRQn=true\:5\:0\:false\:false\:false\:true\:true\:true\:true |
||||||
|
NVIC.USART3_IRQn=true\:5\:0\:false\:false\:false\:true\:true\:true\:true |
||||||
|
NVIC.USART6_IRQn=true\:7\:0\:true\:false\:false\:true\:true\:true\:true |
||||||
|
NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false |
||||||
|
PA0-WKUP.Mode=Asynchronous |
||||||
|
PA0-WKUP.Signal=UART4_TX |
||||||
|
PA1.Mode=Asynchronous |
||||||
|
PA1.Signal=UART4_RX |
||||||
|
PA10.Mode=Asynchronous |
||||||
|
PA10.Signal=USART1_RX |
||||||
|
PA13.Mode=Serial_Wire |
||||||
|
PA13.Signal=SYS_JTMS-SWDIO |
||||||
|
PA14.Mode=Serial_Wire |
||||||
|
PA14.Signal=SYS_JTCK-SWCLK |
||||||
|
PA15.GPIOParameters=GPIO_Label |
||||||
|
PA15.GPIO_Label=CDZ |
||||||
|
PA15.Locked=true |
||||||
|
PA15.Signal=GPIO_Input |
||||||
|
PA2.Locked=true |
||||||
|
PA2.Mode=Asynchronous |
||||||
|
PA2.Signal=USART2_TX |
||||||
|
PA3.Locked=true |
||||||
|
PA3.Mode=Asynchronous |
||||||
|
PA3.Signal=USART2_RX |
||||||
|
PA4.GPIOParameters=GPIO_Label |
||||||
|
PA4.GPIO_Label=MAX3242_EN |
||||||
|
PA4.Locked=true |
||||||
|
PA4.Signal=GPIO_Output |
||||||
|
PA6.GPIOParameters=GPIO_Label |
||||||
|
PA6.GPIO_Label=SENSOR2_EN |
||||||
|
PA6.Locked=true |
||||||
|
PA6.Signal=GPIO_Output |
||||||
|
PA7.GPIOParameters=GPIO_Label |
||||||
|
PA7.GPIO_Label=SENSOR4_EN |
||||||
|
PA7.Locked=true |
||||||
|
PA7.Signal=GPIO_Output |
||||||
|
PA9.Mode=Asynchronous |
||||||
|
PA9.Signal=USART1_TX |
||||||
|
PB10.Locked=true |
||||||
|
PB10.Mode=Asynchronous |
||||||
|
PB10.Signal=USART3_TX |
||||||
|
PB11.Locked=true |
||||||
|
PB11.Mode=Asynchronous |
||||||
|
PB11.Signal=USART3_RX |
||||||
|
PB14.Mode=Device_Only_FS |
||||||
|
PB14.Signal=USB_OTG_HS_DM |
||||||
|
PB15.Mode=Device_Only_FS |
||||||
|
PB15.Signal=USB_OTG_HS_DP |
||||||
|
PB2.GPIOParameters=GPIO_Label |
||||||
|
PB2.GPIO_Label=BOOT1 |
||||||
|
PB2.Locked=true |
||||||
|
PB2.Signal=GPIO_Input |
||||||
|
PB4.GPIOParameters=GPIO_Label |
||||||
|
PB4.GPIO_Label=ADDR |
||||||
|
PB4.Locked=true |
||||||
|
PB4.Signal=GPIO_Output |
||||||
|
PB5.GPIOParameters=GPIO_Label |
||||||
|
PB5.GPIO_Label=RDY |
||||||
|
PB5.Locked=true |
||||||
|
PB5.Signal=GPIO_Output |
||||||
|
PB6.GPIOParameters=GPIO_Pu |
||||||
|
PB6.GPIO_Pu=GPIO_PULLUP |
||||||
|
PB6.Mode=I2C |
||||||
|
PB6.Signal=I2C1_SCL |
||||||
|
PB7.GPIOParameters=GPIO_Pu |
||||||
|
PB7.GPIO_Pu=GPIO_PULLUP |
||||||
|
PB7.Mode=I2C |
||||||
|
PB7.Signal=I2C1_SDA |
||||||
|
PC10.Mode=SD_4_bits_Wide_bus |
||||||
|
PC10.Signal=SDIO_D2 |
||||||
|
PC11.Mode=SD_4_bits_Wide_bus |
||||||
|
PC11.Signal=SDIO_D3 |
||||||
|
PC12.Mode=SD_4_bits_Wide_bus |
||||||
|
PC12.Signal=SDIO_CK |
||||||
|
PC6.Locked=true |
||||||
|
PC6.Mode=Asynchronous |
||||||
|
PC6.Signal=USART6_TX |
||||||
|
PC7.Locked=true |
||||||
|
PC7.Mode=Asynchronous |
||||||
|
PC7.Signal=USART6_RX |
||||||
|
PC8.Mode=SD_4_bits_Wide_bus |
||||||
|
PC8.Signal=SDIO_D0 |
||||||
|
PC9.Mode=SD_4_bits_Wide_bus |
||||||
|
PC9.Signal=SDIO_D1 |
||||||
|
PD2.Mode=SD_4_bits_Wide_bus |
||||||
|
PD2.Signal=SDIO_CMD |
||||||
|
PE0.GPIOParameters=GPIO_Label |
||||||
|
PE0.GPIO_Label=LED0 |
||||||
|
PE0.Locked=true |
||||||
|
PE0.Signal=GPIO_Output |
||||||
|
PE1.GPIOParameters=GPIO_Label |
||||||
|
PE1.GPIO_Label=LED1 |
||||||
|
PE1.Locked=true |
||||||
|
PE1.Signal=GPIO_Output |
||||||
|
PE12.GPIOParameters=GPIO_Label |
||||||
|
PE12.GPIO_Label=SENSOR3_EN |
||||||
|
PE12.Locked=true |
||||||
|
PE12.Signal=GPIO_Output |
||||||
|
PE13.GPIOParameters=GPIO_Label |
||||||
|
PE13.GPIO_Label=DE485 |
||||||
|
PE13.Locked=true |
||||||
|
PE13.Signal=GPIO_Output |
||||||
|
PE14.GPIOParameters=GPIO_Label |
||||||
|
PE14.GPIO_Label=HDPLX |
||||||
|
PE14.Locked=true |
||||||
|
PE14.Signal=GPIO_Output |
||||||
|
PE15.GPIOParameters=GPIO_Label |
||||||
|
PE15.GPIO_Label=SEL_232/485 |
||||||
|
PE15.Locked=true |
||||||
|
PE15.Signal=GPIO_Output |
||||||
|
PE4.GPIOParameters=GPIO_Label |
||||||
|
PE4.GPIO_Label=EN_1302 |
||||||
|
PE4.Locked=true |
||||||
|
PE4.Signal=GPIO_Output |
||||||
|
PE5.GPIOParameters=GPIO_Label,GPIO_ModeDefaultOutputPP |
||||||
|
PE5.GPIO_Label=DA_1302 |
||||||
|
PE5.GPIO_ModeDefaultOutputPP=GPIO_MODE_OUTPUT_OD |
||||||
|
PE5.Locked=true |
||||||
|
PE5.Signal=GPIO_Output |
||||||
|
PE6.GPIOParameters=GPIO_Label |
||||||
|
PE6.GPIO_Label=SCLK_1302 |
||||||
|
PE6.Locked=true |
||||||
|
PE6.Signal=GPIO_Output |
||||||
|
PF0.GPIOParameters=GPIO_Label |
||||||
|
PF0.GPIO_Label=PUMP_EN |
||||||
|
PF0.Locked=true |
||||||
|
PF0.Signal=GPIO_Output |
||||||
|
PG4.GPIOParameters=GPIO_Label |
||||||
|
PG4.GPIO_Label=SENSOR6_EN |
||||||
|
PG4.Locked=true |
||||||
|
PG4.Signal=GPIO_Output |
||||||
|
PG5.GPIOParameters=GPIO_Label |
||||||
|
PG5.GPIO_Label=R/W |
||||||
|
PG5.Locked=true |
||||||
|
PG5.Signal=GPIO_Output |
||||||
|
PH0-OSC_IN.Mode=HSE-External-Oscillator |
||||||
|
PH0-OSC_IN.Signal=RCC_OSC_IN |
||||||
|
PH1-OSC_OUT.Mode=HSE-External-Oscillator |
||||||
|
PH1-OSC_OUT.Signal=RCC_OSC_OUT |
||||||
|
PinOutPanel.RotationAngle=0 |
||||||
|
ProjectManager.AskForMigrate=true |
||||||
|
ProjectManager.BackupPrevious=false |
||||||
|
ProjectManager.CompilerOptimize=6 |
||||||
|
ProjectManager.ComputerToolchain=false |
||||||
|
ProjectManager.CoupleFile=true |
||||||
|
ProjectManager.CustomerFirmwarePackage= |
||||||
|
ProjectManager.DefaultFWLocation=true |
||||||
|
ProjectManager.DeletePrevious=true |
||||||
|
ProjectManager.DeviceId=STM32F407ZETx |
||||||
|
ProjectManager.FirmwarePackage=STM32Cube FW_F4 V1.27.1 |
||||||
|
ProjectManager.FreePins=false |
||||||
|
ProjectManager.HalAssertFull=false |
||||||
|
ProjectManager.HeapSize=0x1000 |
||||||
|
ProjectManager.KeepUserCode=true |
||||||
|
ProjectManager.LastFirmware=true |
||||||
|
ProjectManager.LibraryCopy=0 |
||||||
|
ProjectManager.MainLocation=Core/Src |
||||||
|
ProjectManager.NoMain=false |
||||||
|
ProjectManager.PreviousToolchain= |
||||||
|
ProjectManager.ProjectBuild=false |
||||||
|
ProjectManager.ProjectFileName=H2S.ioc |
||||||
|
ProjectManager.ProjectName=H2S |
||||||
|
ProjectManager.ProjectStructure= |
||||||
|
ProjectManager.RegisterCallBack= |
||||||
|
ProjectManager.StackSize=0x1500 |
||||||
|
ProjectManager.TargetToolchain=Makefile |
||||||
|
ProjectManager.ToolChainLocation= |
||||||
|
ProjectManager.UnderRoot=false |
||||||
|
ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_I2C1_Init-I2C1-false-HAL-true,5-MX_SDIO_SD_Init-SDIO-false-HAL-true,6-MX_UART4_Init-UART4-false-HAL-true,7-MX_USART1_UART_Init-USART1-false-HAL-true,8-MX_USART2_UART_Init-USART2-false-HAL-true,9-MX_USART3_UART_Init-USART3-false-HAL-true,10-MX_USART6_UART_Init-USART6-false-HAL-true,11-MX_TIM7_Init-TIM7-false-HAL-true,12-MX_FATFS_Init-FATFS-false-HAL-false,13-MX_USB_DEVICE_Init-USB_DEVICE-false-HAL-false,14-MX_TIM2_Init-TIM2-false-HAL-true |
||||||
|
RCC.48MHZClocksFreq_Value=48000000 |
||||||
|
RCC.AHBFreq_Value=168000000 |
||||||
|
RCC.APB1CLKDivider=RCC_HCLK_DIV4 |
||||||
|
RCC.APB1Freq_Value=42000000 |
||||||
|
RCC.APB1TimFreq_Value=84000000 |
||||||
|
RCC.APB2CLKDivider=RCC_HCLK_DIV2 |
||||||
|
RCC.APB2Freq_Value=84000000 |
||||||
|
RCC.APB2TimFreq_Value=168000000 |
||||||
|
RCC.CortexFreq_Value=168000000 |
||||||
|
RCC.EthernetFreq_Value=168000000 |
||||||
|
RCC.FCLKCortexFreq_Value=168000000 |
||||||
|
RCC.FamilyName=M |
||||||
|
RCC.HCLKFreq_Value=168000000 |
||||||
|
RCC.HSE_VALUE=8000000 |
||||||
|
RCC.HSI_VALUE=16000000 |
||||||
|
RCC.I2SClocksFreq_Value=192000000 |
||||||
|
RCC.IPParameters=48MHZClocksFreq_Value,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2CLKDivider,APB2Freq_Value,APB2TimFreq_Value,CortexFreq_Value,EthernetFreq_Value,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,HSE_VALUE,HSI_VALUE,I2SClocksFreq_Value,LSE_VALUE,LSI_VALUE,MCO2PinFreq_Value,PLLCLKFreq_Value,PLLM,PLLN,PLLQ,PLLQCLKFreq_Value,RTCFreq_Value,RTCHSEDivFreq_Value,SYSCLKFreq_VALUE,SYSCLKSource,VCOI2SOutputFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value,VcooutputI2S |
||||||
|
RCC.LSE_VALUE=32768 |
||||||
|
RCC.LSI_VALUE=32000 |
||||||
|
RCC.MCO2PinFreq_Value=168000000 |
||||||
|
RCC.PLLCLKFreq_Value=168000000 |
||||||
|
RCC.PLLM=4 |
||||||
|
RCC.PLLN=168 |
||||||
|
RCC.PLLQ=7 |
||||||
|
RCC.PLLQCLKFreq_Value=48000000 |
||||||
|
RCC.RTCFreq_Value=32000 |
||||||
|
RCC.RTCHSEDivFreq_Value=4000000 |
||||||
|
RCC.SYSCLKFreq_VALUE=168000000 |
||||||
|
RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK |
||||||
|
RCC.VCOI2SOutputFreq_Value=384000000 |
||||||
|
RCC.VCOInputFreq_Value=2000000 |
||||||
|
RCC.VCOOutputFreq_Value=336000000 |
||||||
|
RCC.VcooutputI2S=192000000 |
||||||
|
SDIO.ClockDiv=6 |
||||||
|
SDIO.IPParameters=ClockDiv |
||||||
|
TIM2.IPParameters=Prescaler,Period |
||||||
|
TIM2.Period=10000-1 |
||||||
|
TIM2.Prescaler=8400-1 |
||||||
|
TIM7.IPParameters=Prescaler,Period |
||||||
|
TIM7.Period=50-1 |
||||||
|
TIM7.Prescaler=8400-1 |
||||||
|
UART4.IPParameters=VirtualMode |
||||||
|
UART4.VirtualMode=Asynchronous |
||||||
|
USART1.IPParameters=VirtualMode |
||||||
|
USART1.VirtualMode=VM_ASYNC |
||||||
|
USART2.IPParameters=VirtualMode |
||||||
|
USART2.VirtualMode=VM_ASYNC |
||||||
|
USART3.BaudRate=9600 |
||||||
|
USART3.IPParameters=VirtualMode,BaudRate |
||||||
|
USART3.VirtualMode=VM_ASYNC |
||||||
|
USART6.BaudRate=19200 |
||||||
|
USART6.IPParameters=VirtualMode,BaudRate |
||||||
|
USART6.VirtualMode=VM_ASYNC |
||||||
|
USB_DEVICE.CLASS_NAME_HS=MSC |
||||||
|
USB_DEVICE.IPParameters=VirtualMode-MSC_HS,VirtualModeHS,CLASS_NAME_HS,MSC_MEDIA_PACKET-MSC_HS |
||||||
|
USB_DEVICE.MSC_MEDIA_PACKET-MSC_HS=4096 |
||||||
|
USB_DEVICE.VirtualMode-MSC_HS=Msc |
||||||
|
USB_DEVICE.VirtualModeHS=Msc_HS |
||||||
|
USB_OTG_HS.IPParameters=VirtualMode-Device_Only_FS |
||||||
|
USB_OTG_HS.VirtualMode-Device_Only_FS=Device_Only_FS |
||||||
|
VP_FATFS_VS_SDIO.Mode=SDIO |
||||||
|
VP_FATFS_VS_SDIO.Signal=FATFS_VS_SDIO |
||||||
|
VP_FREERTOS_VS_CMSIS_V2.Mode=CMSIS_V2 |
||||||
|
VP_FREERTOS_VS_CMSIS_V2.Signal=FREERTOS_VS_CMSIS_V2 |
||||||
|
VP_SYS_VS_tim6.Mode=TIM6 |
||||||
|
VP_SYS_VS_tim6.Signal=SYS_VS_tim6 |
||||||
|
VP_TIM2_VS_ClockSourceINT.Mode=Internal |
||||||
|
VP_TIM2_VS_ClockSourceINT.Signal=TIM2_VS_ClockSourceINT |
||||||
|
VP_TIM7_VS_ClockSourceINT.Mode=Enable_Timer |
||||||
|
VP_TIM7_VS_ClockSourceINT.Signal=TIM7_VS_ClockSourceINT |
||||||
|
VP_USB_DEVICE_VS_USB_DEVICE_MSC_HS.Mode=MSC_HS |
||||||
|
VP_USB_DEVICE_VS_USB_DEVICE_MSC_HS.Signal=USB_DEVICE_VS_USB_DEVICE_MSC_HS |
||||||
|
board=custom |
||||||
|
rtos.0.ip=FREERTOS |
||||||
@ -1,130 +0,0 @@ |
|||||||
/**
|
|
||||||
****************************************************************************** |
|
||||||
* @file usbd_msc.h |
|
||||||
* @author MCD Application Team |
|
||||||
* @brief Header for the usbd_msc.c file |
|
||||||
****************************************************************************** |
|
||||||
* @attention |
|
||||||
* |
|
||||||
* Copyright (c) 2015 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. |
|
||||||
* |
|
||||||
****************************************************************************** |
|
||||||
*/ |
|
||||||
|
|
||||||
/* Define to prevent recursive inclusion -------------------------------------*/ |
|
||||||
#ifndef __USBD_MSC_H |
|
||||||
#define __USBD_MSC_H |
|
||||||
|
|
||||||
#ifdef __cplusplus |
|
||||||
extern "C" { |
|
||||||
#endif |
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/ |
|
||||||
#include "usbd_msc_bot.h" |
|
||||||
#include "usbd_msc_scsi.h" |
|
||||||
#include "usbd_ioreq.h" |
|
||||||
|
|
||||||
/** @addtogroup USBD_MSC_BOT
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_MSC
|
|
||||||
* @brief This file is the Header file for usbd_msc.c |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup USBD_BOT_Exported_Defines
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
/* MSC Class Config */ |
|
||||||
#ifndef MSC_MEDIA_PACKET |
|
||||||
#define MSC_MEDIA_PACKET 512U |
|
||||||
#endif /* MSC_MEDIA_PACKET */ |
|
||||||
|
|
||||||
#define MSC_MAX_FS_PACKET 0x40U |
|
||||||
#define MSC_MAX_HS_PACKET 0x200U |
|
||||||
|
|
||||||
#define BOT_GET_MAX_LUN 0xFE |
|
||||||
#define BOT_RESET 0xFF |
|
||||||
#define USB_MSC_CONFIG_DESC_SIZ 32 |
|
||||||
|
|
||||||
#ifndef MSC_EPIN_ADDR |
|
||||||
#define MSC_EPIN_ADDR 0x81U |
|
||||||
#endif /* MSC_EPIN_ADDR */ |
|
||||||
|
|
||||||
#ifndef MSC_EPOUT_ADDR |
|
||||||
#define MSC_EPOUT_ADDR 0x01U |
|
||||||
#endif /* MSC_EPOUT_ADDR */ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USB_CORE_Exported_Types
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
typedef struct _USBD_STORAGE |
|
||||||
{ |
|
||||||
int8_t (* Init)(uint8_t lun); |
|
||||||
int8_t (* GetCapacity)(uint8_t lun, uint32_t *block_num, uint16_t *block_size); |
|
||||||
int8_t (* IsReady)(uint8_t lun); |
|
||||||
int8_t (* IsWriteProtected)(uint8_t lun); |
|
||||||
int8_t (* Read)(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len); |
|
||||||
int8_t (* Write)(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len); |
|
||||||
int8_t (* GetMaxLun)(void); |
|
||||||
int8_t *pInquiry; |
|
||||||
|
|
||||||
} USBD_StorageTypeDef; |
|
||||||
|
|
||||||
|
|
||||||
typedef struct |
|
||||||
{ |
|
||||||
uint32_t max_lun; |
|
||||||
uint32_t interface; |
|
||||||
uint8_t bot_state; |
|
||||||
uint8_t bot_status; |
|
||||||
uint32_t bot_data_length; |
|
||||||
uint8_t bot_data[MSC_MEDIA_PACKET]; |
|
||||||
USBD_MSC_BOT_CBWTypeDef cbw; |
|
||||||
USBD_MSC_BOT_CSWTypeDef csw; |
|
||||||
|
|
||||||
USBD_SCSI_SenseTypeDef scsi_sense [SENSE_LIST_DEEPTH]; |
|
||||||
uint8_t scsi_sense_head; |
|
||||||
uint8_t scsi_sense_tail; |
|
||||||
uint8_t scsi_medium_state; |
|
||||||
|
|
||||||
uint16_t scsi_blk_size; |
|
||||||
uint32_t scsi_blk_nbr; |
|
||||||
|
|
||||||
uint32_t scsi_blk_addr; |
|
||||||
uint32_t scsi_blk_len; |
|
||||||
} USBD_MSC_BOT_HandleTypeDef; |
|
||||||
|
|
||||||
/* Structure for MSC process */ |
|
||||||
extern USBD_ClassTypeDef USBD_MSC; |
|
||||||
#define USBD_MSC_CLASS &USBD_MSC |
|
||||||
|
|
||||||
uint8_t USBD_MSC_RegisterStorage(USBD_HandleTypeDef *pdev, |
|
||||||
USBD_StorageTypeDef *fops); |
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
#ifdef __cplusplus |
|
||||||
} |
|
||||||
#endif |
|
||||||
|
|
||||||
#endif /* __USBD_MSC_H */ |
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
@ -1,146 +0,0 @@ |
|||||||
/**
|
|
||||||
****************************************************************************** |
|
||||||
* @file usbd_msc_bot.h |
|
||||||
* @author MCD Application Team |
|
||||||
* @brief Header for the usbd_msc_bot.c file |
|
||||||
****************************************************************************** |
|
||||||
* @attention |
|
||||||
* |
|
||||||
* Copyright (c) 2015 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. |
|
||||||
* |
|
||||||
****************************************************************************** |
|
||||||
*/ |
|
||||||
|
|
||||||
/* Define to prevent recursive inclusion -------------------------------------*/ |
|
||||||
#ifndef __USBD_MSC_BOT_H |
|
||||||
#define __USBD_MSC_BOT_H |
|
||||||
|
|
||||||
#ifdef __cplusplus |
|
||||||
extern "C" { |
|
||||||
#endif |
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/ |
|
||||||
#include "usbd_core.h" |
|
||||||
|
|
||||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup MSC_BOT
|
|
||||||
* @brief This file is the Header file for usbd_msc_bot.c |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup USBD_CORE_Exported_Defines
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
#define USBD_BOT_IDLE 0U /* Idle state */ |
|
||||||
#define USBD_BOT_DATA_OUT 1U /* Data Out state */ |
|
||||||
#define USBD_BOT_DATA_IN 2U /* Data In state */ |
|
||||||
#define USBD_BOT_LAST_DATA_IN 3U /* Last Data In Last */ |
|
||||||
#define USBD_BOT_SEND_DATA 4U /* Send Immediate data */ |
|
||||||
#define USBD_BOT_NO_DATA 5U /* No data Stage */ |
|
||||||
|
|
||||||
#define USBD_BOT_CBW_SIGNATURE 0x43425355U |
|
||||||
#define USBD_BOT_CSW_SIGNATURE 0x53425355U |
|
||||||
#define USBD_BOT_CBW_LENGTH 31U |
|
||||||
#define USBD_BOT_CSW_LENGTH 13U |
|
||||||
#define USBD_BOT_MAX_DATA 256U |
|
||||||
|
|
||||||
/* CSW Status Definitions */ |
|
||||||
#define USBD_CSW_CMD_PASSED 0x00U |
|
||||||
#define USBD_CSW_CMD_FAILED 0x01U |
|
||||||
#define USBD_CSW_PHASE_ERROR 0x02U |
|
||||||
|
|
||||||
/* BOT Status */ |
|
||||||
#define USBD_BOT_STATUS_NORMAL 0U |
|
||||||
#define USBD_BOT_STATUS_RECOVERY 1U |
|
||||||
#define USBD_BOT_STATUS_ERROR 2U |
|
||||||
|
|
||||||
|
|
||||||
#define USBD_DIR_IN 0U |
|
||||||
#define USBD_DIR_OUT 1U |
|
||||||
#define USBD_BOTH_DIR 2U |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup MSC_CORE_Private_TypesDefinitions
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
typedef struct |
|
||||||
{ |
|
||||||
uint32_t dSignature; |
|
||||||
uint32_t dTag; |
|
||||||
uint32_t dDataLength; |
|
||||||
uint8_t bmFlags; |
|
||||||
uint8_t bLUN; |
|
||||||
uint8_t bCBLength; |
|
||||||
uint8_t CB[16]; |
|
||||||
uint8_t ReservedForAlign; |
|
||||||
} USBD_MSC_BOT_CBWTypeDef; |
|
||||||
|
|
||||||
|
|
||||||
typedef struct |
|
||||||
{ |
|
||||||
uint32_t dSignature; |
|
||||||
uint32_t dTag; |
|
||||||
uint32_t dDataResidue; |
|
||||||
uint8_t bStatus; |
|
||||||
uint8_t ReservedForAlign[3]; |
|
||||||
} USBD_MSC_BOT_CSWTypeDef; |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup USBD_CORE_Exported_Types
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
/** @defgroup USBD_CORE_Exported_FunctionsPrototypes
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
void MSC_BOT_Init(USBD_HandleTypeDef *pdev); |
|
||||||
void MSC_BOT_Reset(USBD_HandleTypeDef *pdev); |
|
||||||
void MSC_BOT_DeInit(USBD_HandleTypeDef *pdev); |
|
||||||
void MSC_BOT_DataIn(USBD_HandleTypeDef *pdev, |
|
||||||
uint8_t epnum); |
|
||||||
|
|
||||||
void MSC_BOT_DataOut(USBD_HandleTypeDef *pdev, |
|
||||||
uint8_t epnum); |
|
||||||
|
|
||||||
void MSC_BOT_SendCSW(USBD_HandleTypeDef *pdev, |
|
||||||
uint8_t CSW_Status); |
|
||||||
|
|
||||||
void MSC_BOT_CplClrFeature(USBD_HandleTypeDef *pdev, |
|
||||||
uint8_t epnum); |
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
#ifdef __cplusplus |
|
||||||
} |
|
||||||
#endif |
|
||||||
|
|
||||||
#endif /* __USBD_MSC_BOT_H */ |
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
@ -1,102 +0,0 @@ |
|||||||
/**
|
|
||||||
****************************************************************************** |
|
||||||
* @file usbd_msc_data.h |
|
||||||
* @author MCD Application Team |
|
||||||
* @brief Header for the usbd_msc_data.c file |
|
||||||
****************************************************************************** |
|
||||||
* @attention |
|
||||||
* |
|
||||||
* Copyright (c) 2015 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. |
|
||||||
* |
|
||||||
****************************************************************************** |
|
||||||
*/ |
|
||||||
|
|
||||||
/* Define to prevent recursive inclusion -------------------------------------*/ |
|
||||||
#ifndef __USBD_MSC_DATA_H |
|
||||||
#define __USBD_MSC_DATA_H |
|
||||||
|
|
||||||
#ifdef __cplusplus |
|
||||||
extern "C" { |
|
||||||
#endif |
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/ |
|
||||||
#include "usbd_conf.h" |
|
||||||
|
|
||||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USB_INFO
|
|
||||||
* @brief general defines for the usb device library file |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USB_INFO_Exported_Defines
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
#define MODE_SENSE6_LEN 0x17U |
|
||||||
#define MODE_SENSE10_LEN 0x1BU |
|
||||||
#define LENGTH_INQUIRY_PAGE00 0x06U |
|
||||||
#define LENGTH_INQUIRY_PAGE80 0x08U |
|
||||||
#define LENGTH_FORMAT_CAPACITIES 0x14U |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup USBD_INFO_Exported_TypesDefinitions
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup USBD_INFO_Exported_Macros
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_INFO_Exported_Variables
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
extern uint8_t MSC_Page00_Inquiry_Data[LENGTH_INQUIRY_PAGE00]; |
|
||||||
extern uint8_t MSC_Page80_Inquiry_Data[LENGTH_INQUIRY_PAGE80]; |
|
||||||
extern uint8_t MSC_Mode_Sense6_data[MODE_SENSE6_LEN]; |
|
||||||
extern uint8_t MSC_Mode_Sense10_data[MODE_SENSE10_LEN]; |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_INFO_Exported_FunctionsPrototype
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
#ifdef __cplusplus |
|
||||||
} |
|
||||||
#endif |
|
||||||
|
|
||||||
#endif /* __USBD_MSC_DATA_H */ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
@ -1,182 +0,0 @@ |
|||||||
/**
|
|
||||||
****************************************************************************** |
|
||||||
* @file usbd_msc_scsi.h |
|
||||||
* @author MCD Application Team |
|
||||||
* @brief Header for the usbd_msc_scsi.c file |
|
||||||
****************************************************************************** |
|
||||||
* @attention |
|
||||||
* |
|
||||||
* Copyright (c) 2015 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. |
|
||||||
* |
|
||||||
****************************************************************************** |
|
||||||
*/ |
|
||||||
|
|
||||||
/* Define to prevent recursive inclusion -------------------------------------*/ |
|
||||||
#ifndef __USBD_MSC_SCSI_H |
|
||||||
#define __USBD_MSC_SCSI_H |
|
||||||
|
|
||||||
#ifdef __cplusplus |
|
||||||
extern "C" { |
|
||||||
#endif |
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/ |
|
||||||
#include "usbd_def.h" |
|
||||||
|
|
||||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_SCSI
|
|
||||||
* @brief header file for the storage disk file |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_SCSI_Exported_Defines
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
#define SENSE_LIST_DEEPTH 4U |
|
||||||
|
|
||||||
/* SCSI Commands */ |
|
||||||
#define SCSI_FORMAT_UNIT 0x04U |
|
||||||
#define SCSI_INQUIRY 0x12U |
|
||||||
#define SCSI_MODE_SELECT6 0x15U |
|
||||||
#define SCSI_MODE_SELECT10 0x55U |
|
||||||
#define SCSI_MODE_SENSE6 0x1AU |
|
||||||
#define SCSI_MODE_SENSE10 0x5AU |
|
||||||
#define SCSI_ALLOW_MEDIUM_REMOVAL 0x1EU |
|
||||||
#define SCSI_READ6 0x08U |
|
||||||
#define SCSI_READ10 0x28U |
|
||||||
#define SCSI_READ12 0xA8U |
|
||||||
#define SCSI_READ16 0x88U |
|
||||||
|
|
||||||
#define SCSI_READ_CAPACITY10 0x25U |
|
||||||
#define SCSI_READ_CAPACITY16 0x9EU |
|
||||||
|
|
||||||
#define SCSI_REQUEST_SENSE 0x03U |
|
||||||
#define SCSI_START_STOP_UNIT 0x1BU |
|
||||||
#define SCSI_TEST_UNIT_READY 0x00U |
|
||||||
#define SCSI_WRITE6 0x0AU |
|
||||||
#define SCSI_WRITE10 0x2AU |
|
||||||
#define SCSI_WRITE12 0xAAU |
|
||||||
#define SCSI_WRITE16 0x8AU |
|
||||||
|
|
||||||
#define SCSI_VERIFY10 0x2FU |
|
||||||
#define SCSI_VERIFY12 0xAFU |
|
||||||
#define SCSI_VERIFY16 0x8FU |
|
||||||
|
|
||||||
#define SCSI_SEND_DIAGNOSTIC 0x1DU |
|
||||||
#define SCSI_READ_FORMAT_CAPACITIES 0x23U |
|
||||||
|
|
||||||
#define NO_SENSE 0U |
|
||||||
#define RECOVERED_ERROR 1U |
|
||||||
#define NOT_READY 2U |
|
||||||
#define MEDIUM_ERROR 3U |
|
||||||
#define HARDWARE_ERROR 4U |
|
||||||
#define ILLEGAL_REQUEST 5U |
|
||||||
#define UNIT_ATTENTION 6U |
|
||||||
#define DATA_PROTECT 7U |
|
||||||
#define BLANK_CHECK 8U |
|
||||||
#define VENDOR_SPECIFIC 9U |
|
||||||
#define COPY_ABORTED 10U |
|
||||||
#define ABORTED_COMMAND 11U |
|
||||||
#define VOLUME_OVERFLOW 13U |
|
||||||
#define MISCOMPARE 14U |
|
||||||
|
|
||||||
|
|
||||||
#define INVALID_CDB 0x20U |
|
||||||
#define INVALID_FIELED_IN_COMMAND 0x24U |
|
||||||
#define PARAMETER_LIST_LENGTH_ERROR 0x1AU |
|
||||||
#define INVALID_FIELD_IN_PARAMETER_LIST 0x26U |
|
||||||
#define ADDRESS_OUT_OF_RANGE 0x21U |
|
||||||
#define MEDIUM_NOT_PRESENT 0x3AU |
|
||||||
#define MEDIUM_HAVE_CHANGED 0x28U |
|
||||||
#define WRITE_PROTECTED 0x27U |
|
||||||
#define UNRECOVERED_READ_ERROR 0x11U |
|
||||||
#define WRITE_FAULT 0x03U |
|
||||||
|
|
||||||
#define READ_FORMAT_CAPACITY_DATA_LEN 0x0CU |
|
||||||
#define READ_CAPACITY10_DATA_LEN 0x08U |
|
||||||
#define REQUEST_SENSE_DATA_LEN 0x12U |
|
||||||
#define STANDARD_INQUIRY_DATA_LEN 0x24U |
|
||||||
#define BLKVFY 0x04U |
|
||||||
|
|
||||||
#define SCSI_MEDIUM_UNLOCKED 0x00U |
|
||||||
#define SCSI_MEDIUM_LOCKED 0x01U |
|
||||||
#define SCSI_MEDIUM_EJECTED 0x02U |
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup USBD_SCSI_Exported_TypesDefinitions
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
typedef struct _SENSE_ITEM |
|
||||||
{ |
|
||||||
uint8_t Skey; |
|
||||||
union |
|
||||||
{ |
|
||||||
struct _ASCs |
|
||||||
{ |
|
||||||
uint8_t ASC; |
|
||||||
uint8_t ASCQ; |
|
||||||
} b; |
|
||||||
uint8_t ASC; |
|
||||||
uint8_t *pData; |
|
||||||
} w; |
|
||||||
} USBD_SCSI_SenseTypeDef; |
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_SCSI_Exported_Macros
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_SCSI_Exported_Variables
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
/** @defgroup USBD_SCSI_Exported_FunctionsPrototype
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
int8_t SCSI_ProcessCmd(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *cmd); |
|
||||||
|
|
||||||
void SCSI_SenseCode(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t sKey, |
|
||||||
uint8_t ASC); |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
#ifdef __cplusplus |
|
||||||
} |
|
||||||
#endif |
|
||||||
|
|
||||||
#endif /* __USBD_MSC_SCSI_H */ |
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
@ -1,579 +0,0 @@ |
|||||||
/**
|
|
||||||
****************************************************************************** |
|
||||||
* @file usbd_msc.c |
|
||||||
* @author MCD Application Team |
|
||||||
* @brief This file provides all the MSC core functions. |
|
||||||
* |
|
||||||
****************************************************************************** |
|
||||||
* @attention |
|
||||||
* |
|
||||||
* Copyright (c) 2015 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. |
|
||||||
* |
|
||||||
****************************************************************************** |
|
||||||
* @verbatim |
|
||||||
* |
|
||||||
* =================================================================== |
|
||||||
* MSC Class Description |
|
||||||
* =================================================================== |
|
||||||
* This module manages the MSC class V1.0 following the "Universal |
|
||||||
* Serial Bus Mass Storage Class (MSC) Bulk-Only Transport (BOT) Version 1.0 |
|
||||||
* Sep. 31, 1999". |
|
||||||
* This driver implements the following aspects of the specification: |
|
||||||
* - Bulk-Only Transport protocol |
|
||||||
* - Subclass : SCSI transparent command set (ref. SCSI Primary Commands - 3 (SPC-3)) |
|
||||||
* |
|
||||||
* @endverbatim |
|
||||||
* |
|
||||||
****************************************************************************** |
|
||||||
*/ |
|
||||||
|
|
||||||
/* BSPDependencies
|
|
||||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" |
|
||||||
- "stm32xxxxx_{eval}{discovery}_io.c" |
|
||||||
- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c" |
|
||||||
EndBSPDependencies */ |
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/ |
|
||||||
#include "usbd_msc.h" |
|
||||||
|
|
||||||
|
|
||||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup MSC_CORE
|
|
||||||
* @brief Mass storage core module |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup MSC_CORE_Private_TypesDefinitions
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup MSC_CORE_Private_Defines
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup MSC_CORE_Private_Macros
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup MSC_CORE_Private_FunctionPrototypes
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
uint8_t USBD_MSC_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx); |
|
||||||
uint8_t USBD_MSC_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx); |
|
||||||
uint8_t USBD_MSC_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); |
|
||||||
uint8_t USBD_MSC_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum); |
|
||||||
uint8_t USBD_MSC_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum); |
|
||||||
|
|
||||||
#ifndef USE_USBD_COMPOSITE |
|
||||||
uint8_t *USBD_MSC_GetHSCfgDesc(uint16_t *length); |
|
||||||
uint8_t *USBD_MSC_GetFSCfgDesc(uint16_t *length); |
|
||||||
uint8_t *USBD_MSC_GetOtherSpeedCfgDesc(uint16_t *length); |
|
||||||
uint8_t *USBD_MSC_GetDeviceQualifierDescriptor(uint16_t *length); |
|
||||||
#endif /* USE_USBD_COMPOSITE */ |
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup MSC_CORE_Private_Variables
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
USBD_ClassTypeDef USBD_MSC = |
|
||||||
{ |
|
||||||
USBD_MSC_Init, |
|
||||||
USBD_MSC_DeInit, |
|
||||||
USBD_MSC_Setup, |
|
||||||
NULL, /*EP0_TxSent*/ |
|
||||||
NULL, /*EP0_RxReady*/ |
|
||||||
USBD_MSC_DataIn, |
|
||||||
USBD_MSC_DataOut, |
|
||||||
NULL, /*SOF */ |
|
||||||
NULL, |
|
||||||
NULL, |
|
||||||
#ifdef USE_USBD_COMPOSITE |
|
||||||
NULL, |
|
||||||
NULL, |
|
||||||
NULL, |
|
||||||
NULL, |
|
||||||
#else |
|
||||||
USBD_MSC_GetHSCfgDesc, |
|
||||||
USBD_MSC_GetFSCfgDesc, |
|
||||||
USBD_MSC_GetOtherSpeedCfgDesc, |
|
||||||
USBD_MSC_GetDeviceQualifierDescriptor, |
|
||||||
#endif /* USE_USBD_COMPOSITE */ |
|
||||||
}; |
|
||||||
|
|
||||||
/* USB Mass storage device Configuration Descriptor */ |
|
||||||
#ifndef USE_USBD_COMPOSITE |
|
||||||
/* USB Mass storage device Configuration Descriptor */ |
|
||||||
/* All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */ |
|
||||||
__ALIGN_BEGIN static uint8_t USBD_MSC_CfgDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END = |
|
||||||
{ |
|
||||||
0x09, /* bLength: Configuration Descriptor size */ |
|
||||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */ |
|
||||||
USB_MSC_CONFIG_DESC_SIZ, |
|
||||||
|
|
||||||
0x00, |
|
||||||
0x01, /* bNumInterfaces: 1 interface */ |
|
||||||
0x01, /* bConfigurationValue */ |
|
||||||
0x04, /* iConfiguration */ |
|
||||||
#if (USBD_SELF_POWERED == 1U) |
|
||||||
0xC0, /* bmAttributes: Bus Powered according to user configuration */ |
|
||||||
#else |
|
||||||
0x80, /* bmAttributes: Bus Powered according to user configuration */ |
|
||||||
#endif /* USBD_SELF_POWERED */ |
|
||||||
USBD_MAX_POWER, /* MaxPower (mA) */ |
|
||||||
|
|
||||||
/******************** Mass Storage interface ********************/ |
|
||||||
0x09, /* bLength: Interface Descriptor size */ |
|
||||||
0x04, /* bDescriptorType: */ |
|
||||||
0x00, /* bInterfaceNumber: Number of Interface */ |
|
||||||
0x00, /* bAlternateSetting: Alternate setting */ |
|
||||||
0x02, /* bNumEndpoints */ |
|
||||||
0x08, /* bInterfaceClass: MSC Class */ |
|
||||||
0x06, /* bInterfaceSubClass : SCSI transparent*/ |
|
||||||
0x50, /* nInterfaceProtocol */ |
|
||||||
0x05, /* iInterface: */ |
|
||||||
/******************** Mass Storage Endpoints ********************/ |
|
||||||
0x07, /* Endpoint descriptor length = 7 */ |
|
||||||
0x05, /* Endpoint descriptor type */ |
|
||||||
MSC_EPIN_ADDR, /* Endpoint address (IN, address 1) */ |
|
||||||
0x02, /* Bulk endpoint type */ |
|
||||||
LOBYTE(MSC_MAX_FS_PACKET), |
|
||||||
HIBYTE(MSC_MAX_FS_PACKET), |
|
||||||
0x00, /* Polling interval in milliseconds */ |
|
||||||
|
|
||||||
0x07, /* Endpoint descriptor length = 7 */ |
|
||||||
0x05, /* Endpoint descriptor type */ |
|
||||||
MSC_EPOUT_ADDR, /* Endpoint address (OUT, address 1) */ |
|
||||||
0x02, /* Bulk endpoint type */ |
|
||||||
LOBYTE(MSC_MAX_FS_PACKET), |
|
||||||
HIBYTE(MSC_MAX_FS_PACKET), |
|
||||||
0x00 /* Polling interval in milliseconds */ |
|
||||||
}; |
|
||||||
|
|
||||||
/* USB Standard Device Descriptor */ |
|
||||||
__ALIGN_BEGIN static uint8_t USBD_MSC_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END = |
|
||||||
{ |
|
||||||
USB_LEN_DEV_QUALIFIER_DESC, |
|
||||||
USB_DESC_TYPE_DEVICE_QUALIFIER, |
|
||||||
0x00, |
|
||||||
0x02, |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
MSC_MAX_FS_PACKET, |
|
||||||
0x01, |
|
||||||
0x00, |
|
||||||
}; |
|
||||||
#endif /* USE_USBD_COMPOSITE */ |
|
||||||
|
|
||||||
uint8_t MSCInEpAdd = MSC_EPIN_ADDR; |
|
||||||
uint8_t MSCOutEpAdd = MSC_EPOUT_ADDR; |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup MSC_CORE_Private_Functions
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief USBD_MSC_Init |
|
||||||
* Initialize the mass storage configuration |
|
||||||
* @param pdev: device instance |
|
||||||
* @param cfgidx: configuration index |
|
||||||
* @retval status |
|
||||||
*/ |
|
||||||
uint8_t USBD_MSC_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx) |
|
||||||
{ |
|
||||||
UNUSED(cfgidx); |
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc; |
|
||||||
|
|
||||||
hmsc = (USBD_MSC_BOT_HandleTypeDef *)USBD_malloc(sizeof(USBD_MSC_BOT_HandleTypeDef)); |
|
||||||
|
|
||||||
if (hmsc == NULL) |
|
||||||
{ |
|
||||||
pdev->pClassDataCmsit[pdev->classId] = NULL; |
|
||||||
return (uint8_t)USBD_EMEM; |
|
||||||
} |
|
||||||
|
|
||||||
pdev->pClassDataCmsit[pdev->classId] = (void *)hmsc; |
|
||||||
pdev->pClassData = pdev->pClassDataCmsit[pdev->classId]; |
|
||||||
|
|
||||||
#ifdef USE_USBD_COMPOSITE |
|
||||||
/* Get the Endpoints addresses allocated for this class instance */ |
|
||||||
MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK); |
|
||||||
MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK); |
|
||||||
#endif /* USE_USBD_COMPOSITE */ |
|
||||||
|
|
||||||
if (pdev->dev_speed == USBD_SPEED_HIGH) |
|
||||||
{ |
|
||||||
/* Open EP OUT */ |
|
||||||
(void)USBD_LL_OpenEP(pdev, MSCOutEpAdd, USBD_EP_TYPE_BULK, MSC_MAX_HS_PACKET); |
|
||||||
pdev->ep_out[MSCOutEpAdd & 0xFU].is_used = 1U; |
|
||||||
|
|
||||||
/* Open EP IN */ |
|
||||||
(void)USBD_LL_OpenEP(pdev, MSCInEpAdd, USBD_EP_TYPE_BULK, MSC_MAX_HS_PACKET); |
|
||||||
pdev->ep_in[MSCInEpAdd & 0xFU].is_used = 1U; |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
/* Open EP OUT */ |
|
||||||
(void)USBD_LL_OpenEP(pdev, MSCOutEpAdd, USBD_EP_TYPE_BULK, MSC_MAX_FS_PACKET); |
|
||||||
pdev->ep_out[MSCOutEpAdd & 0xFU].is_used = 1U; |
|
||||||
|
|
||||||
/* Open EP IN */ |
|
||||||
(void)USBD_LL_OpenEP(pdev, MSCInEpAdd, USBD_EP_TYPE_BULK, MSC_MAX_FS_PACKET); |
|
||||||
pdev->ep_in[MSCInEpAdd & 0xFU].is_used = 1U; |
|
||||||
} |
|
||||||
|
|
||||||
/* Init the BOT layer */ |
|
||||||
MSC_BOT_Init(pdev); |
|
||||||
|
|
||||||
return (uint8_t)USBD_OK; |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief USBD_MSC_DeInit |
|
||||||
* DeInitialize the mass storage configuration |
|
||||||
* @param pdev: device instance |
|
||||||
* @param cfgidx: configuration index |
|
||||||
* @retval status |
|
||||||
*/ |
|
||||||
uint8_t USBD_MSC_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx) |
|
||||||
{ |
|
||||||
UNUSED(cfgidx); |
|
||||||
|
|
||||||
#ifdef USE_USBD_COMPOSITE |
|
||||||
/* Get the Endpoints addresses allocated for this class instance */ |
|
||||||
MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK); |
|
||||||
MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK); |
|
||||||
#endif /* USE_USBD_COMPOSITE */ |
|
||||||
|
|
||||||
/* Close MSC EPs */ |
|
||||||
(void)USBD_LL_CloseEP(pdev, MSCOutEpAdd); |
|
||||||
pdev->ep_out[MSCOutEpAdd & 0xFU].is_used = 0U; |
|
||||||
|
|
||||||
/* Close EP IN */ |
|
||||||
(void)USBD_LL_CloseEP(pdev, MSCInEpAdd); |
|
||||||
pdev->ep_in[MSCInEpAdd & 0xFU].is_used = 0U; |
|
||||||
|
|
||||||
/* Free MSC Class Resources */ |
|
||||||
if (pdev->pClassDataCmsit[pdev->classId] != NULL) |
|
||||||
{ |
|
||||||
/* De-Init the BOT layer */ |
|
||||||
MSC_BOT_DeInit(pdev); |
|
||||||
|
|
||||||
(void)USBD_free(pdev->pClassDataCmsit[pdev->classId]); |
|
||||||
pdev->pClassDataCmsit[pdev->classId] = NULL; |
|
||||||
pdev->pClassData = NULL; |
|
||||||
} |
|
||||||
|
|
||||||
return (uint8_t)USBD_OK; |
|
||||||
} |
|
||||||
/**
|
|
||||||
* @brief USBD_MSC_Setup |
|
||||||
* Handle the MSC specific requests |
|
||||||
* @param pdev: device instance |
|
||||||
* @param req: USB request |
|
||||||
* @retval status |
|
||||||
*/ |
|
||||||
uint8_t USBD_MSC_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) |
|
||||||
{ |
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; |
|
||||||
USBD_StatusTypeDef ret = USBD_OK; |
|
||||||
uint16_t status_info = 0U; |
|
||||||
|
|
||||||
#ifdef USE_USBD_COMPOSITE |
|
||||||
/* Get the Endpoints addresses allocated for this class instance */ |
|
||||||
MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK); |
|
||||||
MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK); |
|
||||||
#endif /* USE_USBD_COMPOSITE */ |
|
||||||
|
|
||||||
if (hmsc == NULL) |
|
||||||
{ |
|
||||||
return (uint8_t)USBD_FAIL; |
|
||||||
} |
|
||||||
|
|
||||||
switch (req->bmRequest & USB_REQ_TYPE_MASK) |
|
||||||
{ |
|
||||||
/* Class request */ |
|
||||||
case USB_REQ_TYPE_CLASS: |
|
||||||
switch (req->bRequest) |
|
||||||
{ |
|
||||||
case BOT_GET_MAX_LUN: |
|
||||||
if ((req->wValue == 0U) && (req->wLength == 1U) && |
|
||||||
((req->bmRequest & 0x80U) == 0x80U)) |
|
||||||
{ |
|
||||||
hmsc->max_lun = (uint32_t)((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->GetMaxLun(); |
|
||||||
(void)USBD_CtlSendData(pdev, (uint8_t *)&hmsc->max_lun, 1U); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
USBD_CtlError(pdev, req); |
|
||||||
ret = USBD_FAIL; |
|
||||||
} |
|
||||||
break; |
|
||||||
|
|
||||||
case BOT_RESET : |
|
||||||
if ((req->wValue == 0U) && (req->wLength == 0U) && |
|
||||||
((req->bmRequest & 0x80U) != 0x80U)) |
|
||||||
{ |
|
||||||
MSC_BOT_Reset(pdev); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
USBD_CtlError(pdev, req); |
|
||||||
ret = USBD_FAIL; |
|
||||||
} |
|
||||||
break; |
|
||||||
|
|
||||||
default: |
|
||||||
USBD_CtlError(pdev, req); |
|
||||||
ret = USBD_FAIL; |
|
||||||
break; |
|
||||||
} |
|
||||||
break; |
|
||||||
/* Interface & Endpoint request */ |
|
||||||
case USB_REQ_TYPE_STANDARD: |
|
||||||
switch (req->bRequest) |
|
||||||
{ |
|
||||||
case USB_REQ_GET_STATUS: |
|
||||||
if (pdev->dev_state == USBD_STATE_CONFIGURED) |
|
||||||
{ |
|
||||||
(void)USBD_CtlSendData(pdev, (uint8_t *)&status_info, 2U); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
USBD_CtlError(pdev, req); |
|
||||||
ret = USBD_FAIL; |
|
||||||
} |
|
||||||
break; |
|
||||||
|
|
||||||
case USB_REQ_GET_INTERFACE: |
|
||||||
if (pdev->dev_state == USBD_STATE_CONFIGURED) |
|
||||||
{ |
|
||||||
(void)USBD_CtlSendData(pdev, (uint8_t *)&hmsc->interface, 1U); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
USBD_CtlError(pdev, req); |
|
||||||
ret = USBD_FAIL; |
|
||||||
} |
|
||||||
break; |
|
||||||
|
|
||||||
case USB_REQ_SET_INTERFACE: |
|
||||||
if (pdev->dev_state == USBD_STATE_CONFIGURED) |
|
||||||
{ |
|
||||||
hmsc->interface = (uint8_t)(req->wValue); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
USBD_CtlError(pdev, req); |
|
||||||
ret = USBD_FAIL; |
|
||||||
} |
|
||||||
break; |
|
||||||
|
|
||||||
case USB_REQ_CLEAR_FEATURE: |
|
||||||
if (pdev->dev_state == USBD_STATE_CONFIGURED) |
|
||||||
{ |
|
||||||
if (req->wValue == USB_FEATURE_EP_HALT) |
|
||||||
{ |
|
||||||
/* Flush the FIFO */ |
|
||||||
(void)USBD_LL_FlushEP(pdev, (uint8_t)req->wIndex); |
|
||||||
|
|
||||||
/* Handle BOT error */ |
|
||||||
MSC_BOT_CplClrFeature(pdev, (uint8_t)req->wIndex); |
|
||||||
} |
|
||||||
} |
|
||||||
break; |
|
||||||
|
|
||||||
default: |
|
||||||
USBD_CtlError(pdev, req); |
|
||||||
ret = USBD_FAIL; |
|
||||||
break; |
|
||||||
} |
|
||||||
break; |
|
||||||
|
|
||||||
default: |
|
||||||
USBD_CtlError(pdev, req); |
|
||||||
ret = USBD_FAIL; |
|
||||||
break; |
|
||||||
} |
|
||||||
|
|
||||||
return (uint8_t)ret; |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief USBD_MSC_DataIn |
|
||||||
* handle data IN Stage |
|
||||||
* @param pdev: device instance |
|
||||||
* @param epnum: endpoint index |
|
||||||
* @retval status |
|
||||||
*/ |
|
||||||
uint8_t USBD_MSC_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum) |
|
||||||
{ |
|
||||||
MSC_BOT_DataIn(pdev, epnum); |
|
||||||
|
|
||||||
return (uint8_t)USBD_OK; |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief USBD_MSC_DataOut |
|
||||||
* handle data OUT Stage |
|
||||||
* @param pdev: device instance |
|
||||||
* @param epnum: endpoint index |
|
||||||
* @retval status |
|
||||||
*/ |
|
||||||
uint8_t USBD_MSC_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum) |
|
||||||
{ |
|
||||||
MSC_BOT_DataOut(pdev, epnum); |
|
||||||
|
|
||||||
return (uint8_t)USBD_OK; |
|
||||||
} |
|
||||||
#ifndef USE_USBD_COMPOSITE |
|
||||||
/**
|
|
||||||
* @brief USBD_MSC_GetHSCfgDesc |
|
||||||
* return configuration descriptor |
|
||||||
* @param length : pointer data length |
|
||||||
* @retval pointer to descriptor buffer |
|
||||||
*/ |
|
||||||
uint8_t *USBD_MSC_GetHSCfgDesc(uint16_t *length) |
|
||||||
{ |
|
||||||
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_MSC_CfgDesc, MSC_EPIN_ADDR); |
|
||||||
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_MSC_CfgDesc, MSC_EPOUT_ADDR); |
|
||||||
|
|
||||||
if (pEpInDesc != NULL) |
|
||||||
{ |
|
||||||
pEpInDesc->wMaxPacketSize = MSC_MAX_HS_PACKET; |
|
||||||
} |
|
||||||
|
|
||||||
if (pEpOutDesc != NULL) |
|
||||||
{ |
|
||||||
pEpOutDesc->wMaxPacketSize = MSC_MAX_HS_PACKET; |
|
||||||
} |
|
||||||
|
|
||||||
*length = (uint16_t)sizeof(USBD_MSC_CfgDesc); |
|
||||||
return USBD_MSC_CfgDesc; |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief USBD_MSC_GetFSCfgDesc |
|
||||||
* return configuration descriptor |
|
||||||
* @param length : pointer data length |
|
||||||
* @retval pointer to descriptor buffer |
|
||||||
*/ |
|
||||||
uint8_t *USBD_MSC_GetFSCfgDesc(uint16_t *length) |
|
||||||
{ |
|
||||||
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_MSC_CfgDesc, MSC_EPIN_ADDR); |
|
||||||
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_MSC_CfgDesc, MSC_EPOUT_ADDR); |
|
||||||
|
|
||||||
if (pEpInDesc != NULL) |
|
||||||
{ |
|
||||||
pEpInDesc->wMaxPacketSize = MSC_MAX_FS_PACKET; |
|
||||||
} |
|
||||||
|
|
||||||
if (pEpOutDesc != NULL) |
|
||||||
{ |
|
||||||
pEpOutDesc->wMaxPacketSize = MSC_MAX_FS_PACKET; |
|
||||||
} |
|
||||||
|
|
||||||
*length = (uint16_t)sizeof(USBD_MSC_CfgDesc); |
|
||||||
return USBD_MSC_CfgDesc; |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief USBD_MSC_GetOtherSpeedCfgDesc |
|
||||||
* return other speed configuration descriptor |
|
||||||
* @param length : pointer data length |
|
||||||
* @retval pointer to descriptor buffer |
|
||||||
*/ |
|
||||||
uint8_t *USBD_MSC_GetOtherSpeedCfgDesc(uint16_t *length) |
|
||||||
{ |
|
||||||
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_MSC_CfgDesc, MSC_EPIN_ADDR); |
|
||||||
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_MSC_CfgDesc, MSC_EPOUT_ADDR); |
|
||||||
|
|
||||||
if (pEpInDesc != NULL) |
|
||||||
{ |
|
||||||
pEpInDesc->wMaxPacketSize = MSC_MAX_FS_PACKET; |
|
||||||
} |
|
||||||
|
|
||||||
if (pEpOutDesc != NULL) |
|
||||||
{ |
|
||||||
pEpOutDesc->wMaxPacketSize = MSC_MAX_FS_PACKET; |
|
||||||
} |
|
||||||
|
|
||||||
*length = (uint16_t)sizeof(USBD_MSC_CfgDesc); |
|
||||||
return USBD_MSC_CfgDesc; |
|
||||||
} |
|
||||||
/**
|
|
||||||
* @brief DeviceQualifierDescriptor |
|
||||||
* return Device Qualifier descriptor |
|
||||||
* @param length : pointer data length |
|
||||||
* @retval pointer to descriptor buffer |
|
||||||
*/ |
|
||||||
uint8_t *USBD_MSC_GetDeviceQualifierDescriptor(uint16_t *length) |
|
||||||
{ |
|
||||||
*length = (uint16_t)sizeof(USBD_MSC_DeviceQualifierDesc); |
|
||||||
|
|
||||||
return USBD_MSC_DeviceQualifierDesc; |
|
||||||
} |
|
||||||
#endif /* USE_USBD_COMPOSITE */ |
|
||||||
/**
|
|
||||||
* @brief USBD_MSC_RegisterStorage |
|
||||||
* @param fops: storage callback |
|
||||||
* @retval status |
|
||||||
*/ |
|
||||||
uint8_t USBD_MSC_RegisterStorage(USBD_HandleTypeDef *pdev, USBD_StorageTypeDef *fops) |
|
||||||
{ |
|
||||||
if (fops == NULL) |
|
||||||
{ |
|
||||||
return (uint8_t)USBD_FAIL; |
|
||||||
} |
|
||||||
|
|
||||||
pdev->pUserData[pdev->classId] = fops; |
|
||||||
|
|
||||||
return (uint8_t)USBD_OK; |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
@ -1,478 +0,0 @@ |
|||||||
/**
|
|
||||||
****************************************************************************** |
|
||||||
* @file usbd_msc_bot.c |
|
||||||
* @author MCD Application Team |
|
||||||
* @brief This file provides all the BOT protocol core functions. |
|
||||||
****************************************************************************** |
|
||||||
* @attention |
|
||||||
* |
|
||||||
* Copyright (c) 2015 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. |
|
||||||
* |
|
||||||
****************************************************************************** |
|
||||||
*/ |
|
||||||
|
|
||||||
/* BSPDependencies
|
|
||||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" |
|
||||||
- "stm32xxxxx_{eval}{discovery}_io.c" |
|
||||||
- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c" |
|
||||||
EndBSPDependencies */ |
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/ |
|
||||||
#include "usbd_msc_bot.h" |
|
||||||
#include "usbd_msc.h" |
|
||||||
#include "usbd_msc_scsi.h" |
|
||||||
#include "usbd_ioreq.h" |
|
||||||
|
|
||||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup MSC_BOT
|
|
||||||
* @brief BOT protocol module |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup MSC_BOT_Private_TypesDefinitions
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup MSC_BOT_Private_Defines
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup MSC_BOT_Private_Macros
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup MSC_BOT_Private_Variables
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
extern uint8_t MSCInEpAdd; |
|
||||||
extern uint8_t MSCOutEpAdd; |
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup MSC_BOT_Private_FunctionPrototypes
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
static void MSC_BOT_SendData(USBD_HandleTypeDef *pdev, uint8_t *pbuf, uint32_t len); |
|
||||||
static void MSC_BOT_CBW_Decode(USBD_HandleTypeDef *pdev); |
|
||||||
static void MSC_BOT_Abort(USBD_HandleTypeDef *pdev); |
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup MSC_BOT_Private_Functions
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief MSC_BOT_Init |
|
||||||
* Initialize the BOT Process |
|
||||||
* @param pdev: device instance |
|
||||||
* @retval None |
|
||||||
*/ |
|
||||||
void MSC_BOT_Init(USBD_HandleTypeDef *pdev) |
|
||||||
{ |
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; |
|
||||||
|
|
||||||
#ifdef USE_USBD_COMPOSITE |
|
||||||
/* Get the Endpoints addresses allocated for this class instance */ |
|
||||||
MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK); |
|
||||||
MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK); |
|
||||||
#endif /* USE_USBD_COMPOSITE */ |
|
||||||
|
|
||||||
if (hmsc == NULL) |
|
||||||
{ |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
hmsc->bot_state = USBD_BOT_IDLE; |
|
||||||
hmsc->bot_status = USBD_BOT_STATUS_NORMAL; |
|
||||||
|
|
||||||
hmsc->scsi_sense_tail = 0U; |
|
||||||
hmsc->scsi_sense_head = 0U; |
|
||||||
hmsc->scsi_medium_state = SCSI_MEDIUM_UNLOCKED; |
|
||||||
|
|
||||||
((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->Init(0U); |
|
||||||
|
|
||||||
(void)USBD_LL_FlushEP(pdev, MSCOutEpAdd); |
|
||||||
(void)USBD_LL_FlushEP(pdev, MSCInEpAdd); |
|
||||||
|
|
||||||
/* Prepare EP to Receive First BOT Cmd */ |
|
||||||
(void)USBD_LL_PrepareReceive(pdev, MSCOutEpAdd, (uint8_t *)&hmsc->cbw, |
|
||||||
USBD_BOT_CBW_LENGTH); |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief MSC_BOT_Reset |
|
||||||
* Reset the BOT Machine |
|
||||||
* @param pdev: device instance |
|
||||||
* @retval None |
|
||||||
*/ |
|
||||||
void MSC_BOT_Reset(USBD_HandleTypeDef *pdev) |
|
||||||
{ |
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; |
|
||||||
|
|
||||||
#ifdef USE_USBD_COMPOSITE |
|
||||||
/* Get the Endpoints addresses allocated for this class instance */ |
|
||||||
MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK); |
|
||||||
MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK); |
|
||||||
#endif /* USE_USBD_COMPOSITE */ |
|
||||||
|
|
||||||
if (hmsc == NULL) |
|
||||||
{ |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
hmsc->bot_state = USBD_BOT_IDLE; |
|
||||||
hmsc->bot_status = USBD_BOT_STATUS_RECOVERY; |
|
||||||
|
|
||||||
(void)USBD_LL_ClearStallEP(pdev, MSCInEpAdd); |
|
||||||
(void)USBD_LL_ClearStallEP(pdev, MSCOutEpAdd); |
|
||||||
|
|
||||||
/* Prepare EP to Receive First BOT Cmd */ |
|
||||||
(void)USBD_LL_PrepareReceive(pdev, MSCOutEpAdd, (uint8_t *)&hmsc->cbw, |
|
||||||
USBD_BOT_CBW_LENGTH); |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief MSC_BOT_DeInit |
|
||||||
* DeInitialize the BOT Machine |
|
||||||
* @param pdev: device instance |
|
||||||
* @retval None |
|
||||||
*/ |
|
||||||
void MSC_BOT_DeInit(USBD_HandleTypeDef *pdev) |
|
||||||
{ |
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; |
|
||||||
|
|
||||||
if (hmsc != NULL) |
|
||||||
{ |
|
||||||
hmsc->bot_state = USBD_BOT_IDLE; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief MSC_BOT_DataIn |
|
||||||
* Handle BOT IN data stage |
|
||||||
* @param pdev: device instance |
|
||||||
* @param epnum: endpoint index |
|
||||||
* @retval None |
|
||||||
*/ |
|
||||||
void MSC_BOT_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum) |
|
||||||
{ |
|
||||||
UNUSED(epnum); |
|
||||||
|
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; |
|
||||||
|
|
||||||
if (hmsc == NULL) |
|
||||||
{ |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
switch (hmsc->bot_state) |
|
||||||
{ |
|
||||||
case USBD_BOT_DATA_IN: |
|
||||||
if (SCSI_ProcessCmd(pdev, hmsc->cbw.bLUN, &hmsc->cbw.CB[0]) < 0) |
|
||||||
{ |
|
||||||
MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_FAILED); |
|
||||||
} |
|
||||||
break; |
|
||||||
|
|
||||||
case USBD_BOT_SEND_DATA: |
|
||||||
case USBD_BOT_LAST_DATA_IN: |
|
||||||
MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_PASSED); |
|
||||||
break; |
|
||||||
|
|
||||||
default: |
|
||||||
break; |
|
||||||
} |
|
||||||
} |
|
||||||
/**
|
|
||||||
* @brief MSC_BOT_DataOut |
|
||||||
* Process MSC OUT data |
|
||||||
* @param pdev: device instance |
|
||||||
* @param epnum: endpoint index |
|
||||||
* @retval None |
|
||||||
*/ |
|
||||||
void MSC_BOT_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum) |
|
||||||
{ |
|
||||||
UNUSED(epnum); |
|
||||||
|
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; |
|
||||||
|
|
||||||
if (hmsc == NULL) |
|
||||||
{ |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
switch (hmsc->bot_state) |
|
||||||
{ |
|
||||||
case USBD_BOT_IDLE: |
|
||||||
MSC_BOT_CBW_Decode(pdev); |
|
||||||
break; |
|
||||||
|
|
||||||
case USBD_BOT_DATA_OUT: |
|
||||||
if (SCSI_ProcessCmd(pdev, hmsc->cbw.bLUN, &hmsc->cbw.CB[0]) < 0) |
|
||||||
{ |
|
||||||
MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_FAILED); |
|
||||||
} |
|
||||||
break; |
|
||||||
|
|
||||||
default: |
|
||||||
break; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief MSC_BOT_CBW_Decode |
|
||||||
* Decode the CBW command and set the BOT state machine accordingly |
|
||||||
* @param pdev: device instance |
|
||||||
* @retval None |
|
||||||
*/ |
|
||||||
static void MSC_BOT_CBW_Decode(USBD_HandleTypeDef *pdev) |
|
||||||
{ |
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; |
|
||||||
|
|
||||||
#ifdef USE_USBD_COMPOSITE |
|
||||||
/* Get the Endpoints addresses allocated for this class instance */ |
|
||||||
MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK); |
|
||||||
MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK); |
|
||||||
#endif /* USE_USBD_COMPOSITE */ |
|
||||||
|
|
||||||
if (hmsc == NULL) |
|
||||||
{ |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
hmsc->csw.dTag = hmsc->cbw.dTag; |
|
||||||
hmsc->csw.dDataResidue = hmsc->cbw.dDataLength; |
|
||||||
|
|
||||||
if ((USBD_LL_GetRxDataSize(pdev, MSCOutEpAdd) != USBD_BOT_CBW_LENGTH) || |
|
||||||
(hmsc->cbw.dSignature != USBD_BOT_CBW_SIGNATURE) || |
|
||||||
(hmsc->cbw.bLUN > 1U) || (hmsc->cbw.bCBLength < 1U) || |
|
||||||
(hmsc->cbw.bCBLength > 16U)) |
|
||||||
{ |
|
||||||
SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); |
|
||||||
|
|
||||||
hmsc->bot_status = USBD_BOT_STATUS_ERROR; |
|
||||||
MSC_BOT_Abort(pdev); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
if (SCSI_ProcessCmd(pdev, hmsc->cbw.bLUN, &hmsc->cbw.CB[0]) < 0) |
|
||||||
{ |
|
||||||
if (hmsc->bot_state == USBD_BOT_NO_DATA) |
|
||||||
{ |
|
||||||
MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_FAILED); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
MSC_BOT_Abort(pdev); |
|
||||||
} |
|
||||||
} |
|
||||||
/* Burst xfer handled internally */ |
|
||||||
else if ((hmsc->bot_state != USBD_BOT_DATA_IN) && |
|
||||||
(hmsc->bot_state != USBD_BOT_DATA_OUT) && |
|
||||||
(hmsc->bot_state != USBD_BOT_LAST_DATA_IN)) |
|
||||||
{ |
|
||||||
if (hmsc->bot_data_length > 0U) |
|
||||||
{ |
|
||||||
MSC_BOT_SendData(pdev, hmsc->bot_data, hmsc->bot_data_length); |
|
||||||
} |
|
||||||
else if (hmsc->bot_data_length == 0U) |
|
||||||
{ |
|
||||||
MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_PASSED); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
MSC_BOT_Abort(pdev); |
|
||||||
} |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
return; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief MSC_BOT_SendData |
|
||||||
* Send the requested data |
|
||||||
* @param pdev: device instance |
|
||||||
* @param buf: pointer to data buffer |
|
||||||
* @param len: Data Length |
|
||||||
* @retval None |
|
||||||
*/ |
|
||||||
static void MSC_BOT_SendData(USBD_HandleTypeDef *pdev, uint8_t *pbuf, uint32_t len) |
|
||||||
{ |
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; |
|
||||||
|
|
||||||
uint32_t length; |
|
||||||
|
|
||||||
#ifdef USE_USBD_COMPOSITE |
|
||||||
/* Get the Endpoints addresses allocated for this class instance */ |
|
||||||
MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK); |
|
||||||
MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK); |
|
||||||
#endif /* USE_USBD_COMPOSITE */ |
|
||||||
|
|
||||||
if (hmsc == NULL) |
|
||||||
{ |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
length = MIN(hmsc->cbw.dDataLength, len); |
|
||||||
|
|
||||||
hmsc->csw.dDataResidue -= len; |
|
||||||
hmsc->csw.bStatus = USBD_CSW_CMD_PASSED; |
|
||||||
hmsc->bot_state = USBD_BOT_SEND_DATA; |
|
||||||
|
|
||||||
(void)USBD_LL_Transmit(pdev, MSCInEpAdd, pbuf, length); |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief MSC_BOT_SendCSW |
|
||||||
* Send the Command Status Wrapper |
|
||||||
* @param pdev: device instance |
|
||||||
* @param status : CSW status |
|
||||||
* @retval None |
|
||||||
*/ |
|
||||||
void MSC_BOT_SendCSW(USBD_HandleTypeDef *pdev, uint8_t CSW_Status) |
|
||||||
{ |
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; |
|
||||||
|
|
||||||
#ifdef USE_USBD_COMPOSITE |
|
||||||
/* Get the Endpoints addresses allocated for this class instance */ |
|
||||||
MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK); |
|
||||||
MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK); |
|
||||||
#endif /* USE_USBD_COMPOSITE */ |
|
||||||
|
|
||||||
if (hmsc == NULL) |
|
||||||
{ |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
hmsc->csw.dSignature = USBD_BOT_CSW_SIGNATURE; |
|
||||||
hmsc->csw.bStatus = CSW_Status; |
|
||||||
hmsc->bot_state = USBD_BOT_IDLE; |
|
||||||
|
|
||||||
(void)USBD_LL_Transmit(pdev, MSCInEpAdd, (uint8_t *)&hmsc->csw, |
|
||||||
USBD_BOT_CSW_LENGTH); |
|
||||||
|
|
||||||
/* Prepare EP to Receive next Cmd */ |
|
||||||
(void)USBD_LL_PrepareReceive(pdev, MSCOutEpAdd, (uint8_t *)&hmsc->cbw, |
|
||||||
USBD_BOT_CBW_LENGTH); |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief MSC_BOT_Abort |
|
||||||
* Abort the current transfer |
|
||||||
* @param pdev: device instance |
|
||||||
* @retval status |
|
||||||
*/ |
|
||||||
|
|
||||||
static void MSC_BOT_Abort(USBD_HandleTypeDef *pdev) |
|
||||||
{ |
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; |
|
||||||
|
|
||||||
#ifdef USE_USBD_COMPOSITE |
|
||||||
/* Get the Endpoints addresses allocated for this class instance */ |
|
||||||
MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK); |
|
||||||
MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK); |
|
||||||
#endif /* USE_USBD_COMPOSITE */ |
|
||||||
|
|
||||||
if (hmsc == NULL) |
|
||||||
{ |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
if ((hmsc->cbw.bmFlags == 0U) && |
|
||||||
(hmsc->cbw.dDataLength != 0U) && |
|
||||||
(hmsc->bot_status == USBD_BOT_STATUS_NORMAL)) |
|
||||||
{ |
|
||||||
(void)USBD_LL_StallEP(pdev, MSCOutEpAdd); |
|
||||||
} |
|
||||||
|
|
||||||
(void)USBD_LL_StallEP(pdev, MSCInEpAdd); |
|
||||||
|
|
||||||
if (hmsc->bot_status == USBD_BOT_STATUS_ERROR) |
|
||||||
{ |
|
||||||
(void)USBD_LL_StallEP(pdev, MSCInEpAdd); |
|
||||||
(void)USBD_LL_StallEP(pdev, MSCOutEpAdd); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief MSC_BOT_CplClrFeature |
|
||||||
* Complete the clear feature request |
|
||||||
* @param pdev: device instance |
|
||||||
* @param epnum: endpoint index |
|
||||||
* @retval None |
|
||||||
*/ |
|
||||||
|
|
||||||
void MSC_BOT_CplClrFeature(USBD_HandleTypeDef *pdev, uint8_t epnum) |
|
||||||
{ |
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; |
|
||||||
|
|
||||||
#ifdef USE_USBD_COMPOSITE |
|
||||||
/* Get the Endpoints addresses allocated for this class instance */ |
|
||||||
MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK); |
|
||||||
MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK); |
|
||||||
#endif /* USE_USBD_COMPOSITE */ |
|
||||||
|
|
||||||
if (hmsc == NULL) |
|
||||||
{ |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
if (hmsc->bot_status == USBD_BOT_STATUS_ERROR) /* Bad CBW Signature */ |
|
||||||
{ |
|
||||||
(void)USBD_LL_StallEP(pdev, MSCInEpAdd); |
|
||||||
(void)USBD_LL_StallEP(pdev, MSCOutEpAdd); |
|
||||||
} |
|
||||||
else if (((epnum & 0x80U) == 0x80U) && (hmsc->bot_status != USBD_BOT_STATUS_RECOVERY)) |
|
||||||
{ |
|
||||||
MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_FAILED); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
return; |
|
||||||
} |
|
||||||
} |
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
@ -1,181 +0,0 @@ |
|||||||
/**
|
|
||||||
****************************************************************************** |
|
||||||
* @file usbd_msc_data.c |
|
||||||
* @author MCD Application Team |
|
||||||
* @brief This file provides all the vital inquiry pages and sense data. |
|
||||||
****************************************************************************** |
|
||||||
* @attention |
|
||||||
* |
|
||||||
* Copyright (c) 2015 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. |
|
||||||
* |
|
||||||
****************************************************************************** |
|
||||||
*/ |
|
||||||
|
|
||||||
/* BSPDependencies
|
|
||||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" |
|
||||||
- "stm32xxxxx_{eval}{discovery}_io.c" |
|
||||||
- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c" |
|
||||||
EndBSPDependencies */ |
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/ |
|
||||||
#include "usbd_msc_data.h" |
|
||||||
|
|
||||||
|
|
||||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup MSC_DATA
|
|
||||||
* @brief Mass storage info/data module |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup MSC_DATA_Private_TypesDefinitions
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup MSC_DATA_Private_Defines
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup MSC_DATA_Private_Macros
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup MSC_DATA_Private_Variables
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/* USB Mass storage Page 0 Inquiry Data */ |
|
||||||
uint8_t MSC_Page00_Inquiry_Data[LENGTH_INQUIRY_PAGE00] = |
|
||||||
{ |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
(LENGTH_INQUIRY_PAGE00 - 4U), |
|
||||||
0x00, |
|
||||||
0x80 |
|
||||||
}; |
|
||||||
|
|
||||||
/* USB Mass storage VPD Page 0x80 Inquiry Data for Unit Serial Number */ |
|
||||||
uint8_t MSC_Page80_Inquiry_Data[LENGTH_INQUIRY_PAGE80] = |
|
||||||
{ |
|
||||||
0x00, |
|
||||||
0x80, |
|
||||||
0x00, |
|
||||||
LENGTH_INQUIRY_PAGE80, |
|
||||||
0x20, /* Put Product Serial number */ |
|
||||||
0x20, |
|
||||||
0x20, |
|
||||||
0x20 |
|
||||||
}; |
|
||||||
|
|
||||||
/* USB Mass storage sense 6 Data */ |
|
||||||
uint8_t MSC_Mode_Sense6_data[MODE_SENSE6_LEN] = |
|
||||||
{ |
|
||||||
0x22, |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
0x08, |
|
||||||
0x12, |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
0x00 |
|
||||||
}; |
|
||||||
|
|
||||||
|
|
||||||
/* USB Mass storage sense 10 Data */ |
|
||||||
uint8_t MSC_Mode_Sense10_data[MODE_SENSE10_LEN] = |
|
||||||
{ |
|
||||||
0x00, |
|
||||||
0x26, |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
0x08, |
|
||||||
0x12, |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
0x00 |
|
||||||
}; |
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup MSC_DATA_Private_FunctionPrototypes
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup MSC_DATA_Private_Functions
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
File diff suppressed because it is too large
Load Diff
@ -1,172 +0,0 @@ |
|||||||
/**
|
|
||||||
****************************************************************************** |
|
||||||
* @file usbd_core.h |
|
||||||
* @author MCD Application Team |
|
||||||
* @brief Header file for usbd_core.c file |
|
||||||
****************************************************************************** |
|
||||||
* @attention |
|
||||||
* |
|
||||||
* Copyright (c) 2015 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. |
|
||||||
* |
|
||||||
****************************************************************************** |
|
||||||
*/ |
|
||||||
|
|
||||||
/* Define to prevent recursive inclusion -------------------------------------*/ |
|
||||||
#ifndef __USBD_CORE_H |
|
||||||
#define __USBD_CORE_H |
|
||||||
|
|
||||||
#ifdef __cplusplus |
|
||||||
extern "C" { |
|
||||||
#endif |
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/ |
|
||||||
#include "usbd_conf.h" |
|
||||||
#include "usbd_def.h" |
|
||||||
#include "usbd_ioreq.h" |
|
||||||
#include "usbd_ctlreq.h" |
|
||||||
|
|
||||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_CORE
|
|
||||||
* @brief This file is the Header file for usbd_core.c file |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup USBD_CORE_Exported_Defines
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
#ifndef USBD_DEBUG_LEVEL |
|
||||||
#define USBD_DEBUG_LEVEL 0U |
|
||||||
#endif /* USBD_DEBUG_LEVEL */ |
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup USBD_CORE_Exported_TypesDefinitions
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup USBD_CORE_Exported_Macros
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_CORE_Exported_Variables
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
#define USBD_SOF USBD_LL_SOF |
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_CORE_Exported_FunctionsPrototype
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, USBD_DescriptorsTypeDef *pdesc, uint8_t id); |
|
||||||
USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev); |
|
||||||
USBD_StatusTypeDef USBD_Start(USBD_HandleTypeDef *pdev); |
|
||||||
USBD_StatusTypeDef USBD_Stop(USBD_HandleTypeDef *pdev); |
|
||||||
USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass); |
|
||||||
|
|
||||||
#ifdef USE_USBD_COMPOSITE |
|
||||||
USBD_StatusTypeDef USBD_RegisterClassComposite(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass, |
|
||||||
USBD_CompositeClassTypeDef classtype, uint8_t *EpAddr); |
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_UnRegisterClassComposite(USBD_HandleTypeDef *pdev); |
|
||||||
uint8_t USBD_CoreGetEPAdd(USBD_HandleTypeDef *pdev, uint8_t ep_dir, uint8_t ep_type); |
|
||||||
#endif /* USE_USBD_COMPOSITE */ |
|
||||||
|
|
||||||
uint8_t USBD_CoreFindIF(USBD_HandleTypeDef *pdev, uint8_t index); |
|
||||||
uint8_t USBD_CoreFindEP(USBD_HandleTypeDef *pdev, uint8_t index); |
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_RunTestMode(USBD_HandleTypeDef *pdev); |
|
||||||
USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx); |
|
||||||
USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx); |
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup); |
|
||||||
USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev, uint8_t epnum, uint8_t *pdata); |
|
||||||
USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev, uint8_t epnum, uint8_t *pdata); |
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev); |
|
||||||
USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev, USBD_SpeedTypeDef speed); |
|
||||||
USBD_StatusTypeDef USBD_LL_Suspend(USBD_HandleTypeDef *pdev); |
|
||||||
USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef *pdev); |
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev); |
|
||||||
USBD_StatusTypeDef USBD_LL_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum); |
|
||||||
USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum); |
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev); |
|
||||||
USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev); |
|
||||||
|
|
||||||
/* USBD Low Level Driver */ |
|
||||||
USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev); |
|
||||||
USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev); |
|
||||||
USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev); |
|
||||||
USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev); |
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr, |
|
||||||
uint8_t ep_type, uint16_t ep_mps); |
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); |
|
||||||
USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); |
|
||||||
USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); |
|
||||||
USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); |
|
||||||
USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr); |
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr, |
|
||||||
uint8_t *pbuf, uint32_t size); |
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, uint8_t ep_addr, |
|
||||||
uint8_t *pbuf, uint32_t size); |
|
||||||
|
|
||||||
#ifdef USBD_HS_TESTMODE_ENABLE |
|
||||||
USBD_StatusTypeDef USBD_LL_SetTestMode(USBD_HandleTypeDef *pdev, uint8_t testmode); |
|
||||||
#endif /* USBD_HS_TESTMODE_ENABLE */ |
|
||||||
|
|
||||||
uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); |
|
||||||
uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr); |
|
||||||
|
|
||||||
void USBD_LL_Delay(uint32_t Delay); |
|
||||||
|
|
||||||
void *USBD_GetEpDesc(uint8_t *pConfDesc, uint8_t EpAddr); |
|
||||||
USBD_DescHeaderTypeDef *USBD_GetNextDesc(uint8_t *pbuf, uint16_t *ptr); |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
#ifdef __cplusplus |
|
||||||
} |
|
||||||
#endif |
|
||||||
|
|
||||||
#endif /* __USBD_CORE_H */ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
@ -1,101 +0,0 @@ |
|||||||
/**
|
|
||||||
****************************************************************************** |
|
||||||
* @file usbd_req.h |
|
||||||
* @author MCD Application Team |
|
||||||
* @brief Header file for the usbd_req.c file |
|
||||||
****************************************************************************** |
|
||||||
* @attention |
|
||||||
* |
|
||||||
* Copyright (c) 2015 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. |
|
||||||
* |
|
||||||
****************************************************************************** |
|
||||||
*/ |
|
||||||
|
|
||||||
/* Define to prevent recursive inclusion -------------------------------------*/ |
|
||||||
#ifndef __USB_REQUEST_H |
|
||||||
#define __USB_REQUEST_H |
|
||||||
|
|
||||||
#ifdef __cplusplus |
|
||||||
extern "C" { |
|
||||||
#endif |
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/ |
|
||||||
#include "usbd_def.h" |
|
||||||
|
|
||||||
|
|
||||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_REQ
|
|
||||||
* @brief header file for the usbd_req.c file |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_REQ_Exported_Defines
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup USBD_REQ_Exported_Types
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup USBD_REQ_Exported_Macros
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_REQ_Exported_Variables
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_REQ_Exported_FunctionsPrototype
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_StdDevReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); |
|
||||||
USBD_StatusTypeDef USBD_StdItfReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); |
|
||||||
USBD_StatusTypeDef USBD_StdEPReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); |
|
||||||
|
|
||||||
void USBD_CtlError(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); |
|
||||||
void USBD_ParseSetupRequest(USBD_SetupReqTypedef *req, uint8_t *pdata); |
|
||||||
void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len); |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
#ifdef __cplusplus |
|
||||||
} |
|
||||||
#endif |
|
||||||
|
|
||||||
#endif /* __USB_REQUEST_H */ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
@ -1,514 +0,0 @@ |
|||||||
/**
|
|
||||||
****************************************************************************** |
|
||||||
* @file usbd_def.h |
|
||||||
* @author MCD Application Team |
|
||||||
* @brief General defines for the usb device library |
|
||||||
****************************************************************************** |
|
||||||
* @attention |
|
||||||
* |
|
||||||
* Copyright (c) 2015 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. |
|
||||||
* |
|
||||||
****************************************************************************** |
|
||||||
*/ |
|
||||||
|
|
||||||
/* Define to prevent recursive inclusion -------------------------------------*/ |
|
||||||
#ifndef __USBD_DEF_H |
|
||||||
#define __USBD_DEF_H |
|
||||||
|
|
||||||
#ifdef __cplusplus |
|
||||||
extern "C" { |
|
||||||
#endif |
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/ |
|
||||||
#include "usbd_conf.h" |
|
||||||
|
|
||||||
/** @addtogroup STM32_USBD_DEVICE_LIBRARY
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USB_DEF
|
|
||||||
* @brief general defines for the usb device library file |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USB_DEF_Exported_Defines
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
#ifndef NULL |
|
||||||
#define NULL 0U |
|
||||||
#endif /* NULL */ |
|
||||||
|
|
||||||
#ifndef USBD_MAX_NUM_INTERFACES |
|
||||||
#define USBD_MAX_NUM_INTERFACES 1U |
|
||||||
#endif /* USBD_MAX_NUM_CONFIGURATION */ |
|
||||||
|
|
||||||
#ifndef USBD_MAX_NUM_CONFIGURATION |
|
||||||
#define USBD_MAX_NUM_CONFIGURATION 1U |
|
||||||
#endif /* USBD_MAX_NUM_CONFIGURATION */ |
|
||||||
|
|
||||||
#ifdef USE_USBD_COMPOSITE |
|
||||||
#ifndef USBD_MAX_SUPPORTED_CLASS |
|
||||||
#define USBD_MAX_SUPPORTED_CLASS 4U |
|
||||||
#endif /* USBD_MAX_SUPPORTED_CLASS */ |
|
||||||
#else |
|
||||||
#ifndef USBD_MAX_SUPPORTED_CLASS |
|
||||||
#define USBD_MAX_SUPPORTED_CLASS 1U |
|
||||||
#endif /* USBD_MAX_SUPPORTED_CLASS */ |
|
||||||
#endif /* USE_USBD_COMPOSITE */ |
|
||||||
|
|
||||||
#ifndef USBD_MAX_CLASS_ENDPOINTS |
|
||||||
#define USBD_MAX_CLASS_ENDPOINTS 5U |
|
||||||
#endif /* USBD_MAX_CLASS_ENDPOINTS */ |
|
||||||
|
|
||||||
#ifndef USBD_MAX_CLASS_INTERFACES |
|
||||||
#define USBD_MAX_CLASS_INTERFACES 5U |
|
||||||
#endif /* USBD_MAX_CLASS_INTERFACES */ |
|
||||||
|
|
||||||
#ifndef USBD_LPM_ENABLED |
|
||||||
#define USBD_LPM_ENABLED 0U |
|
||||||
#endif /* USBD_LPM_ENABLED */ |
|
||||||
|
|
||||||
#ifndef USBD_SELF_POWERED |
|
||||||
#define USBD_SELF_POWERED 1U |
|
||||||
#endif /*USBD_SELF_POWERED */ |
|
||||||
|
|
||||||
#ifndef USBD_MAX_POWER |
|
||||||
#define USBD_MAX_POWER 0x32U /* 100 mA */ |
|
||||||
#endif /* USBD_MAX_POWER */ |
|
||||||
|
|
||||||
#ifndef USBD_SUPPORT_USER_STRING_DESC |
|
||||||
#define USBD_SUPPORT_USER_STRING_DESC 0U |
|
||||||
#endif /* USBD_SUPPORT_USER_STRING_DESC */ |
|
||||||
|
|
||||||
#ifndef USBD_CLASS_USER_STRING_DESC |
|
||||||
#define USBD_CLASS_USER_STRING_DESC 0U |
|
||||||
#endif /* USBD_CLASS_USER_STRING_DESC */ |
|
||||||
|
|
||||||
#define USB_LEN_DEV_QUALIFIER_DESC 0x0AU |
|
||||||
#define USB_LEN_DEV_DESC 0x12U |
|
||||||
#define USB_LEN_CFG_DESC 0x09U |
|
||||||
#define USB_LEN_IF_DESC 0x09U |
|
||||||
#define USB_LEN_EP_DESC 0x07U |
|
||||||
#define USB_LEN_OTG_DESC 0x03U |
|
||||||
#define USB_LEN_LANGID_STR_DESC 0x04U |
|
||||||
#define USB_LEN_OTHER_SPEED_DESC_SIZ 0x09U |
|
||||||
|
|
||||||
#define USBD_IDX_LANGID_STR 0x00U |
|
||||||
#define USBD_IDX_MFC_STR 0x01U |
|
||||||
#define USBD_IDX_PRODUCT_STR 0x02U |
|
||||||
#define USBD_IDX_SERIAL_STR 0x03U |
|
||||||
#define USBD_IDX_CONFIG_STR 0x04U |
|
||||||
#define USBD_IDX_INTERFACE_STR 0x05U |
|
||||||
|
|
||||||
#define USB_REQ_TYPE_STANDARD 0x00U |
|
||||||
#define USB_REQ_TYPE_CLASS 0x20U |
|
||||||
#define USB_REQ_TYPE_VENDOR 0x40U |
|
||||||
#define USB_REQ_TYPE_MASK 0x60U |
|
||||||
|
|
||||||
#define USB_REQ_RECIPIENT_DEVICE 0x00U |
|
||||||
#define USB_REQ_RECIPIENT_INTERFACE 0x01U |
|
||||||
#define USB_REQ_RECIPIENT_ENDPOINT 0x02U |
|
||||||
#define USB_REQ_RECIPIENT_MASK 0x03U |
|
||||||
|
|
||||||
#define USB_REQ_GET_STATUS 0x00U |
|
||||||
#define USB_REQ_CLEAR_FEATURE 0x01U |
|
||||||
#define USB_REQ_SET_FEATURE 0x03U |
|
||||||
#define USB_REQ_SET_ADDRESS 0x05U |
|
||||||
#define USB_REQ_GET_DESCRIPTOR 0x06U |
|
||||||
#define USB_REQ_SET_DESCRIPTOR 0x07U |
|
||||||
#define USB_REQ_GET_CONFIGURATION 0x08U |
|
||||||
#define USB_REQ_SET_CONFIGURATION 0x09U |
|
||||||
#define USB_REQ_GET_INTERFACE 0x0AU |
|
||||||
#define USB_REQ_SET_INTERFACE 0x0BU |
|
||||||
#define USB_REQ_SYNCH_FRAME 0x0CU |
|
||||||
|
|
||||||
#define USB_DESC_TYPE_DEVICE 0x01U |
|
||||||
#define USB_DESC_TYPE_CONFIGURATION 0x02U |
|
||||||
#define USB_DESC_TYPE_STRING 0x03U |
|
||||||
#define USB_DESC_TYPE_INTERFACE 0x04U |
|
||||||
#define USB_DESC_TYPE_ENDPOINT 0x05U |
|
||||||
#define USB_DESC_TYPE_DEVICE_QUALIFIER 0x06U |
|
||||||
#define USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION 0x07U |
|
||||||
#define USB_DESC_TYPE_IAD 0x0BU |
|
||||||
#define USB_DESC_TYPE_BOS 0x0FU |
|
||||||
|
|
||||||
#define USB_CONFIG_REMOTE_WAKEUP 0x02U |
|
||||||
#define USB_CONFIG_SELF_POWERED 0x01U |
|
||||||
|
|
||||||
#define USB_FEATURE_EP_HALT 0x00U |
|
||||||
#define USB_FEATURE_REMOTE_WAKEUP 0x01U |
|
||||||
#define USB_FEATURE_TEST_MODE 0x02U |
|
||||||
|
|
||||||
#define USB_DEVICE_CAPABITY_TYPE 0x10U |
|
||||||
|
|
||||||
#define USB_CONF_DESC_SIZE 0x09U |
|
||||||
#define USB_IF_DESC_SIZE 0x09U |
|
||||||
#define USB_EP_DESC_SIZE 0x07U |
|
||||||
#define USB_IAD_DESC_SIZE 0x08U |
|
||||||
|
|
||||||
#define USB_HS_MAX_PACKET_SIZE 512U |
|
||||||
#define USB_FS_MAX_PACKET_SIZE 64U |
|
||||||
#define USB_MAX_EP0_SIZE 64U |
|
||||||
|
|
||||||
/* Device Status */ |
|
||||||
#define USBD_STATE_DEFAULT 0x01U |
|
||||||
#define USBD_STATE_ADDRESSED 0x02U |
|
||||||
#define USBD_STATE_CONFIGURED 0x03U |
|
||||||
#define USBD_STATE_SUSPENDED 0x04U |
|
||||||
|
|
||||||
|
|
||||||
/* EP0 State */ |
|
||||||
#define USBD_EP0_IDLE 0x00U |
|
||||||
#define USBD_EP0_SETUP 0x01U |
|
||||||
#define USBD_EP0_DATA_IN 0x02U |
|
||||||
#define USBD_EP0_DATA_OUT 0x03U |
|
||||||
#define USBD_EP0_STATUS_IN 0x04U |
|
||||||
#define USBD_EP0_STATUS_OUT 0x05U |
|
||||||
#define USBD_EP0_STALL 0x06U |
|
||||||
|
|
||||||
#define USBD_EP_TYPE_CTRL 0x00U |
|
||||||
#define USBD_EP_TYPE_ISOC 0x01U |
|
||||||
#define USBD_EP_TYPE_BULK 0x02U |
|
||||||
#define USBD_EP_TYPE_INTR 0x03U |
|
||||||
|
|
||||||
#ifdef USE_USBD_COMPOSITE |
|
||||||
#define USBD_EP_IN 0x80U |
|
||||||
#define USBD_EP_OUT 0x00U |
|
||||||
#define USBD_FUNC_DESCRIPTOR_TYPE 0x24U |
|
||||||
#define USBD_DESC_SUBTYPE_ACM 0x0FU |
|
||||||
#define USBD_DESC_ECM_BCD_LOW 0x00U |
|
||||||
#define USBD_DESC_ECM_BCD_HIGH 0x10U |
|
||||||
#endif /* USE_USBD_COMPOSITE */ |
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup USBD_DEF_Exported_TypesDefinitions
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
typedef struct usb_setup_req |
|
||||||
{ |
|
||||||
uint8_t bmRequest; |
|
||||||
uint8_t bRequest; |
|
||||||
uint16_t wValue; |
|
||||||
uint16_t wIndex; |
|
||||||
uint16_t wLength; |
|
||||||
} USBD_SetupReqTypedef; |
|
||||||
|
|
||||||
typedef struct |
|
||||||
{ |
|
||||||
uint8_t bLength; |
|
||||||
uint8_t bDescriptorType; |
|
||||||
uint16_t wTotalLength; |
|
||||||
uint8_t bNumInterfaces; |
|
||||||
uint8_t bConfigurationValue; |
|
||||||
uint8_t iConfiguration; |
|
||||||
uint8_t bmAttributes; |
|
||||||
uint8_t bMaxPower; |
|
||||||
} __PACKED USBD_ConfigDescTypeDef; |
|
||||||
|
|
||||||
typedef struct |
|
||||||
{ |
|
||||||
uint8_t bLength; |
|
||||||
uint8_t bDescriptorType; |
|
||||||
uint16_t wTotalLength; |
|
||||||
uint8_t bNumDeviceCaps; |
|
||||||
} USBD_BosDescTypeDef; |
|
||||||
|
|
||||||
typedef struct |
|
||||||
{ |
|
||||||
uint8_t bLength; |
|
||||||
uint8_t bDescriptorType; |
|
||||||
uint8_t bEndpointAddress; |
|
||||||
uint8_t bmAttributes; |
|
||||||
uint16_t wMaxPacketSize; |
|
||||||
uint8_t bInterval; |
|
||||||
} __PACKED USBD_EpDescTypeDef; |
|
||||||
|
|
||||||
typedef struct |
|
||||||
{ |
|
||||||
uint8_t bLength; |
|
||||||
uint8_t bDescriptorType; |
|
||||||
uint8_t bDescriptorSubType; |
|
||||||
} USBD_DescHeaderTypeDef; |
|
||||||
|
|
||||||
struct _USBD_HandleTypeDef; |
|
||||||
|
|
||||||
typedef struct _Device_cb |
|
||||||
{ |
|
||||||
uint8_t (*Init)(struct _USBD_HandleTypeDef *pdev, uint8_t cfgidx); |
|
||||||
uint8_t (*DeInit)(struct _USBD_HandleTypeDef *pdev, uint8_t cfgidx); |
|
||||||
/* Control Endpoints*/ |
|
||||||
uint8_t (*Setup)(struct _USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); |
|
||||||
uint8_t (*EP0_TxSent)(struct _USBD_HandleTypeDef *pdev); |
|
||||||
uint8_t (*EP0_RxReady)(struct _USBD_HandleTypeDef *pdev); |
|
||||||
/* Class Specific Endpoints*/ |
|
||||||
uint8_t (*DataIn)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum); |
|
||||||
uint8_t (*DataOut)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum); |
|
||||||
uint8_t (*SOF)(struct _USBD_HandleTypeDef *pdev); |
|
||||||
uint8_t (*IsoINIncomplete)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum); |
|
||||||
uint8_t (*IsoOUTIncomplete)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum); |
|
||||||
|
|
||||||
uint8_t *(*GetHSConfigDescriptor)(uint16_t *length); |
|
||||||
uint8_t *(*GetFSConfigDescriptor)(uint16_t *length); |
|
||||||
uint8_t *(*GetOtherSpeedConfigDescriptor)(uint16_t *length); |
|
||||||
uint8_t *(*GetDeviceQualifierDescriptor)(uint16_t *length); |
|
||||||
#if (USBD_SUPPORT_USER_STRING_DESC == 1U) |
|
||||||
uint8_t *(*GetUsrStrDescriptor)(struct _USBD_HandleTypeDef *pdev, uint8_t index, uint16_t *length); |
|
||||||
#endif /* USBD_SUPPORT_USER_STRING_DESC */ |
|
||||||
|
|
||||||
} USBD_ClassTypeDef; |
|
||||||
|
|
||||||
/* Following USB Device Speed */ |
|
||||||
typedef enum |
|
||||||
{ |
|
||||||
USBD_SPEED_HIGH = 0U, |
|
||||||
USBD_SPEED_FULL = 1U, |
|
||||||
USBD_SPEED_LOW = 2U, |
|
||||||
} USBD_SpeedTypeDef; |
|
||||||
|
|
||||||
/* Following USB Device status */ |
|
||||||
typedef enum |
|
||||||
{ |
|
||||||
USBD_OK = 0U, |
|
||||||
USBD_BUSY, |
|
||||||
USBD_EMEM, |
|
||||||
USBD_FAIL, |
|
||||||
} USBD_StatusTypeDef; |
|
||||||
|
|
||||||
/* USB Device descriptors structure */ |
|
||||||
typedef struct |
|
||||||
{ |
|
||||||
uint8_t *(*GetDeviceDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length); |
|
||||||
uint8_t *(*GetLangIDStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length); |
|
||||||
uint8_t *(*GetManufacturerStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length); |
|
||||||
uint8_t *(*GetProductStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length); |
|
||||||
uint8_t *(*GetSerialStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length); |
|
||||||
uint8_t *(*GetConfigurationStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length); |
|
||||||
uint8_t *(*GetInterfaceStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length); |
|
||||||
#if (USBD_CLASS_USER_STRING_DESC == 1) |
|
||||||
uint8_t *(*GetUserStrDescriptor)(USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length); |
|
||||||
#endif /* USBD_CLASS_USER_STRING_DESC */ |
|
||||||
#if ((USBD_LPM_ENABLED == 1U) || (USBD_CLASS_BOS_ENABLED == 1)) |
|
||||||
uint8_t *(*GetBOSDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length); |
|
||||||
#endif /* (USBD_LPM_ENABLED == 1U) || (USBD_CLASS_BOS_ENABLED == 1) */ |
|
||||||
} USBD_DescriptorsTypeDef; |
|
||||||
|
|
||||||
/* USB Device handle structure */ |
|
||||||
typedef struct |
|
||||||
{ |
|
||||||
uint32_t status; |
|
||||||
uint32_t total_length; |
|
||||||
uint32_t rem_length; |
|
||||||
uint32_t maxpacket; |
|
||||||
uint16_t is_used; |
|
||||||
uint16_t bInterval; |
|
||||||
} USBD_EndpointTypeDef; |
|
||||||
|
|
||||||
#ifdef USE_USBD_COMPOSITE |
|
||||||
typedef enum |
|
||||||
{ |
|
||||||
CLASS_TYPE_NONE = 0, |
|
||||||
CLASS_TYPE_HID = 1, |
|
||||||
CLASS_TYPE_CDC = 2, |
|
||||||
CLASS_TYPE_MSC = 3, |
|
||||||
CLASS_TYPE_DFU = 4, |
|
||||||
CLASS_TYPE_CHID = 5, |
|
||||||
CLASS_TYPE_AUDIO = 6, |
|
||||||
CLASS_TYPE_ECM = 7, |
|
||||||
CLASS_TYPE_RNDIS = 8, |
|
||||||
CLASS_TYPE_MTP = 9, |
|
||||||
CLASS_TYPE_VIDEO = 10, |
|
||||||
CLASS_TYPE_PRINTER = 11, |
|
||||||
CLASS_TYPE_CCID = 12, |
|
||||||
} USBD_CompositeClassTypeDef; |
|
||||||
|
|
||||||
|
|
||||||
/* USB Device handle structure */ |
|
||||||
typedef struct |
|
||||||
{ |
|
||||||
uint8_t add; |
|
||||||
uint8_t type; |
|
||||||
uint8_t size; |
|
||||||
uint8_t is_used; |
|
||||||
} USBD_EPTypeDef; |
|
||||||
|
|
||||||
/* USB Device handle structure */ |
|
||||||
typedef struct |
|
||||||
{ |
|
||||||
USBD_CompositeClassTypeDef ClassType; |
|
||||||
uint32_t ClassId; |
|
||||||
uint32_t Active; |
|
||||||
uint32_t NumEps; |
|
||||||
USBD_EPTypeDef Eps[USBD_MAX_CLASS_ENDPOINTS]; |
|
||||||
uint8_t *EpAdd; |
|
||||||
uint32_t NumIf; |
|
||||||
uint8_t Ifs[USBD_MAX_CLASS_INTERFACES]; |
|
||||||
uint32_t CurrPcktSze; |
|
||||||
} USBD_CompositeElementTypeDef; |
|
||||||
#endif /* USE_USBD_COMPOSITE */ |
|
||||||
|
|
||||||
/* USB Device handle structure */ |
|
||||||
typedef struct _USBD_HandleTypeDef |
|
||||||
{ |
|
||||||
uint8_t id; |
|
||||||
uint32_t dev_config; |
|
||||||
uint32_t dev_default_config; |
|
||||||
uint32_t dev_config_status; |
|
||||||
USBD_SpeedTypeDef dev_speed; |
|
||||||
USBD_EndpointTypeDef ep_in[16]; |
|
||||||
USBD_EndpointTypeDef ep_out[16]; |
|
||||||
__IO uint32_t ep0_state; |
|
||||||
uint32_t ep0_data_len; |
|
||||||
__IO uint8_t dev_state; |
|
||||||
__IO uint8_t dev_old_state; |
|
||||||
uint8_t dev_address; |
|
||||||
uint8_t dev_connection_status; |
|
||||||
uint8_t dev_test_mode; |
|
||||||
uint32_t dev_remote_wakeup; |
|
||||||
uint8_t ConfIdx; |
|
||||||
|
|
||||||
USBD_SetupReqTypedef request; |
|
||||||
USBD_DescriptorsTypeDef *pDesc; |
|
||||||
USBD_ClassTypeDef *pClass[USBD_MAX_SUPPORTED_CLASS]; |
|
||||||
void *pClassData; |
|
||||||
void *pClassDataCmsit[USBD_MAX_SUPPORTED_CLASS]; |
|
||||||
void *pUserData[USBD_MAX_SUPPORTED_CLASS]; |
|
||||||
void *pData; |
|
||||||
void *pBosDesc; |
|
||||||
void *pConfDesc; |
|
||||||
uint32_t classId; |
|
||||||
uint32_t NumClasses; |
|
||||||
#ifdef USE_USBD_COMPOSITE |
|
||||||
USBD_CompositeElementTypeDef tclasslist[USBD_MAX_SUPPORTED_CLASS]; |
|
||||||
#endif /* USE_USBD_COMPOSITE */ |
|
||||||
} USBD_HandleTypeDef; |
|
||||||
|
|
||||||
/* USB Device endpoint direction */ |
|
||||||
typedef enum |
|
||||||
{ |
|
||||||
OUT = 0x00, |
|
||||||
IN = 0x80, |
|
||||||
} USBD_EPDirectionTypeDef; |
|
||||||
|
|
||||||
typedef enum |
|
||||||
{ |
|
||||||
NETWORK_CONNECTION = 0x00, |
|
||||||
RESPONSE_AVAILABLE = 0x01, |
|
||||||
CONNECTION_SPEED_CHANGE = 0x2A |
|
||||||
} USBD_CDC_NotifCodeTypeDef; |
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup USBD_DEF_Exported_Macros
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
__STATIC_INLINE uint16_t SWAPBYTE(uint8_t *addr) |
|
||||||
{ |
|
||||||
uint16_t _SwapVal, _Byte1, _Byte2; |
|
||||||
uint8_t *_pbuff = addr; |
|
||||||
|
|
||||||
_Byte1 = *(uint8_t *)_pbuff; |
|
||||||
_pbuff++; |
|
||||||
_Byte2 = *(uint8_t *)_pbuff; |
|
||||||
|
|
||||||
_SwapVal = (_Byte2 << 8) | _Byte1; |
|
||||||
|
|
||||||
return _SwapVal; |
|
||||||
} |
|
||||||
|
|
||||||
#ifndef LOBYTE |
|
||||||
#define LOBYTE(x) ((uint8_t)((x) & 0x00FFU)) |
|
||||||
#endif /* LOBYTE */ |
|
||||||
|
|
||||||
#ifndef HIBYTE |
|
||||||
#define HIBYTE(x) ((uint8_t)(((x) & 0xFF00U) >> 8U)) |
|
||||||
#endif /* HIBYTE */ |
|
||||||
|
|
||||||
#ifndef MIN |
|
||||||
#define MIN(a, b) (((a) < (b)) ? (a) : (b)) |
|
||||||
#endif /* MIN */ |
|
||||||
|
|
||||||
#ifndef MAX |
|
||||||
#define MAX(a, b) (((a) > (b)) ? (a) : (b)) |
|
||||||
#endif /* MAX */ |
|
||||||
|
|
||||||
#if defined ( __GNUC__ ) |
|
||||||
#ifndef __weak |
|
||||||
#define __weak __attribute__((weak)) |
|
||||||
#endif /* __weak */ |
|
||||||
#ifndef __packed |
|
||||||
#define __packed __attribute__((__packed__)) |
|
||||||
#endif /* __packed */ |
|
||||||
#endif /* __GNUC__ */ |
|
||||||
|
|
||||||
|
|
||||||
/* In HS mode and when the DMA is used, all variables and data structures dealing
|
|
||||||
with the DMA during the transaction process should be 4-bytes aligned */ |
|
||||||
|
|
||||||
#if defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */ |
|
||||||
#ifndef __ALIGN_END |
|
||||||
#define __ALIGN_END __attribute__ ((aligned (4U))) |
|
||||||
#endif /* __ALIGN_END */ |
|
||||||
#ifndef __ALIGN_BEGIN |
|
||||||
#define __ALIGN_BEGIN |
|
||||||
#endif /* __ALIGN_BEGIN */ |
|
||||||
#else |
|
||||||
#ifndef __ALIGN_END |
|
||||||
#define __ALIGN_END |
|
||||||
#endif /* __ALIGN_END */ |
|
||||||
#ifndef __ALIGN_BEGIN |
|
||||||
#if defined (__CC_ARM) /* ARM Compiler */ |
|
||||||
#define __ALIGN_BEGIN __align(4U) |
|
||||||
#elif defined (__ICCARM__) /* IAR Compiler */ |
|
||||||
#define __ALIGN_BEGIN |
|
||||||
#endif /* __CC_ARM */ |
|
||||||
#endif /* __ALIGN_BEGIN */ |
|
||||||
#endif /* __GNUC__ */ |
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_DEF_Exported_Variables
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_DEF_Exported_FunctionsPrototype
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
#ifdef __cplusplus |
|
||||||
} |
|
||||||
#endif |
|
||||||
|
|
||||||
#endif /* __USBD_DEF_H */ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
@ -1,113 +0,0 @@ |
|||||||
/**
|
|
||||||
****************************************************************************** |
|
||||||
* @file usbd_ioreq.h |
|
||||||
* @author MCD Application Team |
|
||||||
* @brief Header file for the usbd_ioreq.c file |
|
||||||
****************************************************************************** |
|
||||||
* @attention |
|
||||||
* |
|
||||||
* Copyright (c) 2015 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. |
|
||||||
* |
|
||||||
****************************************************************************** |
|
||||||
*/ |
|
||||||
|
|
||||||
/* Define to prevent recursive inclusion -------------------------------------*/ |
|
||||||
#ifndef __USBD_IOREQ_H |
|
||||||
#define __USBD_IOREQ_H |
|
||||||
|
|
||||||
#ifdef __cplusplus |
|
||||||
extern "C" { |
|
||||||
#endif |
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/ |
|
||||||
#include "usbd_def.h" |
|
||||||
#include "usbd_core.h" |
|
||||||
|
|
||||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_IOREQ
|
|
||||||
* @brief header file for the usbd_ioreq.c file |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_IOREQ_Exported_Defines
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup USBD_IOREQ_Exported_Types
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup USBD_IOREQ_Exported_Macros
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_IOREQ_Exported_Variables
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_IOREQ_Exported_FunctionsPrototype
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev, |
|
||||||
uint8_t *pbuf, uint32_t len); |
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_CtlContinueSendData(USBD_HandleTypeDef *pdev, |
|
||||||
uint8_t *pbuf, uint32_t len); |
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef *pdev, |
|
||||||
uint8_t *pbuf, uint32_t len); |
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_CtlContinueRx(USBD_HandleTypeDef *pdev, |
|
||||||
uint8_t *pbuf, uint32_t len); |
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_CtlSendStatus(USBD_HandleTypeDef *pdev); |
|
||||||
USBD_StatusTypeDef USBD_CtlReceiveStatus(USBD_HandleTypeDef *pdev); |
|
||||||
|
|
||||||
uint32_t USBD_GetRxCount(USBD_HandleTypeDef *pdev, uint8_t ep_addr); |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
#ifdef __cplusplus |
|
||||||
} |
|
||||||
#endif |
|
||||||
|
|
||||||
#endif /* __USBD_IOREQ_H */ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,224 +0,0 @@ |
|||||||
/**
|
|
||||||
****************************************************************************** |
|
||||||
* @file usbd_ioreq.c |
|
||||||
* @author MCD Application Team |
|
||||||
* @brief This file provides the IO requests APIs for control endpoints. |
|
||||||
****************************************************************************** |
|
||||||
* @attention |
|
||||||
* |
|
||||||
* Copyright (c) 2015 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. |
|
||||||
* |
|
||||||
****************************************************************************** |
|
||||||
*/ |
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/ |
|
||||||
#include "usbd_ioreq.h" |
|
||||||
|
|
||||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup USBD_IOREQ
|
|
||||||
* @brief control I/O requests module |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_IOREQ_Private_TypesDefinitions
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup USBD_IOREQ_Private_Defines
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup USBD_IOREQ_Private_Macros
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup USBD_IOREQ_Private_Variables
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup USBD_IOREQ_Private_FunctionPrototypes
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup USBD_IOREQ_Private_Functions
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief USBD_CtlSendData |
|
||||||
* send data on the ctl pipe |
|
||||||
* @param pdev: device instance |
|
||||||
* @param buff: pointer to data buffer |
|
||||||
* @param len: length of data to be sent |
|
||||||
* @retval status |
|
||||||
*/ |
|
||||||
USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev, |
|
||||||
uint8_t *pbuf, uint32_t len) |
|
||||||
{ |
|
||||||
/* Set EP0 State */ |
|
||||||
pdev->ep0_state = USBD_EP0_DATA_IN; |
|
||||||
pdev->ep_in[0].total_length = len; |
|
||||||
|
|
||||||
#ifdef USBD_AVOID_PACKET_SPLIT_MPS |
|
||||||
pdev->ep_in[0].rem_length = 0U; |
|
||||||
#else |
|
||||||
pdev->ep_in[0].rem_length = len; |
|
||||||
#endif /* USBD_AVOID_PACKET_SPLIT_MPS */ |
|
||||||
|
|
||||||
/* Start the transfer */ |
|
||||||
(void)USBD_LL_Transmit(pdev, 0x00U, pbuf, len); |
|
||||||
|
|
||||||
return USBD_OK; |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief USBD_CtlContinueSendData |
|
||||||
* continue sending data on the ctl pipe |
|
||||||
* @param pdev: device instance |
|
||||||
* @param buff: pointer to data buffer |
|
||||||
* @param len: length of data to be sent |
|
||||||
* @retval status |
|
||||||
*/ |
|
||||||
USBD_StatusTypeDef USBD_CtlContinueSendData(USBD_HandleTypeDef *pdev, |
|
||||||
uint8_t *pbuf, uint32_t len) |
|
||||||
{ |
|
||||||
/* Start the next transfer */ |
|
||||||
(void)USBD_LL_Transmit(pdev, 0x00U, pbuf, len); |
|
||||||
|
|
||||||
return USBD_OK; |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief USBD_CtlPrepareRx |
|
||||||
* receive data on the ctl pipe |
|
||||||
* @param pdev: device instance |
|
||||||
* @param buff: pointer to data buffer |
|
||||||
* @param len: length of data to be received |
|
||||||
* @retval status |
|
||||||
*/ |
|
||||||
USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef *pdev, |
|
||||||
uint8_t *pbuf, uint32_t len) |
|
||||||
{ |
|
||||||
/* Set EP0 State */ |
|
||||||
pdev->ep0_state = USBD_EP0_DATA_OUT; |
|
||||||
pdev->ep_out[0].total_length = len; |
|
||||||
|
|
||||||
#ifdef USBD_AVOID_PACKET_SPLIT_MPS |
|
||||||
pdev->ep_out[0].rem_length = 0U; |
|
||||||
#else |
|
||||||
pdev->ep_out[0].rem_length = len; |
|
||||||
#endif /* USBD_AVOID_PACKET_SPLIT_MPS */ |
|
||||||
|
|
||||||
/* Start the transfer */ |
|
||||||
(void)USBD_LL_PrepareReceive(pdev, 0U, pbuf, len); |
|
||||||
|
|
||||||
return USBD_OK; |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief USBD_CtlContinueRx |
|
||||||
* continue receive data on the ctl pipe |
|
||||||
* @param pdev: device instance |
|
||||||
* @param buff: pointer to data buffer |
|
||||||
* @param len: length of data to be received |
|
||||||
* @retval status |
|
||||||
*/ |
|
||||||
USBD_StatusTypeDef USBD_CtlContinueRx(USBD_HandleTypeDef *pdev, |
|
||||||
uint8_t *pbuf, uint32_t len) |
|
||||||
{ |
|
||||||
(void)USBD_LL_PrepareReceive(pdev, 0U, pbuf, len); |
|
||||||
|
|
||||||
return USBD_OK; |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief USBD_CtlSendStatus |
|
||||||
* send zero lzngth packet on the ctl pipe |
|
||||||
* @param pdev: device instance |
|
||||||
* @retval status |
|
||||||
*/ |
|
||||||
USBD_StatusTypeDef USBD_CtlSendStatus(USBD_HandleTypeDef *pdev) |
|
||||||
{ |
|
||||||
/* Set EP0 State */ |
|
||||||
pdev->ep0_state = USBD_EP0_STATUS_IN; |
|
||||||
|
|
||||||
/* Start the transfer */ |
|
||||||
(void)USBD_LL_Transmit(pdev, 0x00U, NULL, 0U); |
|
||||||
|
|
||||||
return USBD_OK; |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief USBD_CtlReceiveStatus |
|
||||||
* receive zero lzngth packet on the ctl pipe |
|
||||||
* @param pdev: device instance |
|
||||||
* @retval status |
|
||||||
*/ |
|
||||||
USBD_StatusTypeDef USBD_CtlReceiveStatus(USBD_HandleTypeDef *pdev) |
|
||||||
{ |
|
||||||
/* Set EP0 State */ |
|
||||||
pdev->ep0_state = USBD_EP0_STATUS_OUT; |
|
||||||
|
|
||||||
/* Start the transfer */ |
|
||||||
(void)USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U); |
|
||||||
|
|
||||||
return USBD_OK; |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief USBD_GetRxCount |
|
||||||
* returns the received data length |
|
||||||
* @param pdev: device instance |
|
||||||
* @param ep_addr: endpoint address |
|
||||||
* @retval Rx Data blength |
|
||||||
*/ |
|
||||||
uint32_t USBD_GetRxCount(USBD_HandleTypeDef *pdev, uint8_t ep_addr) |
|
||||||
{ |
|
||||||
return USBD_LL_GetRxDataSize(pdev, ep_addr); |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
@ -0,0 +1,656 @@ |
|||||||
|
/*
|
||||||
|
* FreeRTOS Kernel V10.3.1 |
||||||
|
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
||||||
|
* |
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of |
||||||
|
* this software and associated documentation files (the "Software"), to deal in |
||||||
|
* the Software without restriction, including without limitation the rights to |
||||||
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
||||||
|
* the Software, and to permit persons to whom the Software is furnished to do so, |
||||||
|
* subject to the following conditions: |
||||||
|
* |
||||||
|
* The above copyright notice and this permission notice shall be included in all |
||||||
|
* copies or substantial portions of the Software. |
||||||
|
* |
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
||||||
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
||||||
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
||||||
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
||||||
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
||||||
|
* |
||||||
|
* http://www.FreeRTOS.org
|
||||||
|
* http://aws.amazon.com/freertos
|
||||||
|
* |
||||||
|
* 1 tab == 4 spaces! |
||||||
|
*/ |
||||||
|
|
||||||
|
/*-----------------------------------------------------------
|
||||||
|
* Implementation of functions defined in portable.h for the ARM CM4F port. |
||||||
|
*----------------------------------------------------------*/ |
||||||
|
|
||||||
|
/* IAR includes. */ |
||||||
|
#include <intrinsics.h> |
||||||
|
|
||||||
|
/* Scheduler includes. */ |
||||||
|
#include "FreeRTOS.h" |
||||||
|
#include "task.h" |
||||||
|
|
||||||
|
#ifndef __ARMVFP__ |
||||||
|
#error This port can only be used when the project options are configured to enable hardware floating point support. |
||||||
|
#endif |
||||||
|
|
||||||
|
#if( configMAX_SYSCALL_INTERRUPT_PRIORITY == 0 ) |
||||||
|
#error configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to 0. See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html
|
||||||
|
#endif |
||||||
|
|
||||||
|
#ifndef configSYSTICK_CLOCK_HZ |
||||||
|
#define configSYSTICK_CLOCK_HZ configCPU_CLOCK_HZ |
||||||
|
/* Ensure the SysTick is clocked at the same frequency as the core. */ |
||||||
|
#define portNVIC_SYSTICK_CLK_BIT ( 1UL << 2UL ) |
||||||
|
#else |
||||||
|
/* The way the SysTick is clocked is not modified in case it is not the same
|
||||||
|
as the core. */ |
||||||
|
#define portNVIC_SYSTICK_CLK_BIT ( 0 ) |
||||||
|
#endif |
||||||
|
|
||||||
|
/* Constants required to manipulate the core. Registers first... */ |
||||||
|
#define portNVIC_SYSTICK_CTRL_REG ( * ( ( volatile uint32_t * ) 0xe000e010 ) ) |
||||||
|
#define portNVIC_SYSTICK_LOAD_REG ( * ( ( volatile uint32_t * ) 0xe000e014 ) ) |
||||||
|
#define portNVIC_SYSTICK_CURRENT_VALUE_REG ( * ( ( volatile uint32_t * ) 0xe000e018 ) ) |
||||||
|
#define portNVIC_SYSPRI2_REG ( * ( ( volatile uint32_t * ) 0xe000ed20 ) ) |
||||||
|
/* ...then bits in the registers. */ |
||||||
|
#define portNVIC_SYSTICK_INT_BIT ( 1UL << 1UL ) |
||||||
|
#define portNVIC_SYSTICK_ENABLE_BIT ( 1UL << 0UL ) |
||||||
|
#define portNVIC_SYSTICK_COUNT_FLAG_BIT ( 1UL << 16UL ) |
||||||
|
#define portNVIC_PENDSVCLEAR_BIT ( 1UL << 27UL ) |
||||||
|
#define portNVIC_PEND_SYSTICK_CLEAR_BIT ( 1UL << 25UL ) |
||||||
|
|
||||||
|
/* Constants used to detect a Cortex-M7 r0p1 core, which should use the ARM_CM7
|
||||||
|
r0p1 port. */ |
||||||
|
#define portCPUID ( * ( ( volatile uint32_t * ) 0xE000ed00 ) ) |
||||||
|
#define portCORTEX_M7_r0p1_ID ( 0x410FC271UL ) |
||||||
|
#define portCORTEX_M7_r0p0_ID ( 0x410FC270UL ) |
||||||
|
|
||||||
|
#define portNVIC_PENDSV_PRI ( ( ( uint32_t ) configKERNEL_INTERRUPT_PRIORITY ) << 16UL ) |
||||||
|
#define portNVIC_SYSTICK_PRI ( ( ( uint32_t ) configKERNEL_INTERRUPT_PRIORITY ) << 24UL ) |
||||||
|
|
||||||
|
/* Constants required to check the validity of an interrupt priority. */ |
||||||
|
#define portFIRST_USER_INTERRUPT_NUMBER ( 16 ) |
||||||
|
#define portNVIC_IP_REGISTERS_OFFSET_16 ( 0xE000E3F0 ) |
||||||
|
#define portAIRCR_REG ( * ( ( volatile uint32_t * ) 0xE000ED0C ) ) |
||||||
|
#define portMAX_8_BIT_VALUE ( ( uint8_t ) 0xff ) |
||||||
|
#define portTOP_BIT_OF_BYTE ( ( uint8_t ) 0x80 ) |
||||||
|
#define portMAX_PRIGROUP_BITS ( ( uint8_t ) 7 ) |
||||||
|
#define portPRIORITY_GROUP_MASK ( 0x07UL << 8UL ) |
||||||
|
#define portPRIGROUP_SHIFT ( 8UL ) |
||||||
|
|
||||||
|
/* Masks off all bits but the VECTACTIVE bits in the ICSR register. */ |
||||||
|
#define portVECTACTIVE_MASK ( 0xFFUL ) |
||||||
|
|
||||||
|
/* Constants required to manipulate the VFP. */ |
||||||
|
#define portFPCCR ( ( volatile uint32_t * ) 0xe000ef34 ) /* Floating point context control register. */ |
||||||
|
#define portASPEN_AND_LSPEN_BITS ( 0x3UL << 30UL ) |
||||||
|
|
||||||
|
/* Constants required to set up the initial stack. */ |
||||||
|
#define portINITIAL_XPSR ( 0x01000000 ) |
||||||
|
#define portINITIAL_EXC_RETURN ( 0xfffffffd ) |
||||||
|
|
||||||
|
/* The systick is a 24-bit counter. */ |
||||||
|
#define portMAX_24_BIT_NUMBER ( 0xffffffUL ) |
||||||
|
|
||||||
|
/* A fiddle factor to estimate the number of SysTick counts that would have
|
||||||
|
occurred while the SysTick counter is stopped during tickless idle |
||||||
|
calculations. */ |
||||||
|
#define portMISSED_COUNTS_FACTOR ( 45UL ) |
||||||
|
|
||||||
|
/* For strict compliance with the Cortex-M spec the task start address should
|
||||||
|
have bit-0 clear, as it is loaded into the PC on exit from an ISR. */ |
||||||
|
#define portSTART_ADDRESS_MASK ( ( StackType_t ) 0xfffffffeUL ) |
||||||
|
|
||||||
|
/*
|
||||||
|
* Setup the timer to generate the tick interrupts. The implementation in this |
||||||
|
* file is weak to allow application writers to change the timer used to |
||||||
|
* generate the tick interrupt. |
||||||
|
*/ |
||||||
|
void vPortSetupTimerInterrupt( void ); |
||||||
|
|
||||||
|
/*
|
||||||
|
* Exception handlers. |
||||||
|
*/ |
||||||
|
void xPortSysTickHandler( void ); |
||||||
|
|
||||||
|
/*
|
||||||
|
* Start first task is a separate function so it can be tested in isolation. |
||||||
|
*/ |
||||||
|
extern void vPortStartFirstTask( void ); |
||||||
|
|
||||||
|
/*
|
||||||
|
* Turn the VFP on. |
||||||
|
*/ |
||||||
|
extern void vPortEnableVFP( void ); |
||||||
|
|
||||||
|
/*
|
||||||
|
* Used to catch tasks that attempt to return from their implementing function. |
||||||
|
*/ |
||||||
|
static void prvTaskExitError( void ); |
||||||
|
|
||||||
|
/*-----------------------------------------------------------*/ |
||||||
|
|
||||||
|
/* Each task maintains its own interrupt status in the critical nesting
|
||||||
|
variable. */ |
||||||
|
static UBaseType_t uxCriticalNesting = 0xaaaaaaaa; |
||||||
|
|
||||||
|
/*
|
||||||
|
* The number of SysTick increments that make up one tick period. |
||||||
|
*/ |
||||||
|
#if( configUSE_TICKLESS_IDLE == 1 ) |
||||||
|
static uint32_t ulTimerCountsForOneTick = 0; |
||||||
|
#endif /* configUSE_TICKLESS_IDLE */ |
||||||
|
|
||||||
|
/*
|
||||||
|
* The maximum number of tick periods that can be suppressed is limited by the |
||||||
|
* 24 bit resolution of the SysTick timer. |
||||||
|
*/ |
||||||
|
#if( configUSE_TICKLESS_IDLE == 1 ) |
||||||
|
static uint32_t xMaximumPossibleSuppressedTicks = 0; |
||||||
|
#endif /* configUSE_TICKLESS_IDLE */ |
||||||
|
|
||||||
|
/*
|
||||||
|
* Compensate for the CPU cycles that pass while the SysTick is stopped (low |
||||||
|
* power functionality only. |
||||||
|
*/ |
||||||
|
#if( configUSE_TICKLESS_IDLE == 1 ) |
||||||
|
static uint32_t ulStoppedTimerCompensation = 0; |
||||||
|
#endif /* configUSE_TICKLESS_IDLE */ |
||||||
|
|
||||||
|
/*
|
||||||
|
* Used by the portASSERT_IF_INTERRUPT_PRIORITY_INVALID() macro to ensure |
||||||
|
* FreeRTOS API functions are not called from interrupts that have been assigned |
||||||
|
* a priority above configMAX_SYSCALL_INTERRUPT_PRIORITY. |
||||||
|
*/ |
||||||
|
#if( configASSERT_DEFINED == 1 ) |
||||||
|
static uint8_t ucMaxSysCallPriority = 0; |
||||||
|
static uint32_t ulMaxPRIGROUPValue = 0; |
||||||
|
static const volatile uint8_t * const pcInterruptPriorityRegisters = ( const volatile uint8_t * const ) portNVIC_IP_REGISTERS_OFFSET_16; |
||||||
|
#endif /* configASSERT_DEFINED */ |
||||||
|
|
||||||
|
/*-----------------------------------------------------------*/ |
||||||
|
|
||||||
|
/*
|
||||||
|
* See header file for description. |
||||||
|
*/ |
||||||
|
StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters ) |
||||||
|
{ |
||||||
|
/* Simulate the stack frame as it would be created by a context switch
|
||||||
|
interrupt. */ |
||||||
|
|
||||||
|
/* Offset added to account for the way the MCU uses the stack on entry/exit
|
||||||
|
of interrupts, and to ensure alignment. */ |
||||||
|
pxTopOfStack--; |
||||||
|
|
||||||
|
*pxTopOfStack = portINITIAL_XPSR; /* xPSR */ |
||||||
|
pxTopOfStack--; |
||||||
|
*pxTopOfStack = ( ( StackType_t ) pxCode ) & portSTART_ADDRESS_MASK; /* PC */ |
||||||
|
pxTopOfStack--; |
||||||
|
*pxTopOfStack = ( StackType_t ) prvTaskExitError; /* LR */ |
||||||
|
|
||||||
|
/* Save code space by skipping register initialisation. */ |
||||||
|
pxTopOfStack -= 5; /* R12, R3, R2 and R1. */ |
||||||
|
*pxTopOfStack = ( StackType_t ) pvParameters; /* R0 */ |
||||||
|
|
||||||
|
/* A save method is being used that requires each task to maintain its
|
||||||
|
own exec return value. */ |
||||||
|
pxTopOfStack--; |
||||||
|
*pxTopOfStack = portINITIAL_EXC_RETURN; |
||||||
|
|
||||||
|
pxTopOfStack -= 8; /* R11, R10, R9, R8, R7, R6, R5 and R4. */ |
||||||
|
|
||||||
|
return pxTopOfStack; |
||||||
|
} |
||||||
|
/*-----------------------------------------------------------*/ |
||||||
|
|
||||||
|
static void prvTaskExitError( void ) |
||||||
|
{ |
||||||
|
/* A function that implements a task must not exit or attempt to return to
|
||||||
|
its caller as there is nothing to return to. If a task wants to exit it |
||||||
|
should instead call vTaskDelete( NULL ). |
||||||
|
|
||||||
|
Artificially force an assert() to be triggered if configASSERT() is |
||||||
|
defined, then stop here so application writers can catch the error. */ |
||||||
|
configASSERT( uxCriticalNesting == ~0UL ); |
||||||
|
portDISABLE_INTERRUPTS(); |
||||||
|
for( ;; ); |
||||||
|
} |
||||||
|
/*-----------------------------------------------------------*/ |
||||||
|
|
||||||
|
/*
|
||||||
|
* See header file for description. |
||||||
|
*/ |
||||||
|
BaseType_t xPortStartScheduler( void ) |
||||||
|
{ |
||||||
|
/* configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to 0.
|
||||||
|
See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html */
|
||||||
|
configASSERT( configMAX_SYSCALL_INTERRUPT_PRIORITY ); |
||||||
|
|
||||||
|
/* This port can be used on all revisions of the Cortex-M7 core other than
|
||||||
|
the r0p1 parts. r0p1 parts should use the port from the |
||||||
|
/source/portable/GCC/ARM_CM7/r0p1 directory. */ |
||||||
|
configASSERT( portCPUID != portCORTEX_M7_r0p1_ID ); |
||||||
|
configASSERT( portCPUID != portCORTEX_M7_r0p0_ID ); |
||||||
|
|
||||||
|
#if( configASSERT_DEFINED == 1 ) |
||||||
|
{ |
||||||
|
volatile uint32_t ulOriginalPriority; |
||||||
|
volatile uint8_t * const pucFirstUserPriorityRegister = ( volatile uint8_t * const ) ( portNVIC_IP_REGISTERS_OFFSET_16 + portFIRST_USER_INTERRUPT_NUMBER ); |
||||||
|
volatile uint8_t ucMaxPriorityValue; |
||||||
|
|
||||||
|
/* Determine the maximum priority from which ISR safe FreeRTOS API
|
||||||
|
functions can be called. ISR safe functions are those that end in |
||||||
|
"FromISR". FreeRTOS maintains separate thread and ISR API functions to |
||||||
|
ensure interrupt entry is as fast and simple as possible. |
||||||
|
|
||||||
|
Save the interrupt priority value that is about to be clobbered. */ |
||||||
|
ulOriginalPriority = *pucFirstUserPriorityRegister; |
||||||
|
|
||||||
|
/* Determine the number of priority bits available. First write to all
|
||||||
|
possible bits. */ |
||||||
|
*pucFirstUserPriorityRegister = portMAX_8_BIT_VALUE; |
||||||
|
|
||||||
|
/* Read the value back to see how many bits stuck. */ |
||||||
|
ucMaxPriorityValue = *pucFirstUserPriorityRegister; |
||||||
|
|
||||||
|
/* Use the same mask on the maximum system call priority. */ |
||||||
|
ucMaxSysCallPriority = configMAX_SYSCALL_INTERRUPT_PRIORITY & ucMaxPriorityValue; |
||||||
|
|
||||||
|
/* Calculate the maximum acceptable priority group value for the number
|
||||||
|
of bits read back. */ |
||||||
|
ulMaxPRIGROUPValue = portMAX_PRIGROUP_BITS; |
||||||
|
while( ( ucMaxPriorityValue & portTOP_BIT_OF_BYTE ) == portTOP_BIT_OF_BYTE ) |
||||||
|
{ |
||||||
|
ulMaxPRIGROUPValue--; |
||||||
|
ucMaxPriorityValue <<= ( uint8_t ) 0x01; |
||||||
|
} |
||||||
|
|
||||||
|
#ifdef __NVIC_PRIO_BITS |
||||||
|
{ |
||||||
|
/* Check the CMSIS configuration that defines the number of
|
||||||
|
priority bits matches the number of priority bits actually queried |
||||||
|
from the hardware. */ |
||||||
|
configASSERT( ( portMAX_PRIGROUP_BITS - ulMaxPRIGROUPValue ) == __NVIC_PRIO_BITS ); |
||||||
|
} |
||||||
|
#endif |
||||||
|
|
||||||
|
#ifdef configPRIO_BITS |
||||||
|
{ |
||||||
|
/* Check the FreeRTOS configuration that defines the number of
|
||||||
|
priority bits matches the number of priority bits actually queried |
||||||
|
from the hardware. */ |
||||||
|
configASSERT( ( portMAX_PRIGROUP_BITS - ulMaxPRIGROUPValue ) == configPRIO_BITS ); |
||||||
|
} |
||||||
|
#endif |
||||||
|
|
||||||
|
/* Shift the priority group value back to its position within the AIRCR
|
||||||
|
register. */ |
||||||
|
ulMaxPRIGROUPValue <<= portPRIGROUP_SHIFT; |
||||||
|
ulMaxPRIGROUPValue &= portPRIORITY_GROUP_MASK; |
||||||
|
|
||||||
|
/* Restore the clobbered interrupt priority register to its original
|
||||||
|
value. */ |
||||||
|
*pucFirstUserPriorityRegister = ulOriginalPriority; |
||||||
|
} |
||||||
|
#endif /* conifgASSERT_DEFINED */ |
||||||
|
|
||||||
|
/* Make PendSV and SysTick the lowest priority interrupts. */ |
||||||
|
portNVIC_SYSPRI2_REG |= portNVIC_PENDSV_PRI; |
||||||
|
portNVIC_SYSPRI2_REG |= portNVIC_SYSTICK_PRI; |
||||||
|
|
||||||
|
/* Start the timer that generates the tick ISR. Interrupts are disabled
|
||||||
|
here already. */ |
||||||
|
vPortSetupTimerInterrupt(); |
||||||
|
|
||||||
|
/* Initialise the critical nesting count ready for the first task. */ |
||||||
|
uxCriticalNesting = 0; |
||||||
|
|
||||||
|
/* Ensure the VFP is enabled - it should be anyway. */ |
||||||
|
vPortEnableVFP(); |
||||||
|
|
||||||
|
/* Lazy save always. */ |
||||||
|
*( portFPCCR ) |= portASPEN_AND_LSPEN_BITS; |
||||||
|
|
||||||
|
/* Start the first task. */ |
||||||
|
vPortStartFirstTask(); |
||||||
|
|
||||||
|
/* Should not get here! */ |
||||||
|
return 0; |
||||||
|
} |
||||||
|
/*-----------------------------------------------------------*/ |
||||||
|
|
||||||
|
void vPortEndScheduler( void ) |
||||||
|
{ |
||||||
|
/* Not implemented in ports where there is nothing to return to.
|
||||||
|
Artificially force an assert. */ |
||||||
|
configASSERT( uxCriticalNesting == 1000UL ); |
||||||
|
} |
||||||
|
/*-----------------------------------------------------------*/ |
||||||
|
|
||||||
|
void vPortEnterCritical( void ) |
||||||
|
{ |
||||||
|
portDISABLE_INTERRUPTS(); |
||||||
|
uxCriticalNesting++; |
||||||
|
|
||||||
|
/* This is not the interrupt safe version of the enter critical function so
|
||||||
|
assert() if it is being called from an interrupt context. Only API |
||||||
|
functions that end in "FromISR" can be used in an interrupt. Only assert if |
||||||
|
the critical nesting count is 1 to protect against recursive calls if the |
||||||
|
assert function also uses a critical section. */ |
||||||
|
if( uxCriticalNesting == 1 ) |
||||||
|
{ |
||||||
|
configASSERT( ( portNVIC_INT_CTRL_REG & portVECTACTIVE_MASK ) == 0 ); |
||||||
|
} |
||||||
|
} |
||||||
|
/*-----------------------------------------------------------*/ |
||||||
|
|
||||||
|
void vPortExitCritical( void ) |
||||||
|
{ |
||||||
|
configASSERT( uxCriticalNesting ); |
||||||
|
uxCriticalNesting--; |
||||||
|
if( uxCriticalNesting == 0 ) |
||||||
|
{ |
||||||
|
portENABLE_INTERRUPTS(); |
||||||
|
} |
||||||
|
} |
||||||
|
/*-----------------------------------------------------------*/ |
||||||
|
|
||||||
|
void xPortSysTickHandler( void ) |
||||||
|
{ |
||||||
|
/* The SysTick runs at the lowest interrupt priority, so when this interrupt
|
||||||
|
executes all interrupts must be unmasked. There is therefore no need to |
||||||
|
save and then restore the interrupt mask value as its value is already |
||||||
|
known. */ |
||||||
|
portDISABLE_INTERRUPTS(); |
||||||
|
{ |
||||||
|
/* Increment the RTOS tick. */ |
||||||
|
if( xTaskIncrementTick() != pdFALSE ) |
||||||
|
{ |
||||||
|
/* A context switch is required. Context switching is performed in
|
||||||
|
the PendSV interrupt. Pend the PendSV interrupt. */ |
||||||
|
portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT; |
||||||
|
} |
||||||
|
} |
||||||
|
portENABLE_INTERRUPTS(); |
||||||
|
} |
||||||
|
/*-----------------------------------------------------------*/ |
||||||
|
|
||||||
|
#if( configUSE_TICKLESS_IDLE == 1 ) |
||||||
|
|
||||||
|
__weak void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime ) |
||||||
|
{ |
||||||
|
uint32_t ulReloadValue, ulCompleteTickPeriods, ulCompletedSysTickDecrements; |
||||||
|
TickType_t xModifiableIdleTime; |
||||||
|
|
||||||
|
/* Make sure the SysTick reload value does not overflow the counter. */ |
||||||
|
if( xExpectedIdleTime > xMaximumPossibleSuppressedTicks ) |
||||||
|
{ |
||||||
|
xExpectedIdleTime = xMaximumPossibleSuppressedTicks; |
||||||
|
} |
||||||
|
|
||||||
|
/* Stop the SysTick momentarily. The time the SysTick is stopped for
|
||||||
|
is accounted for as best it can be, but using the tickless mode will |
||||||
|
inevitably result in some tiny drift of the time maintained by the |
||||||
|
kernel with respect to calendar time. */ |
||||||
|
portNVIC_SYSTICK_CTRL_REG &= ~portNVIC_SYSTICK_ENABLE_BIT; |
||||||
|
|
||||||
|
/* Calculate the reload value required to wait xExpectedIdleTime
|
||||||
|
tick periods. -1 is used because this code will execute part way |
||||||
|
through one of the tick periods. */ |
||||||
|
ulReloadValue = portNVIC_SYSTICK_CURRENT_VALUE_REG + ( ulTimerCountsForOneTick * ( xExpectedIdleTime - 1UL ) ); |
||||||
|
if( ulReloadValue > ulStoppedTimerCompensation ) |
||||||
|
{ |
||||||
|
ulReloadValue -= ulStoppedTimerCompensation; |
||||||
|
} |
||||||
|
|
||||||
|
/* Enter a critical section but don't use the taskENTER_CRITICAL()
|
||||||
|
method as that will mask interrupts that should exit sleep mode. */ |
||||||
|
__disable_interrupt(); |
||||||
|
__DSB(); |
||||||
|
__ISB(); |
||||||
|
|
||||||
|
/* If a context switch is pending or a task is waiting for the scheduler
|
||||||
|
to be unsuspended then abandon the low power entry. */ |
||||||
|
if( eTaskConfirmSleepModeStatus() == eAbortSleep ) |
||||||
|
{ |
||||||
|
/* Restart from whatever is left in the count register to complete
|
||||||
|
this tick period. */ |
||||||
|
portNVIC_SYSTICK_LOAD_REG = portNVIC_SYSTICK_CURRENT_VALUE_REG; |
||||||
|
|
||||||
|
/* Restart SysTick. */ |
||||||
|
portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT; |
||||||
|
|
||||||
|
/* Reset the reload register to the value required for normal tick
|
||||||
|
periods. */ |
||||||
|
portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL; |
||||||
|
|
||||||
|
/* Re-enable interrupts - see comments above __disable_interrupt()
|
||||||
|
call above. */ |
||||||
|
__enable_interrupt(); |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
/* Set the new reload value. */ |
||||||
|
portNVIC_SYSTICK_LOAD_REG = ulReloadValue; |
||||||
|
|
||||||
|
/* Clear the SysTick count flag and set the count value back to
|
||||||
|
zero. */ |
||||||
|
portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL; |
||||||
|
|
||||||
|
/* Restart SysTick. */ |
||||||
|
portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT; |
||||||
|
|
||||||
|
/* Sleep until something happens. configPRE_SLEEP_PROCESSING() can
|
||||||
|
set its parameter to 0 to indicate that its implementation contains |
||||||
|
its own wait for interrupt or wait for event instruction, and so wfi |
||||||
|
should not be executed again. However, the original expected idle |
||||||
|
time variable must remain unmodified, so a copy is taken. */ |
||||||
|
xModifiableIdleTime = xExpectedIdleTime; |
||||||
|
configPRE_SLEEP_PROCESSING( xModifiableIdleTime ); |
||||||
|
if( xModifiableIdleTime > 0 ) |
||||||
|
{ |
||||||
|
__DSB(); |
||||||
|
__WFI(); |
||||||
|
__ISB(); |
||||||
|
} |
||||||
|
configPOST_SLEEP_PROCESSING( xExpectedIdleTime ); |
||||||
|
|
||||||
|
/* Re-enable interrupts to allow the interrupt that brought the MCU
|
||||||
|
out of sleep mode to execute immediately. see comments above |
||||||
|
__disable_interrupt() call above. */ |
||||||
|
__enable_interrupt(); |
||||||
|
__DSB(); |
||||||
|
__ISB(); |
||||||
|
|
||||||
|
/* Disable interrupts again because the clock is about to be stopped
|
||||||
|
and interrupts that execute while the clock is stopped will increase |
||||||
|
any slippage between the time maintained by the RTOS and calendar |
||||||
|
time. */ |
||||||
|
__disable_interrupt(); |
||||||
|
__DSB(); |
||||||
|
__ISB(); |
||||||
|
|
||||||
|
/* Disable the SysTick clock without reading the
|
||||||
|
portNVIC_SYSTICK_CTRL_REG register to ensure the |
||||||
|
portNVIC_SYSTICK_COUNT_FLAG_BIT is not cleared if it is set. Again,
|
||||||
|
the time the SysTick is stopped for is accounted for as best it can
|
||||||
|
be, but using the tickless mode will inevitably result in some tiny
|
||||||
|
drift of the time maintained by the kernel with respect to calendar
|
||||||
|
time*/ |
||||||
|
portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT ); |
||||||
|
|
||||||
|
/* Determine if the SysTick clock has already counted to zero and
|
||||||
|
been set back to the current reload value (the reload back being |
||||||
|
correct for the entire expected idle time) or if the SysTick is yet |
||||||
|
to count to zero (in which case an interrupt other than the SysTick |
||||||
|
must have brought the system out of sleep mode). */ |
||||||
|
if( ( portNVIC_SYSTICK_CTRL_REG & portNVIC_SYSTICK_COUNT_FLAG_BIT ) != 0 ) |
||||||
|
{ |
||||||
|
uint32_t ulCalculatedLoadValue; |
||||||
|
|
||||||
|
/* The tick interrupt is already pending, and the SysTick count
|
||||||
|
reloaded with ulReloadValue. Reset the |
||||||
|
portNVIC_SYSTICK_LOAD_REG with whatever remains of this tick |
||||||
|
period. */ |
||||||
|
ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL ) - ( ulReloadValue - portNVIC_SYSTICK_CURRENT_VALUE_REG ); |
||||||
|
|
||||||
|
/* Don't allow a tiny value, or values that have somehow
|
||||||
|
underflowed because the post sleep hook did something |
||||||
|
that took too long. */ |
||||||
|
if( ( ulCalculatedLoadValue < ulStoppedTimerCompensation ) || ( ulCalculatedLoadValue > ulTimerCountsForOneTick ) ) |
||||||
|
{ |
||||||
|
ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL ); |
||||||
|
} |
||||||
|
|
||||||
|
portNVIC_SYSTICK_LOAD_REG = ulCalculatedLoadValue; |
||||||
|
|
||||||
|
/* As the pending tick will be processed as soon as this
|
||||||
|
function exits, the tick value maintained by the tick is stepped |
||||||
|
forward by one less than the time spent waiting. */ |
||||||
|
ulCompleteTickPeriods = xExpectedIdleTime - 1UL; |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
/* Something other than the tick interrupt ended the sleep.
|
||||||
|
Work out how long the sleep lasted rounded to complete tick |
||||||
|
periods (not the ulReload value which accounted for part |
||||||
|
ticks). */ |
||||||
|
ulCompletedSysTickDecrements = ( xExpectedIdleTime * ulTimerCountsForOneTick ) - portNVIC_SYSTICK_CURRENT_VALUE_REG; |
||||||
|
|
||||||
|
/* How many complete tick periods passed while the processor
|
||||||
|
was waiting? */ |
||||||
|
ulCompleteTickPeriods = ulCompletedSysTickDecrements / ulTimerCountsForOneTick; |
||||||
|
|
||||||
|
/* The reload value is set to whatever fraction of a single tick
|
||||||
|
period remains. */ |
||||||
|
portNVIC_SYSTICK_LOAD_REG = ( ( ulCompleteTickPeriods + 1UL ) * ulTimerCountsForOneTick ) - ulCompletedSysTickDecrements; |
||||||
|
} |
||||||
|
|
||||||
|
/* Restart SysTick so it runs from portNVIC_SYSTICK_LOAD_REG
|
||||||
|
again, then set portNVIC_SYSTICK_LOAD_REG back to its standard |
||||||
|
value. */ |
||||||
|
portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL; |
||||||
|
portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT; |
||||||
|
vTaskStepTick( ulCompleteTickPeriods ); |
||||||
|
portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL; |
||||||
|
|
||||||
|
/* Exit with interrupts enabled. */ |
||||||
|
__enable_interrupt(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
#endif /* configUSE_TICKLESS_IDLE */ |
||||||
|
/*-----------------------------------------------------------*/ |
||||||
|
|
||||||
|
/*
|
||||||
|
* Setup the systick timer to generate the tick interrupts at the required |
||||||
|
* frequency. |
||||||
|
*/ |
||||||
|
__weak void vPortSetupTimerInterrupt( void ) |
||||||
|
{ |
||||||
|
/* Calculate the constants required to configure the tick interrupt. */ |
||||||
|
#if( configUSE_TICKLESS_IDLE == 1 ) |
||||||
|
{ |
||||||
|
ulTimerCountsForOneTick = ( configSYSTICK_CLOCK_HZ / configTICK_RATE_HZ ); |
||||||
|
xMaximumPossibleSuppressedTicks = portMAX_24_BIT_NUMBER / ulTimerCountsForOneTick; |
||||||
|
ulStoppedTimerCompensation = portMISSED_COUNTS_FACTOR / ( configCPU_CLOCK_HZ / configSYSTICK_CLOCK_HZ ); |
||||||
|
} |
||||||
|
#endif /* configUSE_TICKLESS_IDLE */ |
||||||
|
|
||||||
|
/* Stop and clear the SysTick. */ |
||||||
|
portNVIC_SYSTICK_CTRL_REG = 0UL; |
||||||
|
portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL; |
||||||
|
|
||||||
|
/* Configure SysTick to interrupt at the requested rate. */ |
||||||
|
portNVIC_SYSTICK_LOAD_REG = ( configSYSTICK_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL; |
||||||
|
portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT ); |
||||||
|
} |
||||||
|
/*-----------------------------------------------------------*/ |
||||||
|
|
||||||
|
#if( configASSERT_DEFINED == 1 ) |
||||||
|
|
||||||
|
void vPortValidateInterruptPriority( void ) |
||||||
|
{ |
||||||
|
uint32_t ulCurrentInterrupt; |
||||||
|
uint8_t ucCurrentPriority; |
||||||
|
|
||||||
|
/* Obtain the number of the currently executing interrupt. */ |
||||||
|
__asm volatile( "mrs %0, ipsr" : "=r"( ulCurrentInterrupt ) :: "memory" ); |
||||||
|
|
||||||
|
/* Is the interrupt number a user defined interrupt? */ |
||||||
|
if( ulCurrentInterrupt >= portFIRST_USER_INTERRUPT_NUMBER ) |
||||||
|
{ |
||||||
|
/* Look up the interrupt's priority. */ |
||||||
|
ucCurrentPriority = pcInterruptPriorityRegisters[ ulCurrentInterrupt ]; |
||||||
|
|
||||||
|
/* The following assertion will fail if a service routine (ISR) for
|
||||||
|
an interrupt that has been assigned a priority above |
||||||
|
configMAX_SYSCALL_INTERRUPT_PRIORITY calls an ISR safe FreeRTOS API |
||||||
|
function. ISR safe FreeRTOS API functions must *only* be called |
||||||
|
from interrupts that have been assigned a priority at or below |
||||||
|
configMAX_SYSCALL_INTERRUPT_PRIORITY. |
||||||
|
|
||||||
|
Numerically low interrupt priority numbers represent logically high |
||||||
|
interrupt priorities, therefore the priority of the interrupt must |
||||||
|
be set to a value equal to or numerically *higher* than |
||||||
|
configMAX_SYSCALL_INTERRUPT_PRIORITY. |
||||||
|
|
||||||
|
Interrupts that use the FreeRTOS API must not be left at their |
||||||
|
default priority of zero as that is the highest possible priority, |
||||||
|
which is guaranteed to be above configMAX_SYSCALL_INTERRUPT_PRIORITY, |
||||||
|
and therefore also guaranteed to be invalid. |
||||||
|
|
||||||
|
FreeRTOS maintains separate thread and ISR API functions to ensure |
||||||
|
interrupt entry is as fast and simple as possible. |
||||||
|
|
||||||
|
The following links provide detailed information: |
||||||
|
http://www.freertos.org/RTOS-Cortex-M3-M4.html
|
||||||
|
http://www.freertos.org/FAQHelp.html */
|
||||||
|
configASSERT( ucCurrentPriority >= ucMaxSysCallPriority ); |
||||||
|
} |
||||||
|
|
||||||
|
/* Priority grouping: The interrupt controller (NVIC) allows the bits
|
||||||
|
that define each interrupt's priority to be split between bits that |
||||||
|
define the interrupt's pre-emption priority bits and bits that define |
||||||
|
the interrupt's sub-priority. For simplicity all bits must be defined |
||||||
|
to be pre-emption priority bits. The following assertion will fail if |
||||||
|
this is not the case (if some bits represent a sub-priority). |
||||||
|
|
||||||
|
If the application only uses CMSIS libraries for interrupt |
||||||
|
configuration then the correct setting can be achieved on all Cortex-M |
||||||
|
devices by calling NVIC_SetPriorityGrouping( 0 ); before starting the |
||||||
|
scheduler. Note however that some vendor specific peripheral libraries |
||||||
|
assume a non-zero priority group setting, in which cases using a value |
||||||
|
of zero will result in unpredictable behaviour. */ |
||||||
|
configASSERT( ( portAIRCR_REG & portPRIORITY_GROUP_MASK ) <= ulMaxPRIGROUPValue ); |
||||||
|
} |
||||||
|
|
||||||
|
#endif /* configASSERT_DEFINED */ |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,149 @@ |
|||||||
|
/* |
||||||
|
* FreeRTOS Kernel V10.3.1 |
||||||
|
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
||||||
|
* |
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of |
||||||
|
* this software and associated documentation files (the "Software"), to deal in |
||||||
|
* the Software without restriction, including without limitation the rights to |
||||||
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
||||||
|
* the Software, and to permit persons to whom the Software is furnished to do so, |
||||||
|
* subject to the following conditions: |
||||||
|
* |
||||||
|
* The above copyright notice and this permission notice shall be included in all |
||||||
|
* copies or substantial portions of the Software. |
||||||
|
* |
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
||||||
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
||||||
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
||||||
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
||||||
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
||||||
|
* |
||||||
|
* http://www.FreeRTOS.org |
||||||
|
* http://aws.amazon.com/freertos |
||||||
|
* |
||||||
|
* 1 tab == 4 spaces! |
||||||
|
*/ |
||||||
|
|
||||||
|
#include <FreeRTOSConfig.h> |
||||||
|
|
||||||
|
RSEG CODE:CODE(2) |
||||||
|
thumb |
||||||
|
|
||||||
|
EXTERN pxCurrentTCB |
||||||
|
EXTERN vTaskSwitchContext |
||||||
|
|
||||||
|
PUBLIC xPortPendSVHandler |
||||||
|
PUBLIC vPortSVCHandler |
||||||
|
PUBLIC vPortStartFirstTask |
||||||
|
PUBLIC vPortEnableVFP |
||||||
|
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------*/ |
||||||
|
|
||||||
|
xPortPendSVHandler: |
||||||
|
mrs r0, psp |
||||||
|
isb |
||||||
|
/* Get the location of the current TCB. */ |
||||||
|
ldr r3, =pxCurrentTCB |
||||||
|
ldr r2, [r3] |
||||||
|
|
||||||
|
/* Is the task using the FPU context? If so, push high vfp registers. */ |
||||||
|
tst r14, #0x10 |
||||||
|
it eq |
||||||
|
vstmdbeq r0!, {s16-s31} |
||||||
|
|
||||||
|
/* Save the core registers. */ |
||||||
|
stmdb r0!, {r4-r11, r14} |
||||||
|
|
||||||
|
/* Save the new top of stack into the first member of the TCB. */ |
||||||
|
str r0, [r2] |
||||||
|
|
||||||
|
stmdb sp!, {r0, r3} |
||||||
|
mov r0, #configMAX_SYSCALL_INTERRUPT_PRIORITY |
||||||
|
msr basepri, r0 |
||||||
|
dsb |
||||||
|
isb |
||||||
|
bl vTaskSwitchContext |
||||||
|
mov r0, #0 |
||||||
|
msr basepri, r0 |
||||||
|
ldmia sp!, {r0, r3} |
||||||
|
|
||||||
|
/* The first item in pxCurrentTCB is the task top of stack. */ |
||||||
|
ldr r1, [r3] |
||||||
|
ldr r0, [r1] |
||||||
|
|
||||||
|
/* Pop the core registers. */ |
||||||
|
ldmia r0!, {r4-r11, r14} |
||||||
|
|
||||||
|
/* Is the task using the FPU context? If so, pop the high vfp registers |
||||||
|
too. */ |
||||||
|
tst r14, #0x10 |
||||||
|
it eq |
||||||
|
vldmiaeq r0!, {s16-s31} |
||||||
|
|
||||||
|
msr psp, r0 |
||||||
|
isb |
||||||
|
#ifdef WORKAROUND_PMU_CM001 /* XMC4000 specific errata */ |
||||||
|
#if WORKAROUND_PMU_CM001 == 1 |
||||||
|
push { r14 } |
||||||
|
pop { pc } |
||||||
|
#endif |
||||||
|
#endif |
||||||
|
|
||||||
|
bx r14 |
||||||
|
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------*/ |
||||||
|
|
||||||
|
vPortSVCHandler: |
||||||
|
/* Get the location of the current TCB. */ |
||||||
|
ldr r3, =pxCurrentTCB |
||||||
|
ldr r1, [r3] |
||||||
|
ldr r0, [r1] |
||||||
|
/* Pop the core registers. */ |
||||||
|
ldmia r0!, {r4-r11, r14} |
||||||
|
msr psp, r0 |
||||||
|
isb |
||||||
|
mov r0, #0 |
||||||
|
msr basepri, r0 |
||||||
|
bx r14 |
||||||
|
|
||||||
|
/*-----------------------------------------------------------*/ |
||||||
|
|
||||||
|
vPortStartFirstTask |
||||||
|
/* Use the NVIC offset register to locate the stack. */ |
||||||
|
ldr r0, =0xE000ED08 |
||||||
|
ldr r0, [r0] |
||||||
|
ldr r0, [r0] |
||||||
|
/* Set the msp back to the start of the stack. */ |
||||||
|
msr msp, r0 |
||||||
|
/* Clear the bit that indicates the FPU is in use in case the FPU was used |
||||||
|
before the scheduler was started - which would otherwise result in the |
||||||
|
unnecessary leaving of space in the SVC stack for lazy saving of FPU |
||||||
|
registers. */ |
||||||
|
mov r0, #0 |
||||||
|
msr control, r0 |
||||||
|
/* Call SVC to start the first task. */ |
||||||
|
cpsie i |
||||||
|
cpsie f |
||||||
|
dsb |
||||||
|
isb |
||||||
|
svc 0 |
||||||
|
|
||||||
|
/*-----------------------------------------------------------*/ |
||||||
|
|
||||||
|
vPortEnableVFP: |
||||||
|
/* The FPU enable bits are in the CPACR. */ |
||||||
|
ldr.w r0, =0xE000ED88 |
||||||
|
ldr r1, [r0] |
||||||
|
|
||||||
|
/* Enable CP10 and CP11 coprocessors, then save back. */ |
||||||
|
orr r1, r1, #( 0xf << 20 ) |
||||||
|
str r1, [r0] |
||||||
|
bx r14 |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
END |
||||||
|
|
||||||
@ -0,0 +1,207 @@ |
|||||||
|
/*
|
||||||
|
* FreeRTOS Kernel V10.3.1 |
||||||
|
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
||||||
|
* |
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of |
||||||
|
* this software and associated documentation files (the "Software"), to deal in |
||||||
|
* the Software without restriction, including without limitation the rights to |
||||||
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
||||||
|
* the Software, and to permit persons to whom the Software is furnished to do so, |
||||||
|
* subject to the following conditions: |
||||||
|
* |
||||||
|
* The above copyright notice and this permission notice shall be included in all |
||||||
|
* copies or substantial portions of the Software. |
||||||
|
* |
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
||||||
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
||||||
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
||||||
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
||||||
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
||||||
|
* |
||||||
|
* http://www.FreeRTOS.org
|
||||||
|
* http://aws.amazon.com/freertos
|
||||||
|
* |
||||||
|
* 1 tab == 4 spaces! |
||||||
|
*/ |
||||||
|
|
||||||
|
#ifndef PORTMACRO_H |
||||||
|
#define PORTMACRO_H |
||||||
|
|
||||||
|
#ifdef __cplusplus |
||||||
|
extern "C" { |
||||||
|
#endif |
||||||
|
|
||||||
|
/*-----------------------------------------------------------
|
||||||
|
* Port specific definitions. |
||||||
|
* |
||||||
|
* The settings in this file configure FreeRTOS correctly for the |
||||||
|
* given hardware and compiler. |
||||||
|
* |
||||||
|
* These settings should not be altered. |
||||||
|
*----------------------------------------------------------- |
||||||
|
*/ |
||||||
|
|
||||||
|
/* IAR includes. */ |
||||||
|
#include <intrinsics.h> |
||||||
|
|
||||||
|
/* Type definitions. */ |
||||||
|
#define portCHAR char |
||||||
|
#define portFLOAT float |
||||||
|
#define portDOUBLE double |
||||||
|
#define portLONG long |
||||||
|
#define portSHORT short |
||||||
|
#define portSTACK_TYPE uint32_t |
||||||
|
#define portBASE_TYPE long |
||||||
|
|
||||||
|
typedef portSTACK_TYPE StackType_t; |
||||||
|
typedef long BaseType_t; |
||||||
|
typedef unsigned long UBaseType_t; |
||||||
|
|
||||||
|
#if( configUSE_16_BIT_TICKS == 1 ) |
||||||
|
typedef uint16_t TickType_t; |
||||||
|
#define portMAX_DELAY ( TickType_t ) 0xffff |
||||||
|
#else |
||||||
|
typedef uint32_t TickType_t; |
||||||
|
#define portMAX_DELAY ( TickType_t ) 0xffffffffUL |
||||||
|
|
||||||
|
/* 32-bit tick type on a 32-bit architecture, so reads of the tick count do
|
||||||
|
not need to be guarded with a critical section. */ |
||||||
|
#define portTICK_TYPE_IS_ATOMIC 1 |
||||||
|
#endif |
||||||
|
/*-----------------------------------------------------------*/ |
||||||
|
|
||||||
|
/* Architecture specifics. */ |
||||||
|
#define portSTACK_GROWTH ( -1 ) |
||||||
|
#define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ ) |
||||||
|
#define portBYTE_ALIGNMENT 8 |
||||||
|
/*-----------------------------------------------------------*/ |
||||||
|
|
||||||
|
/* Compiler directives. */ |
||||||
|
#define portWEAK_SYMBOL __attribute__( ( weak ) ) |
||||||
|
|
||||||
|
/*-----------------------------------------------------------*/ |
||||||
|
|
||||||
|
|
||||||
|
/* Scheduler utilities. */ |
||||||
|
#define portYIELD() \ |
||||||
|
{ \
|
||||||
|
/* Set a PendSV to request a context switch. */ \
|
||||||
|
portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT; \
|
||||||
|
__DSB(); \
|
||||||
|
__ISB(); \
|
||||||
|
} |
||||||
|
|
||||||
|
#define portNVIC_INT_CTRL_REG ( * ( ( volatile uint32_t * ) 0xe000ed04 ) ) |
||||||
|
#define portNVIC_PENDSVSET_BIT ( 1UL << 28UL ) |
||||||
|
#define portEND_SWITCHING_ISR( xSwitchRequired ) if( xSwitchRequired != pdFALSE ) portYIELD() |
||||||
|
#define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x ) |
||||||
|
|
||||||
|
/*-----------------------------------------------------------*/ |
||||||
|
|
||||||
|
/* Architecture specific optimisations. */ |
||||||
|
#ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION |
||||||
|
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1 |
||||||
|
#endif |
||||||
|
|
||||||
|
#if( configUSE_PORT_OPTIMISED_TASK_SELECTION == 1 ) |
||||||
|
|
||||||
|
/* Check the configuration. */ |
||||||
|
#if( configMAX_PRIORITIES > 32 ) |
||||||
|
#error configUSE_PORT_OPTIMISED_TASK_SELECTION can only be set to 1 when configMAX_PRIORITIES is less than or equal to 32. It is very rare that a system requires more than 10 to 15 difference priorities as tasks that share a priority will time slice. |
||||||
|
#endif |
||||||
|
|
||||||
|
/* Store/clear the ready priorities in a bit map. */ |
||||||
|
#define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) ) |
||||||
|
#define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) ) |
||||||
|
|
||||||
|
/*-----------------------------------------------------------*/ |
||||||
|
|
||||||
|
#define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31UL - ( ( uint32_t ) __CLZ( ( uxReadyPriorities ) ) ) ) |
||||||
|
|
||||||
|
#endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */ |
||||||
|
/*-----------------------------------------------------------*/ |
||||||
|
|
||||||
|
/* Critical section management. */ |
||||||
|
extern void vPortEnterCritical( void ); |
||||||
|
extern void vPortExitCritical( void ); |
||||||
|
|
||||||
|
#define portDISABLE_INTERRUPTS() \ |
||||||
|
{ \
|
||||||
|
__set_BASEPRI( configMAX_SYSCALL_INTERRUPT_PRIORITY ); \
|
||||||
|
__DSB(); \
|
||||||
|
__ISB(); \
|
||||||
|
} |
||||||
|
|
||||||
|
#define portENABLE_INTERRUPTS() __set_BASEPRI( 0 ) |
||||||
|
#define portENTER_CRITICAL() vPortEnterCritical() |
||||||
|
#define portEXIT_CRITICAL() vPortExitCritical() |
||||||
|
#define portSET_INTERRUPT_MASK_FROM_ISR() __get_BASEPRI(); portDISABLE_INTERRUPTS() |
||||||
|
#define portCLEAR_INTERRUPT_MASK_FROM_ISR(x) __set_BASEPRI( x ) |
||||||
|
/*-----------------------------------------------------------*/ |
||||||
|
|
||||||
|
/* Tickless idle/low power functionality. */ |
||||||
|
#ifndef portSUPPRESS_TICKS_AND_SLEEP |
||||||
|
extern void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime ); |
||||||
|
#define portSUPPRESS_TICKS_AND_SLEEP( xExpectedIdleTime ) vPortSuppressTicksAndSleep( xExpectedIdleTime ) |
||||||
|
#endif |
||||||
|
|
||||||
|
/*-----------------------------------------------------------*/ |
||||||
|
|
||||||
|
/* Task function macros as described on the FreeRTOS.org WEB site. These are
|
||||||
|
not necessary for to use this port. They are defined so the common demo files |
||||||
|
(which build with all the ports) will build. */ |
||||||
|
#define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters ) |
||||||
|
#define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters ) |
||||||
|
/*-----------------------------------------------------------*/ |
||||||
|
|
||||||
|
#ifdef configASSERT |
||||||
|
void vPortValidateInterruptPriority( void ); |
||||||
|
#define portASSERT_IF_INTERRUPT_PRIORITY_INVALID() vPortValidateInterruptPriority() |
||||||
|
#endif |
||||||
|
|
||||||
|
/* portNOP() is not required by this port. */ |
||||||
|
#define portNOP() |
||||||
|
|
||||||
|
#define portINLINE __inline |
||||||
|
|
||||||
|
#ifndef portFORCE_INLINE |
||||||
|
#define portFORCE_INLINE inline __attribute__(( always_inline)) |
||||||
|
#endif |
||||||
|
|
||||||
|
/*-----------------------------------------------------------*/ |
||||||
|
|
||||||
|
portFORCE_INLINE static BaseType_t xPortIsInsideInterrupt( void ) |
||||||
|
{ |
||||||
|
uint32_t ulCurrentInterrupt; |
||||||
|
BaseType_t xReturn; |
||||||
|
|
||||||
|
/* Obtain the number of the currently executing interrupt. */ |
||||||
|
__asm volatile( "mrs %0, ipsr" : "=r"( ulCurrentInterrupt ) :: "memory" ); |
||||||
|
|
||||||
|
if( ulCurrentInterrupt == 0 ) |
||||||
|
{ |
||||||
|
xReturn = pdFALSE; |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
xReturn = pdTRUE; |
||||||
|
} |
||||||
|
|
||||||
|
return xReturn; |
||||||
|
} |
||||||
|
|
||||||
|
/*-----------------------------------------------------------*/ |
||||||
|
|
||||||
|
/* Suppress warnings that are generated by the IAR tools, but cannot be fixed in
|
||||||
|
the source code because to do so would cause other compilers to generate |
||||||
|
warnings. */ |
||||||
|
#pragma diag_suppress=Pe191 |
||||||
|
#pragma diag_suppress=Pa082 |
||||||
|
|
||||||
|
#ifdef __cplusplus |
||||||
|
} |
||||||
|
#endif |
||||||
|
|
||||||
|
#endif /* PORTMACRO_H */ |
||||||
|
|
||||||
@ -1,100 +0,0 @@ |
|||||||
/* USER CODE BEGIN Header */ |
|
||||||
/**
|
|
||||||
****************************************************************************** |
|
||||||
* @file : usb_device.c |
|
||||||
* @version : v1.0_Cube |
|
||||||
* @brief : This file implements the USB Device |
|
||||||
****************************************************************************** |
|
||||||
* @attention |
|
||||||
* |
|
||||||
* Copyright (c) 2023 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 "usb_device.h" |
|
||||||
#include "usbd_core.h" |
|
||||||
#include "usbd_desc.h" |
|
||||||
#include "usbd_msc.h" |
|
||||||
#include "usbd_storage_if.h" |
|
||||||
|
|
||||||
/* USER CODE BEGIN Includes */ |
|
||||||
|
|
||||||
/* USER CODE END Includes */ |
|
||||||
|
|
||||||
/* USER CODE BEGIN PV */ |
|
||||||
/* Private variables ---------------------------------------------------------*/ |
|
||||||
|
|
||||||
/* USER CODE END PV */ |
|
||||||
|
|
||||||
/* USER CODE BEGIN PFP */ |
|
||||||
/* Private function prototypes -----------------------------------------------*/ |
|
||||||
|
|
||||||
/* USER CODE END PFP */ |
|
||||||
|
|
||||||
/* USB Device Core handle declaration. */ |
|
||||||
USBD_HandleTypeDef hUsbDeviceHS; |
|
||||||
|
|
||||||
/*
|
|
||||||
* -- Insert your variables declaration here -- |
|
||||||
*/ |
|
||||||
/* USER CODE BEGIN 0 */ |
|
||||||
|
|
||||||
/* USER CODE END 0 */ |
|
||||||
|
|
||||||
/*
|
|
||||||
* -- Insert your external function declaration here -- |
|
||||||
*/ |
|
||||||
/* USER CODE BEGIN 1 */ |
|
||||||
|
|
||||||
/* USER CODE END 1 */ |
|
||||||
|
|
||||||
/**
|
|
||||||
* Init USB device Library, add supported class and start the library |
|
||||||
* @retval None |
|
||||||
*/ |
|
||||||
void MX_USB_DEVICE_Init(void) |
|
||||||
{ |
|
||||||
/* USER CODE BEGIN USB_DEVICE_Init_PreTreatment */ |
|
||||||
|
|
||||||
/* USER CODE END USB_DEVICE_Init_PreTreatment */ |
|
||||||
|
|
||||||
/* Init Device Library, add supported class and start the library. */ |
|
||||||
if (USBD_Init(&hUsbDeviceHS, &HS_Desc, DEVICE_HS) != USBD_OK) |
|
||||||
{ |
|
||||||
Error_Handler(); |
|
||||||
} |
|
||||||
if (USBD_RegisterClass(&hUsbDeviceHS, &USBD_MSC) != USBD_OK) |
|
||||||
{ |
|
||||||
Error_Handler(); |
|
||||||
} |
|
||||||
if (USBD_MSC_RegisterStorage(&hUsbDeviceHS, &USBD_Storage_Interface_fops_HS) != USBD_OK) |
|
||||||
{ |
|
||||||
Error_Handler(); |
|
||||||
} |
|
||||||
if (USBD_Start(&hUsbDeviceHS) != USBD_OK) |
|
||||||
{ |
|
||||||
Error_Handler(); |
|
||||||
} |
|
||||||
|
|
||||||
/* USER CODE BEGIN USB_DEVICE_Init_PostTreatment */ |
|
||||||
|
|
||||||
/* USER CODE END USB_DEVICE_Init_PostTreatment */ |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
@ -1,102 +0,0 @@ |
|||||||
/* USER CODE BEGIN Header */ |
|
||||||
/**
|
|
||||||
****************************************************************************** |
|
||||||
* @file : usb_device.h |
|
||||||
* @version : v1.0_Cube |
|
||||||
* @brief : Header for usb_device.c file. |
|
||||||
****************************************************************************** |
|
||||||
* @attention |
|
||||||
* |
|
||||||
* Copyright (c) 2023 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 */ |
|
||||||
|
|
||||||
/* Define to prevent recursive inclusion -------------------------------------*/ |
|
||||||
#ifndef __USB_DEVICE__H__ |
|
||||||
#define __USB_DEVICE__H__ |
|
||||||
|
|
||||||
#ifdef __cplusplus |
|
||||||
extern "C" { |
|
||||||
#endif |
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/ |
|
||||||
#include "stm32f4xx.h" |
|
||||||
#include "stm32f4xx_hal.h" |
|
||||||
#include "usbd_def.h" |
|
||||||
|
|
||||||
/* USER CODE BEGIN INCLUDE */ |
|
||||||
|
|
||||||
/* USER CODE END INCLUDE */ |
|
||||||
|
|
||||||
/** @addtogroup USBD_OTG_DRIVER
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_DEVICE USBD_DEVICE
|
|
||||||
* @brief Device file for Usb otg low level driver. |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_DEVICE_Exported_Variables USBD_DEVICE_Exported_Variables
|
|
||||||
* @brief Public variables. |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/* Private variables ---------------------------------------------------------*/ |
|
||||||
/* USER CODE BEGIN PV */ |
|
||||||
|
|
||||||
/* USER CODE END PV */ |
|
||||||
|
|
||||||
/* Private function prototypes -----------------------------------------------*/ |
|
||||||
/* USER CODE BEGIN PFP */ |
|
||||||
|
|
||||||
/* USER CODE END PFP */ |
|
||||||
|
|
||||||
/*
|
|
||||||
* -- Insert your variables declaration here -- |
|
||||||
*/ |
|
||||||
/* USER CODE BEGIN VARIABLES */ |
|
||||||
|
|
||||||
/* USER CODE END VARIABLES */ |
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_DEVICE_Exported_FunctionsPrototype USBD_DEVICE_Exported_FunctionsPrototype
|
|
||||||
* @brief Declaration of public functions for Usb device. |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/** USB Device initialization function. */ |
|
||||||
void MX_USB_DEVICE_Init(void); |
|
||||||
|
|
||||||
/*
|
|
||||||
* -- Insert functions declaration here -- |
|
||||||
*/ |
|
||||||
/* USER CODE BEGIN FD */ |
|
||||||
|
|
||||||
/* USER CODE END FD */ |
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
#ifdef __cplusplus |
|
||||||
} |
|
||||||
#endif |
|
||||||
|
|
||||||
#endif /* __USB_DEVICE__H__ */ |
|
||||||
@ -1,447 +0,0 @@ |
|||||||
/* USER CODE BEGIN Header */ |
|
||||||
/**
|
|
||||||
****************************************************************************** |
|
||||||
* @file : App/usbd_desc.c |
|
||||||
* @version : v1.0_Cube |
|
||||||
* @brief : This file implements the USB device descriptors. |
|
||||||
****************************************************************************** |
|
||||||
* @attention |
|
||||||
* |
|
||||||
* Copyright (c) 2023 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 "usbd_core.h" |
|
||||||
#include "usbd_desc.h" |
|
||||||
#include "usbd_conf.h" |
|
||||||
|
|
||||||
/* USER CODE BEGIN INCLUDE */ |
|
||||||
|
|
||||||
/* USER CODE END INCLUDE */ |
|
||||||
|
|
||||||
/* Private typedef -----------------------------------------------------------*/ |
|
||||||
/* Private define ------------------------------------------------------------*/ |
|
||||||
/* Private macro -------------------------------------------------------------*/ |
|
||||||
|
|
||||||
/* USER CODE BEGIN PV */ |
|
||||||
/* Private variables ---------------------------------------------------------*/ |
|
||||||
|
|
||||||
/* USER CODE END PV */ |
|
||||||
|
|
||||||
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @addtogroup USBD_DESC
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_DESC_Private_TypesDefinitions USBD_DESC_Private_TypesDefinitions
|
|
||||||
* @brief Private types. |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/* USER CODE BEGIN PRIVATE_TYPES */ |
|
||||||
|
|
||||||
/* USER CODE END PRIVATE_TYPES */ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_DESC_Private_Defines USBD_DESC_Private_Defines
|
|
||||||
* @brief Private defines. |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
#define USBD_VID 1155 |
|
||||||
#define USBD_LANGID_STRING 1033 |
|
||||||
#define USBD_MANUFACTURER_STRING "STMicroelectronics" |
|
||||||
#define USBD_PID_HS 22314 |
|
||||||
#define USBD_PRODUCT_STRING_HS "STM32 Mass Storage" |
|
||||||
#define USBD_CONFIGURATION_STRING_HS "MSC Config" |
|
||||||
#define USBD_INTERFACE_STRING_HS "MSC Interface" |
|
||||||
|
|
||||||
#define USB_SIZ_BOS_DESC 0x0C |
|
||||||
|
|
||||||
/* USER CODE BEGIN PRIVATE_DEFINES */ |
|
||||||
|
|
||||||
/* USER CODE END PRIVATE_DEFINES */ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/* USER CODE BEGIN 0 */ |
|
||||||
|
|
||||||
/* USER CODE END 0 */ |
|
||||||
|
|
||||||
/** @defgroup USBD_DESC_Private_Macros USBD_DESC_Private_Macros
|
|
||||||
* @brief Private macros. |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/* USER CODE BEGIN PRIVATE_MACRO */ |
|
||||||
|
|
||||||
/* USER CODE END PRIVATE_MACRO */ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_DESC_Private_FunctionPrototypes USBD_DESC_Private_FunctionPrototypes
|
|
||||||
* @brief Private functions declaration. |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
static void Get_SerialNum(void); |
|
||||||
static void IntToUnicode(uint32_t value, uint8_t * pbuf, uint8_t len); |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_DESC_Private_FunctionPrototypes USBD_DESC_Private_FunctionPrototypes
|
|
||||||
* @brief Private functions declaration for HS. |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
uint8_t * USBD_HS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); |
|
||||||
uint8_t * USBD_HS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); |
|
||||||
uint8_t * USBD_HS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); |
|
||||||
uint8_t * USBD_HS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); |
|
||||||
uint8_t * USBD_HS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); |
|
||||||
uint8_t * USBD_HS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); |
|
||||||
uint8_t * USBD_HS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); |
|
||||||
|
|
||||||
#if (USBD_LPM_ENABLED == 1) |
|
||||||
uint8_t * USBD_HS_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t *length); |
|
||||||
#endif /* (USBD_LPM_ENABLED == 1) */ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_DESC_Private_Variables USBD_DESC_Private_Variables
|
|
||||||
* @brief Private variables. |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
USBD_DescriptorsTypeDef HS_Desc = |
|
||||||
{ |
|
||||||
USBD_HS_DeviceDescriptor |
|
||||||
, USBD_HS_LangIDStrDescriptor |
|
||||||
, USBD_HS_ManufacturerStrDescriptor |
|
||||||
, USBD_HS_ProductStrDescriptor |
|
||||||
, USBD_HS_SerialStrDescriptor |
|
||||||
, USBD_HS_ConfigStrDescriptor |
|
||||||
, USBD_HS_InterfaceStrDescriptor |
|
||||||
#if (USBD_LPM_ENABLED == 1) |
|
||||||
, USBD_HS_USR_BOSDescriptor |
|
||||||
#endif /* (USBD_LPM_ENABLED == 1) */ |
|
||||||
}; |
|
||||||
|
|
||||||
#if defined ( __ICCARM__ ) /* IAR Compiler */ |
|
||||||
#pragma data_alignment=4 |
|
||||||
#endif /* defined ( __ICCARM__ ) */ |
|
||||||
/** USB standard device descriptor. */ |
|
||||||
__ALIGN_BEGIN uint8_t USBD_HS_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = |
|
||||||
{ |
|
||||||
0x12, /*bLength */ |
|
||||||
USB_DESC_TYPE_DEVICE, /*bDescriptorType*/ |
|
||||||
#if (USBD_LPM_ENABLED == 1) |
|
||||||
0x01, /*bcdUSB */ /* changed to USB version 2.01
|
|
||||||
in order to support LPM L1 suspend |
|
||||||
resume test of USBCV3.0*/ |
|
||||||
#else |
|
||||||
0x00, /*bcdUSB */ |
|
||||||
#endif /* (USBD_LPM_ENABLED == 1) */ |
|
||||||
|
|
||||||
0x02, |
|
||||||
0x00, /*bDeviceClass*/ |
|
||||||
0x00, /*bDeviceSubClass*/ |
|
||||||
0x00, /*bDeviceProtocol*/ |
|
||||||
USB_MAX_EP0_SIZE, /*bMaxPacketSize*/ |
|
||||||
LOBYTE(USBD_VID), /*idVendor*/ |
|
||||||
HIBYTE(USBD_VID), /*idVendor*/ |
|
||||||
LOBYTE(USBD_PID_HS), /*idProduct*/ |
|
||||||
HIBYTE(USBD_PID_HS), /*idProduct*/ |
|
||||||
0x00, /*bcdDevice rel. 2.00*/ |
|
||||||
0x02, |
|
||||||
USBD_IDX_MFC_STR, /*Index of manufacturer string*/ |
|
||||||
USBD_IDX_PRODUCT_STR, /*Index of product string*/ |
|
||||||
USBD_IDX_SERIAL_STR, /*Index of serial number string*/ |
|
||||||
USBD_MAX_NUM_CONFIGURATION /*bNumConfigurations*/ |
|
||||||
}; |
|
||||||
|
|
||||||
/** BOS descriptor. */ |
|
||||||
#if (USBD_LPM_ENABLED == 1) |
|
||||||
#if defined ( __ICCARM__ ) /* IAR Compiler */ |
|
||||||
#pragma data_alignment=4 |
|
||||||
#endif /* defined ( __ICCARM__ ) */ |
|
||||||
__ALIGN_BEGIN uint8_t USBD_HS_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END = |
|
||||||
{ |
|
||||||
0x5, |
|
||||||
USB_DESC_TYPE_BOS, |
|
||||||
0xC, |
|
||||||
0x0, |
|
||||||
0x1, /* 1 device capability */ |
|
||||||
/* device capability */ |
|
||||||
0x7, |
|
||||||
USB_DEVICE_CAPABITY_TYPE, |
|
||||||
0x2, |
|
||||||
0x2, /*LPM capability bit set */ |
|
||||||
0x0, |
|
||||||
0x0, |
|
||||||
0x0 |
|
||||||
}; |
|
||||||
#endif /* (USBD_LPM_ENABLED == 1) */ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_DESC_Private_Variables USBD_DESC_Private_Variables
|
|
||||||
* @brief Private variables. |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
#if defined ( __ICCARM__ ) /* IAR Compiler */ |
|
||||||
#pragma data_alignment=4 |
|
||||||
#endif /* defined ( __ICCARM__ ) */ |
|
||||||
|
|
||||||
/** USB lang identifier descriptor. */ |
|
||||||
__ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END = |
|
||||||
{ |
|
||||||
USB_LEN_LANGID_STR_DESC, |
|
||||||
USB_DESC_TYPE_STRING, |
|
||||||
LOBYTE(USBD_LANGID_STRING), |
|
||||||
HIBYTE(USBD_LANGID_STRING) |
|
||||||
}; |
|
||||||
|
|
||||||
#if defined ( __ICCARM__ ) /* IAR Compiler */ |
|
||||||
#pragma data_alignment=4 |
|
||||||
#endif /* defined ( __ICCARM__ ) */ |
|
||||||
/* Internal string descriptor. */ |
|
||||||
__ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END; |
|
||||||
|
|
||||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */ |
|
||||||
#pragma data_alignment=4 |
|
||||||
#endif |
|
||||||
__ALIGN_BEGIN uint8_t USBD_StringSerial[USB_SIZ_STRING_SERIAL] __ALIGN_END = { |
|
||||||
USB_SIZ_STRING_SERIAL, |
|
||||||
USB_DESC_TYPE_STRING, |
|
||||||
}; |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_DESC_Private_Functions USBD_DESC_Private_Functions
|
|
||||||
* @brief Private functions. |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Return the device descriptor |
|
||||||
* @param speed : Current device speed |
|
||||||
* @param length : Pointer to data length variable |
|
||||||
* @retval Pointer to descriptor buffer |
|
||||||
*/ |
|
||||||
uint8_t * USBD_HS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) |
|
||||||
{ |
|
||||||
UNUSED(speed); |
|
||||||
*length = sizeof(USBD_HS_DeviceDesc); |
|
||||||
return USBD_HS_DeviceDesc; |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Return the LangID string descriptor |
|
||||||
* @param speed : Current device speed |
|
||||||
* @param length : Pointer to data length variable |
|
||||||
* @retval Pointer to descriptor buffer |
|
||||||
*/ |
|
||||||
uint8_t * USBD_HS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) |
|
||||||
{ |
|
||||||
UNUSED(speed); |
|
||||||
*length = sizeof(USBD_LangIDDesc); |
|
||||||
return USBD_LangIDDesc; |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Return the product string descriptor |
|
||||||
* @param speed : current device speed |
|
||||||
* @param length : pointer to data length variable |
|
||||||
* @retval pointer to descriptor buffer |
|
||||||
*/ |
|
||||||
uint8_t * USBD_HS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) |
|
||||||
{ |
|
||||||
if(speed == 0) |
|
||||||
{ |
|
||||||
USBD_GetString((uint8_t *)USBD_PRODUCT_STRING_HS, USBD_StrDesc, length); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
USBD_GetString((uint8_t *)USBD_PRODUCT_STRING_HS, USBD_StrDesc, length); |
|
||||||
} |
|
||||||
return USBD_StrDesc; |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Return the manufacturer string descriptor |
|
||||||
* @param speed : Current device speed |
|
||||||
* @param length : Pointer to data length variable |
|
||||||
* @retval Pointer to descriptor buffer |
|
||||||
*/ |
|
||||||
uint8_t * USBD_HS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) |
|
||||||
{ |
|
||||||
UNUSED(speed); |
|
||||||
USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length); |
|
||||||
return USBD_StrDesc; |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Return the serial number string descriptor |
|
||||||
* @param speed : Current device speed |
|
||||||
* @param length : Pointer to data length variable |
|
||||||
* @retval Pointer to descriptor buffer |
|
||||||
*/ |
|
||||||
uint8_t * USBD_HS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) |
|
||||||
{ |
|
||||||
UNUSED(speed); |
|
||||||
*length = USB_SIZ_STRING_SERIAL; |
|
||||||
|
|
||||||
/* Update the serial number string descriptor with the data from the unique
|
|
||||||
* ID */ |
|
||||||
Get_SerialNum(); |
|
||||||
/* USER CODE BEGIN USBD_HS_SerialStrDescriptor */ |
|
||||||
|
|
||||||
/* USER CODE END USBD_HS_SerialStrDescriptor */ |
|
||||||
|
|
||||||
return (uint8_t *) USBD_StringSerial; |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Return the configuration string descriptor |
|
||||||
* @param speed : Current device speed |
|
||||||
* @param length : Pointer to data length variable |
|
||||||
* @retval Pointer to descriptor buffer |
|
||||||
*/ |
|
||||||
uint8_t * USBD_HS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) |
|
||||||
{ |
|
||||||
if(speed == USBD_SPEED_HIGH) |
|
||||||
{ |
|
||||||
USBD_GetString((uint8_t *)USBD_CONFIGURATION_STRING_HS, USBD_StrDesc, length); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
USBD_GetString((uint8_t *)USBD_CONFIGURATION_STRING_HS, USBD_StrDesc, length); |
|
||||||
} |
|
||||||
return USBD_StrDesc; |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Return the interface string descriptor |
|
||||||
* @param speed : Current device speed |
|
||||||
* @param length : Pointer to data length variable |
|
||||||
* @retval Pointer to descriptor buffer |
|
||||||
*/ |
|
||||||
uint8_t * USBD_HS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) |
|
||||||
{ |
|
||||||
if(speed == 0) |
|
||||||
{ |
|
||||||
USBD_GetString((uint8_t *)USBD_INTERFACE_STRING_HS, USBD_StrDesc, length); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
USBD_GetString((uint8_t *)USBD_INTERFACE_STRING_HS, USBD_StrDesc, length); |
|
||||||
} |
|
||||||
return USBD_StrDesc; |
|
||||||
} |
|
||||||
|
|
||||||
#if (USBD_LPM_ENABLED == 1) |
|
||||||
/**
|
|
||||||
* @brief Return the BOS descriptor |
|
||||||
* @param speed : Current device speed |
|
||||||
* @param length : Pointer to data length variable |
|
||||||
* @retval Pointer to descriptor buffer |
|
||||||
*/ |
|
||||||
uint8_t * USBD_HS_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) |
|
||||||
{ |
|
||||||
UNUSED(speed); |
|
||||||
*length = sizeof(USBD_HS_BOSDesc); |
|
||||||
return (uint8_t*)USBD_HS_BOSDesc; |
|
||||||
} |
|
||||||
#endif /* (USBD_LPM_ENABLED == 1) */ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Create the serial number string descriptor |
|
||||||
* @param None |
|
||||||
* @retval None |
|
||||||
*/ |
|
||||||
static void Get_SerialNum(void) |
|
||||||
{ |
|
||||||
uint32_t deviceserial0; |
|
||||||
uint32_t deviceserial1; |
|
||||||
uint32_t deviceserial2; |
|
||||||
|
|
||||||
deviceserial0 = *(uint32_t *) DEVICE_ID1; |
|
||||||
deviceserial1 = *(uint32_t *) DEVICE_ID2; |
|
||||||
deviceserial2 = *(uint32_t *) DEVICE_ID3; |
|
||||||
|
|
||||||
deviceserial0 += deviceserial2; |
|
||||||
|
|
||||||
if (deviceserial0 != 0) |
|
||||||
{ |
|
||||||
IntToUnicode(deviceserial0, &USBD_StringSerial[2], 8); |
|
||||||
IntToUnicode(deviceserial1, &USBD_StringSerial[18], 4); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Convert Hex 32Bits value into char |
|
||||||
* @param value: value to convert |
|
||||||
* @param pbuf: pointer to the buffer |
|
||||||
* @param len: buffer length |
|
||||||
* @retval None |
|
||||||
*/ |
|
||||||
static void IntToUnicode(uint32_t value, uint8_t * pbuf, uint8_t len) |
|
||||||
{ |
|
||||||
uint8_t idx = 0; |
|
||||||
|
|
||||||
for (idx = 0; idx < len; idx++) |
|
||||||
{ |
|
||||||
if (((value >> 28)) < 0xA) |
|
||||||
{ |
|
||||||
pbuf[2 * idx] = (value >> 28) + '0'; |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
pbuf[2 * idx] = (value >> 28) + 'A' - 10; |
|
||||||
} |
|
||||||
|
|
||||||
value = value << 4; |
|
||||||
|
|
||||||
pbuf[2 * idx + 1] = 0; |
|
||||||
} |
|
||||||
} |
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
@ -1,143 +0,0 @@ |
|||||||
/* USER CODE BEGIN Header */ |
|
||||||
/**
|
|
||||||
****************************************************************************** |
|
||||||
* @file : usbd_desc.c |
|
||||||
* @version : v1.0_Cube |
|
||||||
* @brief : Header for usbd_conf.c file. |
|
||||||
****************************************************************************** |
|
||||||
* @attention |
|
||||||
* |
|
||||||
* Copyright (c) 2023 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 */ |
|
||||||
/* Define to prevent recursive inclusion -------------------------------------*/ |
|
||||||
#ifndef __USBD_DESC__C__ |
|
||||||
#define __USBD_DESC__C__ |
|
||||||
|
|
||||||
#ifdef __cplusplus |
|
||||||
extern "C" { |
|
||||||
#endif |
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/ |
|
||||||
#include "usbd_def.h" |
|
||||||
|
|
||||||
/* USER CODE BEGIN INCLUDE */ |
|
||||||
|
|
||||||
/* USER CODE END INCLUDE */ |
|
||||||
|
|
||||||
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
|
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_DESC USBD_DESC
|
|
||||||
* @brief Usb device descriptors module. |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_DESC_Exported_Constants USBD_DESC_Exported_Constants
|
|
||||||
* @brief Constants. |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
#define DEVICE_ID1 (UID_BASE) |
|
||||||
#define DEVICE_ID2 (UID_BASE + 0x4) |
|
||||||
#define DEVICE_ID3 (UID_BASE + 0x8) |
|
||||||
|
|
||||||
#define USB_SIZ_STRING_SERIAL 0x1A |
|
||||||
|
|
||||||
/* USER CODE BEGIN EXPORTED_CONSTANTS */ |
|
||||||
|
|
||||||
/* USER CODE END EXPORTED_CONSTANTS */ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_DESC_Exported_Defines USBD_DESC_Exported_Defines
|
|
||||||
* @brief Defines. |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/* USER CODE BEGIN EXPORTED_DEFINES */ |
|
||||||
|
|
||||||
/* USER CODE END EXPORTED_DEFINES */ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_DESC_Exported_TypesDefinitions USBD_DESC_Exported_TypesDefinitions
|
|
||||||
* @brief Types. |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/* USER CODE BEGIN EXPORTED_TYPES */ |
|
||||||
|
|
||||||
/* USER CODE END EXPORTED_TYPES */ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_DESC_Exported_Macros USBD_DESC_Exported_Macros
|
|
||||||
* @brief Aliases. |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/* USER CODE BEGIN EXPORTED_MACRO */ |
|
||||||
|
|
||||||
/* USER CODE END EXPORTED_MACRO */ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_DESC_Exported_Variables USBD_DESC_Exported_Variables
|
|
||||||
* @brief Public variables. |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/** Descriptor for the Usb device. */ |
|
||||||
extern USBD_DescriptorsTypeDef HS_Desc; |
|
||||||
|
|
||||||
/* USER CODE BEGIN EXPORTED_VARIABLES */ |
|
||||||
|
|
||||||
/* USER CODE END EXPORTED_VARIABLES */ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_DESC_Exported_FunctionsPrototype USBD_DESC_Exported_FunctionsPrototype
|
|
||||||
* @brief Public functions declaration. |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/* USER CODE BEGIN EXPORTED_FUNCTIONS */ |
|
||||||
|
|
||||||
/* USER CODE END EXPORTED_FUNCTIONS */ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
#ifdef __cplusplus |
|
||||||
} |
|
||||||
#endif |
|
||||||
|
|
||||||
#endif /* __USBD_DESC__C__ */ |
|
||||||
|
|
||||||
@ -1,294 +0,0 @@ |
|||||||
/* USER CODE BEGIN Header */ |
|
||||||
/**
|
|
||||||
****************************************************************************** |
|
||||||
* @file : usbd_storage_if.c |
|
||||||
* @version : v1.0_Cube |
|
||||||
* @brief : Memory management layer. |
|
||||||
****************************************************************************** |
|
||||||
* @attention |
|
||||||
* |
|
||||||
* Copyright (c) 2023 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 "usbd_storage_if.h" |
|
||||||
|
|
||||||
/* USER CODE BEGIN INCLUDE */ |
|
||||||
|
|
||||||
/* USER CODE END INCLUDE */ |
|
||||||
|
|
||||||
/* Private typedef -----------------------------------------------------------*/ |
|
||||||
/* Private define ------------------------------------------------------------*/ |
|
||||||
/* Private macro -------------------------------------------------------------*/ |
|
||||||
|
|
||||||
/* USER CODE BEGIN PV */ |
|
||||||
/* Private variables ---------------------------------------------------------*/ |
|
||||||
|
|
||||||
/* USER CODE END PV */ |
|
||||||
|
|
||||||
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
|
|
||||||
* @brief Usb device. |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_STORAGE
|
|
||||||
* @brief Usb mass storage device module |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_STORAGE_Private_TypesDefinitions
|
|
||||||
* @brief Private types. |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/* USER CODE BEGIN PRIVATE_TYPES */ |
|
||||||
|
|
||||||
/* USER CODE END PRIVATE_TYPES */ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_STORAGE_Private_Defines
|
|
||||||
* @brief Private defines. |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
#define STORAGE_LUN_NBR 1 |
|
||||||
#define STORAGE_BLK_NBR 0x10000 |
|
||||||
#define STORAGE_BLK_SIZ 0x200 |
|
||||||
|
|
||||||
/* USER CODE BEGIN PRIVATE_DEFINES */ |
|
||||||
|
|
||||||
/* USER CODE END PRIVATE_DEFINES */ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_STORAGE_Private_Macros
|
|
||||||
* @brief Private macros. |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/* USER CODE BEGIN PRIVATE_MACRO */ |
|
||||||
|
|
||||||
/* USER CODE END PRIVATE_MACRO */ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_STORAGE_Private_Variables
|
|
||||||
* @brief Private variables. |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/* USER CODE BEGIN INQUIRY_DATA_HS */ |
|
||||||
/** USB Mass storage Standard Inquiry Data. */ |
|
||||||
const int8_t STORAGE_Inquirydata_HS[] = {/* 36 */ |
|
||||||
|
|
||||||
/* LUN 0 */ |
|
||||||
0x00, |
|
||||||
0x80, |
|
||||||
0x02, |
|
||||||
0x02, |
|
||||||
(STANDARD_INQUIRY_DATA_LEN - 5), |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
0x00, |
|
||||||
'S', 'T', 'M', ' ', ' ', ' ', ' ', ' ', /* Manufacturer : 8 bytes */ |
|
||||||
'P', 'r', 'o', 'd', 'u', 'c', 't', ' ', /* Product : 16 Bytes */ |
|
||||||
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', |
|
||||||
'0', '.', '0' ,'1' /* Version : 4 Bytes */ |
|
||||||
}; |
|
||||||
/* USER CODE END INQUIRY_DATA_HS */ |
|
||||||
|
|
||||||
/* USER CODE BEGIN PRIVATE_VARIABLES */ |
|
||||||
|
|
||||||
/* USER CODE END PRIVATE_VARIABLES */ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_STORAGE_Exported_Variables
|
|
||||||
* @brief Public variables. |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
extern USBD_HandleTypeDef hUsbDeviceHS; |
|
||||||
|
|
||||||
/* USER CODE BEGIN EXPORTED_VARIABLES */ |
|
||||||
|
|
||||||
/* USER CODE END EXPORTED_VARIABLES */ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_STORAGE_Private_FunctionPrototypes
|
|
||||||
* @brief Private functions declaration. |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
static int8_t STORAGE_Init_HS(uint8_t lun); |
|
||||||
static int8_t STORAGE_GetCapacity_HS(uint8_t lun, uint32_t *block_num, uint16_t *block_size); |
|
||||||
static int8_t STORAGE_IsReady_HS(uint8_t lun); |
|
||||||
static int8_t STORAGE_IsWriteProtected_HS(uint8_t lun); |
|
||||||
static int8_t STORAGE_Read_HS(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len); |
|
||||||
static int8_t STORAGE_Write_HS(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len); |
|
||||||
static int8_t STORAGE_GetMaxLun_HS(void); |
|
||||||
|
|
||||||
/* USER CODE BEGIN PRIVATE_FUNCTIONS_DECLARATION */ |
|
||||||
|
|
||||||
/* USER CODE END PRIVATE_FUNCTIONS_DECLARATION */ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
USBD_StorageTypeDef USBD_Storage_Interface_fops_HS = |
|
||||||
{ |
|
||||||
STORAGE_Init_HS, |
|
||||||
STORAGE_GetCapacity_HS, |
|
||||||
STORAGE_IsReady_HS, |
|
||||||
STORAGE_IsWriteProtected_HS, |
|
||||||
STORAGE_Read_HS, |
|
||||||
STORAGE_Write_HS, |
|
||||||
STORAGE_GetMaxLun_HS, |
|
||||||
(int8_t *)STORAGE_Inquirydata_HS |
|
||||||
}; |
|
||||||
|
|
||||||
/* Private functions ---------------------------------------------------------*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Initializes the storage unit (medium). |
|
||||||
* @param lun: Logical unit number. |
|
||||||
* @retval USBD_OK if all operations are OK else USBD_FAIL |
|
||||||
*/ |
|
||||||
int8_t STORAGE_Init_HS(uint8_t lun) |
|
||||||
{ |
|
||||||
/* USER CODE BEGIN 9 */ |
|
||||||
UNUSED(lun); |
|
||||||
|
|
||||||
return (USBD_OK); |
|
||||||
/* USER CODE END 9 */ |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Returns the medium capacity. |
|
||||||
* @param lun: Logical unit number. |
|
||||||
* @param block_num: Number of total block number. |
|
||||||
* @param block_size: Block size. |
|
||||||
* @retval USBD_OK if all operations are OK else USBD_FAIL |
|
||||||
*/ |
|
||||||
int8_t STORAGE_GetCapacity_HS(uint8_t lun, uint32_t *block_num, uint16_t *block_size) |
|
||||||
{ |
|
||||||
/* USER CODE BEGIN 10 */ |
|
||||||
UNUSED(lun); |
|
||||||
|
|
||||||
*block_num = STORAGE_BLK_NBR; |
|
||||||
*block_size = STORAGE_BLK_SIZ; |
|
||||||
return (USBD_OK); |
|
||||||
/* USER CODE END 10 */ |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Checks whether the medium is ready. |
|
||||||
* @param lun: Logical unit number. |
|
||||||
* @retval USBD_OK if all operations are OK else USBD_FAIL |
|
||||||
*/ |
|
||||||
int8_t STORAGE_IsReady_HS(uint8_t lun) |
|
||||||
{ |
|
||||||
/* USER CODE BEGIN 11 */ |
|
||||||
UNUSED(lun); |
|
||||||
|
|
||||||
return (USBD_OK); |
|
||||||
/* USER CODE END 11 */ |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Checks whether the medium is write protected. |
|
||||||
* @param lun: Logical unit number. |
|
||||||
* @retval USBD_OK if all operations are OK else USBD_FAIL |
|
||||||
*/ |
|
||||||
int8_t STORAGE_IsWriteProtected_HS(uint8_t lun) |
|
||||||
{ |
|
||||||
/* USER CODE BEGIN 12 */ |
|
||||||
return (USBD_OK); |
|
||||||
/* USER CODE END 12 */ |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Reads data from the medium. |
|
||||||
* @param lun: Logical unit number. |
|
||||||
* @param buf: data buffer. |
|
||||||
* @param blk_addr: Logical block address. |
|
||||||
* @param blk_len: Blocks number. |
|
||||||
* @retval USBD_OK if all operations are OK else USBD_FAIL |
|
||||||
*/ |
|
||||||
int8_t STORAGE_Read_HS(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len) |
|
||||||
{ |
|
||||||
/* USER CODE BEGIN 13 */ |
|
||||||
UNUSED(lun); |
|
||||||
UNUSED(buf); |
|
||||||
UNUSED(blk_addr); |
|
||||||
UNUSED(blk_len); |
|
||||||
|
|
||||||
return (USBD_OK); |
|
||||||
/* USER CODE END 13 */ |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Writes data into the medium. |
|
||||||
* @param lun: Logical unit number. |
|
||||||
* @param buf: data buffer. |
|
||||||
* @param blk_addr: Logical block address. |
|
||||||
* @param blk_len: Blocks number. |
|
||||||
* @retval USBD_OK if all operations are OK else USBD_FAIL |
|
||||||
*/ |
|
||||||
int8_t STORAGE_Write_HS(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len) |
|
||||||
{ |
|
||||||
/* USER CODE BEGIN 14 */ |
|
||||||
UNUSED(lun); |
|
||||||
UNUSED(buf); |
|
||||||
UNUSED(blk_addr); |
|
||||||
UNUSED(blk_len); |
|
||||||
|
|
||||||
return (USBD_OK); |
|
||||||
/* USER CODE END 14 */ |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Returns the Max Supported LUNs. |
|
||||||
* @param None |
|
||||||
* @retval Lun(s) number. |
|
||||||
*/ |
|
||||||
int8_t STORAGE_GetMaxLun_HS(void) |
|
||||||
{ |
|
||||||
/* USER CODE BEGIN 15 */ |
|
||||||
return (STORAGE_LUN_NBR - 1); |
|
||||||
/* USER CODE END 15 */ |
|
||||||
} |
|
||||||
|
|
||||||
/* USER CODE BEGIN PRIVATE_FUNCTIONS_IMPLEMENTATION */ |
|
||||||
|
|
||||||
/* USER CODE END PRIVATE_FUNCTIONS_IMPLEMENTATION */ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
@ -1,127 +0,0 @@ |
|||||||
/* USER CODE BEGIN Header */ |
|
||||||
/**
|
|
||||||
****************************************************************************** |
|
||||||
* @file : usbd_storage_if.h |
|
||||||
* @version : v1.0_Cube |
|
||||||
* @brief : Header for usbd_storage_if.c file. |
|
||||||
****************************************************************************** |
|
||||||
* @attention |
|
||||||
* |
|
||||||
* Copyright (c) 2023 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 */ |
|
||||||
|
|
||||||
/* Define to prevent recursive inclusion -------------------------------------*/ |
|
||||||
#ifndef __USBD_STORAGE_IF_H__ |
|
||||||
#define __USBD_STORAGE_IF_H__ |
|
||||||
|
|
||||||
#ifdef __cplusplus |
|
||||||
extern "C" { |
|
||||||
#endif |
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/ |
|
||||||
#include "usbd_msc.h" |
|
||||||
|
|
||||||
/* USER CODE BEGIN INCLUDE */ |
|
||||||
|
|
||||||
/* USER CODE END INCLUDE */ |
|
||||||
|
|
||||||
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
|
|
||||||
* @brief For Usb device. |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_STORAGE USBD_STORAGE
|
|
||||||
* @brief Header file for the usb_storage_if.c file |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_STORAGE_Exported_Defines USBD_STORAGE_Exported_Defines
|
|
||||||
* @brief Defines. |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/* USER CODE BEGIN EXPORTED_DEFINES */ |
|
||||||
|
|
||||||
/* USER CODE END EXPORTED_DEFINES */ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_STORAGE_Exported_Types USBD_STORAGE_Exported_Types
|
|
||||||
* @brief Types. |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/* USER CODE BEGIN EXPORTED_TYPES */ |
|
||||||
|
|
||||||
/* USER CODE END EXPORTED_TYPES */ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_STORAGE_Exported_Macros USBD_STORAGE_Exported_Macros
|
|
||||||
* @brief Aliases. |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/* USER CODE BEGIN EXPORTED_MACRO */ |
|
||||||
|
|
||||||
/* USER CODE END EXPORTED_MACRO */ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_STORAGE_Exported_Variables USBD_STORAGE_Exported_Variables
|
|
||||||
* @brief Public variables. |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/** STORAGE Interface callback. */ |
|
||||||
extern USBD_StorageTypeDef USBD_Storage_Interface_fops_HS; |
|
||||||
|
|
||||||
/* USER CODE BEGIN EXPORTED_VARIABLES */ |
|
||||||
|
|
||||||
/* USER CODE END EXPORTED_VARIABLES */ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_STORAGE_Exported_FunctionsPrototype USBD_STORAGE_Exported_FunctionsPrototype
|
|
||||||
* @brief Public functions declaration. |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/* USER CODE BEGIN EXPORTED_FUNCTIONS */ |
|
||||||
|
|
||||||
/* USER CODE END EXPORTED_FUNCTIONS */ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
#ifdef __cplusplus |
|
||||||
} |
|
||||||
#endif |
|
||||||
|
|
||||||
#endif /* __USBD_STORAGE_IF_H__ */ |
|
||||||
|
|
||||||
@ -1,680 +0,0 @@ |
|||||||
/* USER CODE BEGIN Header */ |
|
||||||
/**
|
|
||||||
****************************************************************************** |
|
||||||
* @file : Target/usbd_conf.c |
|
||||||
* @version : v1.0_Cube |
|
||||||
* @brief : This file implements the board support package for the USB device library |
|
||||||
****************************************************************************** |
|
||||||
* @attention |
|
||||||
* |
|
||||||
* Copyright (c) 2023 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 "stm32f4xx.h" |
|
||||||
#include "stm32f4xx_hal.h" |
|
||||||
#include "usbd_def.h" |
|
||||||
#include "usbd_core.h" |
|
||||||
|
|
||||||
#include "usbd_msc.h" |
|
||||||
|
|
||||||
/* USER CODE BEGIN Includes */ |
|
||||||
|
|
||||||
/* USER CODE END Includes */ |
|
||||||
|
|
||||||
/* Private typedef -----------------------------------------------------------*/ |
|
||||||
/* Private define ------------------------------------------------------------*/ |
|
||||||
/* Private macro -------------------------------------------------------------*/ |
|
||||||
|
|
||||||
/* USER CODE BEGIN PV */ |
|
||||||
/* Private variables ---------------------------------------------------------*/ |
|
||||||
|
|
||||||
/* USER CODE END PV */ |
|
||||||
|
|
||||||
PCD_HandleTypeDef hpcd_USB_OTG_HS; |
|
||||||
void Error_Handler(void); |
|
||||||
|
|
||||||
/* External functions --------------------------------------------------------*/ |
|
||||||
void SystemClock_Config(void); |
|
||||||
|
|
||||||
/* USER CODE BEGIN 0 */ |
|
||||||
|
|
||||||
/* USER CODE END 0 */ |
|
||||||
|
|
||||||
/* USER CODE BEGIN PFP */ |
|
||||||
/* Private function prototypes -----------------------------------------------*/ |
|
||||||
USBD_StatusTypeDef USBD_Get_USB_Status(HAL_StatusTypeDef hal_status); |
|
||||||
|
|
||||||
/* USER CODE END PFP */ |
|
||||||
|
|
||||||
/* Private functions ---------------------------------------------------------*/ |
|
||||||
|
|
||||||
/* USER CODE BEGIN 1 */ |
|
||||||
|
|
||||||
/* USER CODE END 1 */ |
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
LL Driver Callbacks (PCD -> USB Device Library) |
|
||||||
*******************************************************************************/ |
|
||||||
/* MSP Init */ |
|
||||||
|
|
||||||
void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle) |
|
||||||
{ |
|
||||||
GPIO_InitTypeDef GPIO_InitStruct = {0}; |
|
||||||
if(pcdHandle->Instance==USB_OTG_HS) |
|
||||||
{ |
|
||||||
/* USER CODE BEGIN USB_OTG_HS_MspInit 0 */ |
|
||||||
|
|
||||||
/* USER CODE END USB_OTG_HS_MspInit 0 */ |
|
||||||
|
|
||||||
__HAL_RCC_GPIOB_CLK_ENABLE(); |
|
||||||
/**USB_OTG_HS GPIO Configuration
|
|
||||||
PB14 ------> USB_OTG_HS_DM |
|
||||||
PB15 ------> USB_OTG_HS_DP |
|
||||||
*/ |
|
||||||
GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15; |
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL; |
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; |
|
||||||
GPIO_InitStruct.Alternate = GPIO_AF12_OTG_HS_FS; |
|
||||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
|
||||||
|
|
||||||
/* Peripheral clock enable */ |
|
||||||
__HAL_RCC_USB_OTG_HS_CLK_ENABLE(); |
|
||||||
|
|
||||||
/* Peripheral interrupt init */ |
|
||||||
HAL_NVIC_SetPriority(OTG_HS_IRQn, 11, 0); |
|
||||||
HAL_NVIC_EnableIRQ(OTG_HS_IRQn); |
|
||||||
/* USER CODE BEGIN USB_OTG_HS_MspInit 1 */ |
|
||||||
|
|
||||||
/* USER CODE END USB_OTG_HS_MspInit 1 */ |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle) |
|
||||||
{ |
|
||||||
if(pcdHandle->Instance==USB_OTG_HS) |
|
||||||
{ |
|
||||||
/* USER CODE BEGIN USB_OTG_HS_MspDeInit 0 */ |
|
||||||
|
|
||||||
/* USER CODE END USB_OTG_HS_MspDeInit 0 */ |
|
||||||
/* Peripheral clock disable */ |
|
||||||
__HAL_RCC_USB_OTG_HS_CLK_DISABLE(); |
|
||||||
|
|
||||||
/**USB_OTG_HS GPIO Configuration
|
|
||||||
PB14 ------> USB_OTG_HS_DM |
|
||||||
PB15 ------> USB_OTG_HS_DP |
|
||||||
*/ |
|
||||||
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_14|GPIO_PIN_15); |
|
||||||
|
|
||||||
/* Peripheral interrupt Deinit*/ |
|
||||||
HAL_NVIC_DisableIRQ(OTG_HS_IRQn); |
|
||||||
|
|
||||||
/* USER CODE BEGIN USB_OTG_HS_MspDeInit 1 */ |
|
||||||
|
|
||||||
/* USER CODE END USB_OTG_HS_MspDeInit 1 */ |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Setup stage callback |
|
||||||
* @param hpcd: PCD handle |
|
||||||
* @retval None |
|
||||||
*/ |
|
||||||
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
|
||||||
static void PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd) |
|
||||||
#else |
|
||||||
void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd) |
|
||||||
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
|
||||||
{ |
|
||||||
USBD_LL_SetupStage((USBD_HandleTypeDef*)hpcd->pData, (uint8_t *)hpcd->Setup); |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Data Out stage callback. |
|
||||||
* @param hpcd: PCD handle |
|
||||||
* @param epnum: Endpoint number |
|
||||||
* @retval None |
|
||||||
*/ |
|
||||||
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
|
||||||
static void PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) |
|
||||||
#else |
|
||||||
void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) |
|
||||||
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
|
||||||
{ |
|
||||||
USBD_LL_DataOutStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->OUT_ep[epnum].xfer_buff); |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Data In stage callback. |
|
||||||
* @param hpcd: PCD handle |
|
||||||
* @param epnum: Endpoint number |
|
||||||
* @retval None |
|
||||||
*/ |
|
||||||
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
|
||||||
static void PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) |
|
||||||
#else |
|
||||||
void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) |
|
||||||
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
|
||||||
{ |
|
||||||
USBD_LL_DataInStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->IN_ep[epnum].xfer_buff); |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief SOF callback. |
|
||||||
* @param hpcd: PCD handle |
|
||||||
* @retval None |
|
||||||
*/ |
|
||||||
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
|
||||||
static void PCD_SOFCallback(PCD_HandleTypeDef *hpcd) |
|
||||||
#else |
|
||||||
void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd) |
|
||||||
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
|
||||||
{ |
|
||||||
USBD_LL_SOF((USBD_HandleTypeDef*)hpcd->pData); |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Reset callback. |
|
||||||
* @param hpcd: PCD handle |
|
||||||
* @retval None |
|
||||||
*/ |
|
||||||
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
|
||||||
static void PCD_ResetCallback(PCD_HandleTypeDef *hpcd) |
|
||||||
#else |
|
||||||
void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd) |
|
||||||
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
|
||||||
{ |
|
||||||
USBD_SpeedTypeDef speed = USBD_SPEED_FULL; |
|
||||||
|
|
||||||
if ( hpcd->Init.speed == PCD_SPEED_HIGH) |
|
||||||
{ |
|
||||||
speed = USBD_SPEED_HIGH; |
|
||||||
} |
|
||||||
else if ( hpcd->Init.speed == PCD_SPEED_FULL) |
|
||||||
{ |
|
||||||
speed = USBD_SPEED_FULL; |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
Error_Handler(); |
|
||||||
} |
|
||||||
/* Set Speed. */ |
|
||||||
USBD_LL_SetSpeed((USBD_HandleTypeDef*)hpcd->pData, speed); |
|
||||||
|
|
||||||
/* Reset Device. */ |
|
||||||
USBD_LL_Reset((USBD_HandleTypeDef*)hpcd->pData); |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Suspend callback. |
|
||||||
* When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it) |
|
||||||
* @param hpcd: PCD handle |
|
||||||
* @retval None |
|
||||||
*/ |
|
||||||
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
|
||||||
static void PCD_SuspendCallback(PCD_HandleTypeDef *hpcd) |
|
||||||
#else |
|
||||||
void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd) |
|
||||||
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
|
||||||
{ |
|
||||||
/* Inform USB library that core enters in suspend Mode. */ |
|
||||||
USBD_LL_Suspend((USBD_HandleTypeDef*)hpcd->pData); |
|
||||||
__HAL_PCD_GATE_PHYCLOCK(hpcd); |
|
||||||
/* Enter in STOP mode. */ |
|
||||||
/* USER CODE BEGIN 2 */ |
|
||||||
if (hpcd->Init.low_power_enable) |
|
||||||
{ |
|
||||||
/* Set SLEEPDEEP bit and SleepOnExit of Cortex System Control Register. */ |
|
||||||
SCB->SCR |= (uint32_t)((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk)); |
|
||||||
} |
|
||||||
/* USER CODE END 2 */ |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Resume callback. |
|
||||||
* When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it) |
|
||||||
* @param hpcd: PCD handle |
|
||||||
* @retval None |
|
||||||
*/ |
|
||||||
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
|
||||||
static void PCD_ResumeCallback(PCD_HandleTypeDef *hpcd) |
|
||||||
#else |
|
||||||
void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd) |
|
||||||
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
|
||||||
{ |
|
||||||
/* USER CODE BEGIN 3 */ |
|
||||||
|
|
||||||
/* USER CODE END 3 */ |
|
||||||
USBD_LL_Resume((USBD_HandleTypeDef*)hpcd->pData); |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief ISOOUTIncomplete callback. |
|
||||||
* @param hpcd: PCD handle |
|
||||||
* @param epnum: Endpoint number |
|
||||||
* @retval None |
|
||||||
*/ |
|
||||||
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
|
||||||
static void PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) |
|
||||||
#else |
|
||||||
void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) |
|
||||||
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
|
||||||
{ |
|
||||||
USBD_LL_IsoOUTIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum); |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief ISOINIncomplete callback. |
|
||||||
* @param hpcd: PCD handle |
|
||||||
* @param epnum: Endpoint number |
|
||||||
* @retval None |
|
||||||
*/ |
|
||||||
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
|
||||||
static void PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) |
|
||||||
#else |
|
||||||
void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) |
|
||||||
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
|
||||||
{ |
|
||||||
USBD_LL_IsoINIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum); |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Connect callback. |
|
||||||
* @param hpcd: PCD handle |
|
||||||
* @retval None |
|
||||||
*/ |
|
||||||
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
|
||||||
static void PCD_ConnectCallback(PCD_HandleTypeDef *hpcd) |
|
||||||
#else |
|
||||||
void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd) |
|
||||||
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
|
||||||
{ |
|
||||||
USBD_LL_DevConnected((USBD_HandleTypeDef*)hpcd->pData); |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Disconnect callback. |
|
||||||
* @param hpcd: PCD handle |
|
||||||
* @retval None |
|
||||||
*/ |
|
||||||
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
|
||||||
static void PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd) |
|
||||||
#else |
|
||||||
void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd) |
|
||||||
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
|
||||||
{ |
|
||||||
USBD_LL_DevDisconnected((USBD_HandleTypeDef*)hpcd->pData); |
|
||||||
} |
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
LL Driver Interface (USB Device Library --> PCD) |
|
||||||
*******************************************************************************/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Initializes the low level portion of the device driver. |
|
||||||
* @param pdev: Device handle |
|
||||||
* @retval USBD status |
|
||||||
*/ |
|
||||||
USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev) |
|
||||||
{ |
|
||||||
/* Init USB Ip. */ |
|
||||||
if (pdev->id == DEVICE_HS) { |
|
||||||
/* Link the driver to the stack. */ |
|
||||||
hpcd_USB_OTG_HS.pData = pdev; |
|
||||||
pdev->pData = &hpcd_USB_OTG_HS; |
|
||||||
|
|
||||||
hpcd_USB_OTG_HS.Instance = USB_OTG_HS; |
|
||||||
hpcd_USB_OTG_HS.Init.dev_endpoints = 6; |
|
||||||
hpcd_USB_OTG_HS.Init.speed = PCD_SPEED_FULL; |
|
||||||
hpcd_USB_OTG_HS.Init.dma_enable = DISABLE; |
|
||||||
hpcd_USB_OTG_HS.Init.phy_itface = USB_OTG_EMBEDDED_PHY; |
|
||||||
hpcd_USB_OTG_HS.Init.Sof_enable = DISABLE; |
|
||||||
hpcd_USB_OTG_HS.Init.low_power_enable = DISABLE; |
|
||||||
hpcd_USB_OTG_HS.Init.lpm_enable = DISABLE; |
|
||||||
hpcd_USB_OTG_HS.Init.vbus_sensing_enable = DISABLE; |
|
||||||
hpcd_USB_OTG_HS.Init.use_dedicated_ep1 = DISABLE; |
|
||||||
hpcd_USB_OTG_HS.Init.use_external_vbus = DISABLE; |
|
||||||
if (HAL_PCD_Init(&hpcd_USB_OTG_HS) != HAL_OK) |
|
||||||
{ |
|
||||||
Error_Handler( ); |
|
||||||
} |
|
||||||
|
|
||||||
#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
|
||||||
/* Register USB PCD CallBacks */ |
|
||||||
HAL_PCD_RegisterCallback(&hpcd_USB_OTG_HS, HAL_PCD_SOF_CB_ID, PCD_SOFCallback); |
|
||||||
HAL_PCD_RegisterCallback(&hpcd_USB_OTG_HS, HAL_PCD_SETUPSTAGE_CB_ID, PCD_SetupStageCallback); |
|
||||||
HAL_PCD_RegisterCallback(&hpcd_USB_OTG_HS, HAL_PCD_RESET_CB_ID, PCD_ResetCallback); |
|
||||||
HAL_PCD_RegisterCallback(&hpcd_USB_OTG_HS, HAL_PCD_SUSPEND_CB_ID, PCD_SuspendCallback); |
|
||||||
HAL_PCD_RegisterCallback(&hpcd_USB_OTG_HS, HAL_PCD_RESUME_CB_ID, PCD_ResumeCallback); |
|
||||||
HAL_PCD_RegisterCallback(&hpcd_USB_OTG_HS, HAL_PCD_CONNECT_CB_ID, PCD_ConnectCallback); |
|
||||||
HAL_PCD_RegisterCallback(&hpcd_USB_OTG_HS, HAL_PCD_DISCONNECT_CB_ID, PCD_DisconnectCallback); |
|
||||||
|
|
||||||
HAL_PCD_RegisterDataOutStageCallback(&hpcd_USB_OTG_HS, PCD_DataOutStageCallback); |
|
||||||
HAL_PCD_RegisterDataInStageCallback(&hpcd_USB_OTG_HS, PCD_DataInStageCallback); |
|
||||||
HAL_PCD_RegisterIsoOutIncpltCallback(&hpcd_USB_OTG_HS, PCD_ISOOUTIncompleteCallback); |
|
||||||
HAL_PCD_RegisterIsoInIncpltCallback(&hpcd_USB_OTG_HS, PCD_ISOINIncompleteCallback); |
|
||||||
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
|
||||||
HAL_PCDEx_SetRxFiFo(&hpcd_USB_OTG_HS, 0x200); |
|
||||||
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_HS, 0, 0x80); |
|
||||||
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_HS, 1, 0x174); |
|
||||||
} |
|
||||||
return USBD_OK; |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief De-Initializes the low level portion of the device driver. |
|
||||||
* @param pdev: Device handle |
|
||||||
* @retval USBD status |
|
||||||
*/ |
|
||||||
USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev) |
|
||||||
{ |
|
||||||
HAL_StatusTypeDef hal_status = HAL_OK; |
|
||||||
USBD_StatusTypeDef usb_status = USBD_OK; |
|
||||||
|
|
||||||
hal_status = HAL_PCD_DeInit(pdev->pData); |
|
||||||
|
|
||||||
usb_status = USBD_Get_USB_Status(hal_status); |
|
||||||
|
|
||||||
return usb_status; |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Starts the low level portion of the device driver. |
|
||||||
* @param pdev: Device handle |
|
||||||
* @retval USBD status |
|
||||||
*/ |
|
||||||
USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev) |
|
||||||
{ |
|
||||||
HAL_StatusTypeDef hal_status = HAL_OK; |
|
||||||
USBD_StatusTypeDef usb_status = USBD_OK; |
|
||||||
|
|
||||||
hal_status = HAL_PCD_Start(pdev->pData); |
|
||||||
|
|
||||||
usb_status = USBD_Get_USB_Status(hal_status); |
|
||||||
|
|
||||||
return usb_status; |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Stops the low level portion of the device driver. |
|
||||||
* @param pdev: Device handle |
|
||||||
* @retval USBD status |
|
||||||
*/ |
|
||||||
USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev) |
|
||||||
{ |
|
||||||
HAL_StatusTypeDef hal_status = HAL_OK; |
|
||||||
USBD_StatusTypeDef usb_status = USBD_OK; |
|
||||||
|
|
||||||
hal_status = HAL_PCD_Stop(pdev->pData); |
|
||||||
|
|
||||||
usb_status = USBD_Get_USB_Status(hal_status); |
|
||||||
|
|
||||||
return usb_status; |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Opens an endpoint of the low level driver. |
|
||||||
* @param pdev: Device handle |
|
||||||
* @param ep_addr: Endpoint number |
|
||||||
* @param ep_type: Endpoint type |
|
||||||
* @param ep_mps: Endpoint max packet size |
|
||||||
* @retval USBD status |
|
||||||
*/ |
|
||||||
USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t ep_type, uint16_t ep_mps) |
|
||||||
{ |
|
||||||
HAL_StatusTypeDef hal_status = HAL_OK; |
|
||||||
USBD_StatusTypeDef usb_status = USBD_OK; |
|
||||||
|
|
||||||
hal_status = HAL_PCD_EP_Open(pdev->pData, ep_addr, ep_mps, ep_type); |
|
||||||
|
|
||||||
usb_status = USBD_Get_USB_Status(hal_status); |
|
||||||
|
|
||||||
return usb_status; |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Closes an endpoint of the low level driver. |
|
||||||
* @param pdev: Device handle |
|
||||||
* @param ep_addr: Endpoint number |
|
||||||
* @retval USBD status |
|
||||||
*/ |
|
||||||
USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) |
|
||||||
{ |
|
||||||
HAL_StatusTypeDef hal_status = HAL_OK; |
|
||||||
USBD_StatusTypeDef usb_status = USBD_OK; |
|
||||||
|
|
||||||
hal_status = HAL_PCD_EP_Close(pdev->pData, ep_addr); |
|
||||||
|
|
||||||
usb_status = USBD_Get_USB_Status(hal_status); |
|
||||||
|
|
||||||
return usb_status; |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Flushes an endpoint of the Low Level Driver. |
|
||||||
* @param pdev: Device handle |
|
||||||
* @param ep_addr: Endpoint number |
|
||||||
* @retval USBD status |
|
||||||
*/ |
|
||||||
USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) |
|
||||||
{ |
|
||||||
HAL_StatusTypeDef hal_status = HAL_OK; |
|
||||||
USBD_StatusTypeDef usb_status = USBD_OK; |
|
||||||
|
|
||||||
hal_status = HAL_PCD_EP_Flush(pdev->pData, ep_addr); |
|
||||||
|
|
||||||
usb_status = USBD_Get_USB_Status(hal_status); |
|
||||||
|
|
||||||
return usb_status; |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Sets a Stall condition on an endpoint of the Low Level Driver. |
|
||||||
* @param pdev: Device handle |
|
||||||
* @param ep_addr: Endpoint number |
|
||||||
* @retval USBD status |
|
||||||
*/ |
|
||||||
USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) |
|
||||||
{ |
|
||||||
HAL_StatusTypeDef hal_status = HAL_OK; |
|
||||||
USBD_StatusTypeDef usb_status = USBD_OK; |
|
||||||
|
|
||||||
hal_status = HAL_PCD_EP_SetStall(pdev->pData, ep_addr); |
|
||||||
|
|
||||||
usb_status = USBD_Get_USB_Status(hal_status); |
|
||||||
|
|
||||||
return usb_status; |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Clears a Stall condition on an endpoint of the Low Level Driver. |
|
||||||
* @param pdev: Device handle |
|
||||||
* @param ep_addr: Endpoint number |
|
||||||
* @retval USBD status |
|
||||||
*/ |
|
||||||
USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) |
|
||||||
{ |
|
||||||
HAL_StatusTypeDef hal_status = HAL_OK; |
|
||||||
USBD_StatusTypeDef usb_status = USBD_OK; |
|
||||||
|
|
||||||
hal_status = HAL_PCD_EP_ClrStall(pdev->pData, ep_addr); |
|
||||||
|
|
||||||
usb_status = USBD_Get_USB_Status(hal_status); |
|
||||||
|
|
||||||
return usb_status; |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Returns Stall condition. |
|
||||||
* @param pdev: Device handle |
|
||||||
* @param ep_addr: Endpoint number |
|
||||||
* @retval Stall (1: Yes, 0: No) |
|
||||||
*/ |
|
||||||
uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr) |
|
||||||
{ |
|
||||||
PCD_HandleTypeDef *hpcd = (PCD_HandleTypeDef*) pdev->pData; |
|
||||||
|
|
||||||
if((ep_addr & 0x80) == 0x80) |
|
||||||
{ |
|
||||||
return hpcd->IN_ep[ep_addr & 0x7F].is_stall; |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
return hpcd->OUT_ep[ep_addr & 0x7F].is_stall; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Assigns a USB address to the device. |
|
||||||
* @param pdev: Device handle |
|
||||||
* @param dev_addr: Device address |
|
||||||
* @retval USBD status |
|
||||||
*/ |
|
||||||
USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr) |
|
||||||
{ |
|
||||||
HAL_StatusTypeDef hal_status = HAL_OK; |
|
||||||
USBD_StatusTypeDef usb_status = USBD_OK; |
|
||||||
|
|
||||||
hal_status = HAL_PCD_SetAddress(pdev->pData, dev_addr); |
|
||||||
|
|
||||||
usb_status = USBD_Get_USB_Status(hal_status); |
|
||||||
|
|
||||||
return usb_status; |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Transmits data over an endpoint. |
|
||||||
* @param pdev: Device handle |
|
||||||
* @param ep_addr: Endpoint number |
|
||||||
* @param pbuf: Pointer to data to be sent |
|
||||||
* @param size: Data size |
|
||||||
* @retval USBD status |
|
||||||
*/ |
|
||||||
USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint32_t size) |
|
||||||
{ |
|
||||||
HAL_StatusTypeDef hal_status = HAL_OK; |
|
||||||
USBD_StatusTypeDef usb_status = USBD_OK; |
|
||||||
|
|
||||||
hal_status = HAL_PCD_EP_Transmit(pdev->pData, ep_addr, pbuf, size); |
|
||||||
|
|
||||||
usb_status = USBD_Get_USB_Status(hal_status); |
|
||||||
|
|
||||||
return usb_status; |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Prepares an endpoint for reception. |
|
||||||
* @param pdev: Device handle |
|
||||||
* @param ep_addr: Endpoint number |
|
||||||
* @param pbuf: Pointer to data to be received |
|
||||||
* @param size: Data size |
|
||||||
* @retval USBD status |
|
||||||
*/ |
|
||||||
USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint32_t size) |
|
||||||
{ |
|
||||||
HAL_StatusTypeDef hal_status = HAL_OK; |
|
||||||
USBD_StatusTypeDef usb_status = USBD_OK; |
|
||||||
|
|
||||||
hal_status = HAL_PCD_EP_Receive(pdev->pData, ep_addr, pbuf, size); |
|
||||||
|
|
||||||
usb_status = USBD_Get_USB_Status(hal_status); |
|
||||||
|
|
||||||
return usb_status; |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Returns the last transferred packet size. |
|
||||||
* @param pdev: Device handle |
|
||||||
* @param ep_addr: Endpoint number |
|
||||||
* @retval Received Data Size |
|
||||||
*/ |
|
||||||
uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr) |
|
||||||
{ |
|
||||||
return HAL_PCD_EP_GetRxCount((PCD_HandleTypeDef*) pdev->pData, ep_addr); |
|
||||||
} |
|
||||||
|
|
||||||
#ifdef USBD_HS_TESTMODE_ENABLE |
|
||||||
/**
|
|
||||||
* @brief Set High speed Test mode. |
|
||||||
* @param pdev: Device handle |
|
||||||
* @param testmode: test mode |
|
||||||
* @retval USBD Status |
|
||||||
*/ |
|
||||||
USBD_StatusTypeDef USBD_LL_SetTestMode(USBD_HandleTypeDef *pdev, uint8_t testmode) |
|
||||||
{ |
|
||||||
UNUSED(pdev); |
|
||||||
UNUSED(testmode); |
|
||||||
|
|
||||||
return USBD_OK; |
|
||||||
} |
|
||||||
#endif /* USBD_HS_TESTMODE_ENABLE */ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Static single allocation. |
|
||||||
* @param size: Size of allocated memory |
|
||||||
* @retval None |
|
||||||
*/ |
|
||||||
void *USBD_static_malloc(uint32_t size) |
|
||||||
{ |
|
||||||
static uint32_t mem[(sizeof(USBD_MSC_BOT_HandleTypeDef)/4)+1];/* On 32-bit boundary */ |
|
||||||
return mem; |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Dummy memory free |
|
||||||
* @param p: Pointer to allocated memory address |
|
||||||
* @retval None |
|
||||||
*/ |
|
||||||
void USBD_static_free(void *p) |
|
||||||
{ |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Delays routine for the USB Device Library. |
|
||||||
* @param Delay: Delay in ms |
|
||||||
* @retval None |
|
||||||
*/ |
|
||||||
void USBD_LL_Delay(uint32_t Delay) |
|
||||||
{ |
|
||||||
HAL_Delay(Delay); |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Returns the USB status depending on the HAL status: |
|
||||||
* @param hal_status: HAL status |
|
||||||
* @retval USB status |
|
||||||
*/ |
|
||||||
USBD_StatusTypeDef USBD_Get_USB_Status(HAL_StatusTypeDef hal_status) |
|
||||||
{ |
|
||||||
USBD_StatusTypeDef usb_status = USBD_OK; |
|
||||||
|
|
||||||
switch (hal_status) |
|
||||||
{ |
|
||||||
case HAL_OK : |
|
||||||
usb_status = USBD_OK; |
|
||||||
break; |
|
||||||
case HAL_ERROR : |
|
||||||
usb_status = USBD_FAIL; |
|
||||||
break; |
|
||||||
case HAL_BUSY : |
|
||||||
usb_status = USBD_BUSY; |
|
||||||
break; |
|
||||||
case HAL_TIMEOUT : |
|
||||||
usb_status = USBD_FAIL; |
|
||||||
break; |
|
||||||
default : |
|
||||||
usb_status = USBD_FAIL; |
|
||||||
break; |
|
||||||
} |
|
||||||
return usb_status; |
|
||||||
} |
|
||||||
@ -1,175 +0,0 @@ |
|||||||
/* USER CODE BEGIN Header */ |
|
||||||
/**
|
|
||||||
****************************************************************************** |
|
||||||
* @file : usbd_conf.h |
|
||||||
* @version : v1.0_Cube |
|
||||||
* @brief : Header for usbd_conf.c file. |
|
||||||
****************************************************************************** |
|
||||||
* @attention |
|
||||||
* |
|
||||||
* Copyright (c) 2023 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 */ |
|
||||||
|
|
||||||
/* Define to prevent recursive inclusion -------------------------------------*/ |
|
||||||
#ifndef __USBD_CONF__H__ |
|
||||||
#define __USBD_CONF__H__ |
|
||||||
|
|
||||||
#ifdef __cplusplus |
|
||||||
extern "C" { |
|
||||||
#endif |
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/ |
|
||||||
#include <stdio.h> |
|
||||||
#include <stdlib.h> |
|
||||||
#include <string.h> |
|
||||||
#include "main.h" |
|
||||||
#include "stm32f4xx.h" |
|
||||||
#include "stm32f4xx_hal.h" |
|
||||||
|
|
||||||
/* USER CODE BEGIN INCLUDE */ |
|
||||||
|
|
||||||
/* USER CODE END INCLUDE */ |
|
||||||
|
|
||||||
/** @addtogroup USBD_OTG_DRIVER
|
|
||||||
* @brief Driver for Usb device. |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_CONF USBD_CONF
|
|
||||||
* @brief Configuration file for Usb otg low level driver. |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_CONF_Exported_Variables USBD_CONF_Exported_Variables
|
|
||||||
* @brief Public variables. |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_CONF_Exported_Defines USBD_CONF_Exported_Defines
|
|
||||||
* @brief Defines for configuration of the Usb device. |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/*---------- -----------*/ |
|
||||||
#define USBD_MAX_NUM_INTERFACES 1U |
|
||||||
/*---------- -----------*/ |
|
||||||
#define USBD_MAX_NUM_CONFIGURATION 1U |
|
||||||
/*---------- -----------*/ |
|
||||||
#define USBD_MAX_STR_DESC_SIZ 512U |
|
||||||
/*---------- -----------*/ |
|
||||||
#define USBD_DEBUG_LEVEL 0U |
|
||||||
/*---------- -----------*/ |
|
||||||
#define USBD_LPM_ENABLED 0U |
|
||||||
/*---------- -----------*/ |
|
||||||
#define USBD_SELF_POWERED 1U |
|
||||||
/*---------- -----------*/ |
|
||||||
#define MSC_MEDIA_PACKET 4096U |
|
||||||
|
|
||||||
/****************************************/ |
|
||||||
/* #define for FS and HS identification */ |
|
||||||
#define DEVICE_FS 0 |
|
||||||
#define DEVICE_HS 1 |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_CONF_Exported_Macros USBD_CONF_Exported_Macros
|
|
||||||
* @brief Aliases. |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
/* Memory management macros make sure to use static memory allocation */ |
|
||||||
/** Alias for memory allocation. */ |
|
||||||
|
|
||||||
#define USBD_malloc (void *)USBD_static_malloc |
|
||||||
|
|
||||||
/** Alias for memory release. */ |
|
||||||
#define USBD_free USBD_static_free |
|
||||||
|
|
||||||
/** Alias for memory set. */ |
|
||||||
#define USBD_memset memset |
|
||||||
|
|
||||||
/** Alias for memory copy. */ |
|
||||||
#define USBD_memcpy memcpy |
|
||||||
|
|
||||||
/** Alias for delay. */ |
|
||||||
#define USBD_Delay HAL_Delay |
|
||||||
|
|
||||||
/* DEBUG macros */ |
|
||||||
|
|
||||||
#if (USBD_DEBUG_LEVEL > 0) |
|
||||||
#define USBD_UsrLog(...) printf(__VA_ARGS__);\ |
|
||||||
printf("\n"); |
|
||||||
#else |
|
||||||
#define USBD_UsrLog(...) |
|
||||||
#endif /* (USBD_DEBUG_LEVEL > 0U) */ |
|
||||||
|
|
||||||
#if (USBD_DEBUG_LEVEL > 1) |
|
||||||
|
|
||||||
#define USBD_ErrLog(...) printf("ERROR: ");\ |
|
||||||
printf(__VA_ARGS__);\
|
|
||||||
printf("\n"); |
|
||||||
#else |
|
||||||
#define USBD_ErrLog(...) |
|
||||||
#endif /* (USBD_DEBUG_LEVEL > 1U) */ |
|
||||||
|
|
||||||
#if (USBD_DEBUG_LEVEL > 2) |
|
||||||
#define USBD_DbgLog(...) printf("DEBUG : ");\ |
|
||||||
printf(__VA_ARGS__);\
|
|
||||||
printf("\n"); |
|
||||||
#else |
|
||||||
#define USBD_DbgLog(...) |
|
||||||
#endif /* (USBD_DEBUG_LEVEL > 2U) */ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_CONF_Exported_Types USBD_CONF_Exported_Types
|
|
||||||
* @brief Types. |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @defgroup USBD_CONF_Exported_FunctionsPrototype USBD_CONF_Exported_FunctionsPrototype
|
|
||||||
* @brief Declaration of public functions for Usb device. |
|
||||||
* @{ |
|
||||||
*/ |
|
||||||
|
|
||||||
/* Exported functions -------------------------------------------------------*/ |
|
||||||
void *USBD_static_malloc(uint32_t size); |
|
||||||
void USBD_static_free(void *p); |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @} |
|
||||||
*/ |
|
||||||
|
|
||||||
#ifdef __cplusplus |
|
||||||
} |
|
||||||
#endif |
|
||||||
|
|
||||||
#endif /* __USBD_CONF__H__ */ |
|
||||||
|
|
||||||
@ -1,233 +0,0 @@ |
|||||||
// i2c_ads1115.c
|
|
||||||
#include "i2c_ads1115.h" |
|
||||||
#include "stdlib.h" |
|
||||||
#include "stdio.h" |
|
||||||
|
|
||||||
/*
|
|
||||||
多路测量的话, 需要配置不同的 config_H config_L |
|
||||||
*/ |
|
||||||
|
|
||||||
static I2C_HandleTypeDef *pADS1115_I2C = &hi2c1; |
|
||||||
|
|
||||||
osThreadId_t ads1115TaskHandle; |
|
||||||
const osThreadAttr_t ads1115Task_attributes = { |
|
||||||
.name = "ads1115Task", |
|
||||||
.stack_size = 256 * 4, |
|
||||||
.priority = (osPriority_t) osPriorityNormal, |
|
||||||
}; |
|
||||||
|
|
||||||
osEventFlagsId_t ads1115EventHandle; |
|
||||||
const osEventFlagsAttr_t ads1115Event_attributes = { |
|
||||||
.name = "ads1115Event" |
|
||||||
}; |
|
||||||
|
|
||||||
// ads1115EventHandle = osEventFlagsNew (&ads1115Event_attributes);
|
|
||||||
// typedef enum
|
|
||||||
// {
|
|
||||||
// EV_READY, /*!< Startup finished. */
|
|
||||||
// EV_FRAME_RECEIVED, /*!< Frame received. */
|
|
||||||
// EV_EXECUTE, /*!< Execute function. */
|
|
||||||
// EV_FRAME_SENT /*!< Frame sent. */
|
|
||||||
// } eMBEventType;
|
|
||||||
// osEventFlagsSet(modbusEventHandle,eEvent);
|
|
||||||
// osEventFlagsClear (osEventFlagsId_t ef_id, uint32_t flags)
|
|
||||||
// recvedEvent = osEventFlagsWait (modbusEventHandle,
|
|
||||||
// EV_READY | EV_FRAME_RECEIVED | EV_EXECUTE |
|
|
||||||
// EV_FRAME_SENT, /* 接收任务感兴趣的事件 */
|
|
||||||
// 0,
|
|
||||||
// portMAX_DELAY); /* 指定超时事件,无限等待 */
|
|
||||||
|
|
||||||
ADS1115_TypeDef my_ads1115 = |
|
||||||
{ |
|
||||||
ads1115_init, |
|
||||||
NULL, |
|
||||||
ADS1115_REG_CONFIG_OS_START, |
|
||||||
ADS1115_REG_CONFIG_MUX_SINGLE_0, |
|
||||||
ADS1115_REG_CONFIG_PGA_4, |
|
||||||
ADS1115_REG_CONFIG_MODE_SINGLE, |
|
||||||
ADS1115_REG_CONFIG_DR_128, |
|
||||||
ADS1115_REG_CONFIG_COMP_MODE_TRADITIONAL, |
|
||||||
ADS1115_REG_CONFIG_COMP_POL_LOW, |
|
||||||
ADS1115_REG_CONFIG_COMP_LAT_NONLATCH, |
|
||||||
ADS1115_REG_CONFIG_COMP_QUE_DIS, |
|
||||||
0, |
|
||||||
0, |
|
||||||
0, |
|
||||||
{ 0, 0, 0 }, |
|
||||||
ADS1115_OUTPUT_UNIT_mv, // 默认输出毫伏
|
|
||||||
}; |
|
||||||
|
|
||||||
void ads1115_task(void) |
|
||||||
{ |
|
||||||
uint32_t event_flags; |
|
||||||
for (;;) |
|
||||||
{ |
|
||||||
// 启用中断发送,判断状态,
|
|
||||||
// 地址中断, 确认是哪I2C 设备通讯
|
|
||||||
/* code */ |
|
||||||
/* TODO 统一的超时机制 */ |
|
||||||
|
|
||||||
/* 事件来管理 */ |
|
||||||
event_flags = osEventFlagsWait (
|
|
||||||
ads1115EventHandle |
|
||||||
, ADS1115_Event_READY|ADS1115_Event_INIT|ADS1115_Event_TRANS_ONLY|ADS1115_Event_DATA_RCV |
|
||||||
, 0 |
|
||||||
, portMAX_DELAY ); |
|
||||||
if ( event_flags & (ADS1115_Event_READY|ADS1115_Event_INIT)
|
|
||||||
== (ADS1115_Event_READY|ADS1115_Event_INIT) ) |
|
||||||
{ |
|
||||||
// if (HAL_I2C_GetError(&hi2c1)!= HAL_I2C_ERROR_AF)
|
|
||||||
// {
|
|
||||||
// Error_Handler();
|
|
||||||
// }
|
|
||||||
// if (HAL_I2C_GetState(&hi2c1)!= HAL_I2C_STATE_READY)
|
|
||||||
// {
|
|
||||||
// Error_Handler();
|
|
||||||
// }
|
|
||||||
|
|
||||||
osEventFlagsClear(ads1115EventHandle, ADS1115_Event_INIT); |
|
||||||
osEventFlagsSet(ads1115EventHandle, ADS1115_Event_INIT_SUCCESS); |
|
||||||
} |
|
||||||
|
|
||||||
if ( event_flags & ( ADS1115_Event_READY|ADS1115_Event_TRANS_ONLY )
|
|
||||||
== (ADS1115_Event_READY|ADS1115_Event_TRANS_ONLY) ) |
|
||||||
{ |
|
||||||
osEventFlagsClear(ads1115EventHandle, ADS1115_Event_TRANS_ONLY); |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
if ( event_flags & ( ADS1115_Event_READY|ADS1115_Event_TRANS_FOR_DATA )
|
|
||||||
== (ADS1115_Event_READY|ADS1115_Event_TRANS_FOR_DATA) ) |
|
||||||
{ |
|
||||||
osEventFlagsClear(ads1115EventHandle, ADS1115_Event_TRANS_FOR_DATA); |
|
||||||
osEventFlagsSet(ads1115EventHandle, ADS1115_Event_DATA_RCV); |
|
||||||
|
|
||||||
} |
|
||||||
if ( event_flags & ( ADS1115_Event_READY|ADS1115_Event_DATA_RCV )
|
|
||||||
== ( ADS1115_Event_READY|ADS1115_Event_DATA_RCV ) ) |
|
||||||
{ |
|
||||||
osEventFlagsClear( ads1115EventHandle, ADS1115_Event_DATA_RCV );
|
|
||||||
} |
|
||||||
// __HAL_I2C_GET_FLAG(&hi2c1, I2C_FLAG_TXE) ;
|
|
||||||
osDelay(20); |
|
||||||
}
|
|
||||||
} |
|
||||||
|
|
||||||
void ads1115_port(void) |
|
||||||
{ |
|
||||||
ads1115TaskHandle = osThreadNew(ads1115_task, NULL, &ads1115Task_attributes); |
|
||||||
ads1115EventHandle = osEventFlagsNew (&ads1115Event_attributes); |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief |
|
||||||
* @param [in] ads1115_I2cHandle |
|
||||||
* @param [in] pointADD -- 读的寄存器地址 |
|
||||||
* @param [in] configH |
|
||||||
* @param [in] configL |
|
||||||
* |
|
||||||
* @details |
|
||||||
*/ |
|
||||||
int ads1115_init() |
|
||||||
{ |
|
||||||
uint8_t reg_data[3];
|
|
||||||
my_ads1115.hi2c= pADS1115_I2C; |
|
||||||
my_ads1115.config_H = my_ads1115.config_os|my_ads1115.config_mux |
|
||||||
|my_ads1115.config_PGA|my_ads1115.config_MODE; |
|
||||||
my_ads1115.config_L = my_ads1115.config_DR|my_ads1115.config_COMP_MODE|my_ads1115.config_COMP_POL |
|
||||||
|my_ads1115.config_COMP_LAT|my_ads1115.config_COMP_QUE ; |
|
||||||
reg_data[0] = 0x01; // point addr 8bit 配置寄存器
|
|
||||||
reg_data[1] = my_ads1115.config_H; // config_reg 高位
|
|
||||||
reg_data[2] = my_ads1115.config_L; // config_reg 低位
|
|
||||||
|
|
||||||
// TODO 阻塞式, 改为 DMA 中断模式, 配合定时器 , 或启用中断等待
|
|
||||||
// while (HAL_I2C_Master_Transmit(pADS1115_I2C, ADS1115_WRITE_ADDRESS, reg_data, 3, 2000) != HAL_OK)
|
|
||||||
// {
|
|
||||||
// if (HAL_I2C_GetError(pADS1115_I2C) != HAL_I2C_ERROR_AF)
|
|
||||||
// {
|
|
||||||
// printf("ads1115 Config Register error!!!\r\n");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
osEventFlagsSet ( ads1115TaskHandle, ADS1115_Event_INIT ); |
|
||||||
if (HAL_I2C_Master_Transmit_IT(pADS1115_I2C, ADS1115_WRITE_ADDRESS, reg_data, 3 ) != HAL_OK) |
|
||||||
{ |
|
||||||
return -1; |
|
||||||
} |
|
||||||
return 0; |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
int ads1115_setup(ADS1115_REG_CONFIG_MUX_Diff_TypeDef mux) |
|
||||||
{ |
|
||||||
my_ads1115.config_H &= ~0x70; |
|
||||||
my_ads1115.config_H &= mux; |
|
||||||
return 0; |
|
||||||
} |
|
||||||
|
|
||||||
int16_t ads1115_read_data( ) |
|
||||||
{ |
|
||||||
int16_t data; |
|
||||||
uint8_t rx_data[2] = {0}; |
|
||||||
|
|
||||||
// TODO 阻塞式, 改为 DMA 中断模式
|
|
||||||
// 读寄存器 0x00 十六位
|
|
||||||
while (HAL_I2C_Master_Transmit(pADS1115_I2C, ADS1115_WRITE_ADDRESS, 0x00, 1, 2000) != HAL_OK) |
|
||||||
{ |
|
||||||
if (HAL_I2C_GetError(pADS1115_I2C) != HAL_I2C_ERROR_AF) |
|
||||||
{ |
|
||||||
printf("ads1115 convert Register error!!!\r\n"); |
|
||||||
} |
|
||||||
} |
|
||||||
// 读两位
|
|
||||||
while (HAL_I2C_Master_Receive(pADS1115_I2C, ADS1115_READ_ADDRESS, rx_data, 2, 2000) != HAL_OK) |
|
||||||
{ |
|
||||||
if ( HAL_I2C_GetError(pADS1115_I2C) != HAL_I2C_ERROR_AF ) |
|
||||||
{ |
|
||||||
printf("ads1115 read data error!!!\r\n"); |
|
||||||
} |
|
||||||
} |
|
||||||
data = rx_data[0] * 256 + rx_data[1]; |
|
||||||
return data; |
|
||||||
} |
|
||||||
|
|
||||||
double ads1115_get_voltage_val( ) |
|
||||||
{ |
|
||||||
double val; |
|
||||||
int16_t ad_val; |
|
||||||
// TODO 去掉延时,使用寄存器的指示, setup 和读取数据分开执行
|
|
||||||
// ads1115_setup( pADS1115_I2C, pointADD, configH, configL );
|
|
||||||
ads1115_setup( ADS1115_REG_CONFIG_MUX_SINGLE_0 ); |
|
||||||
|
|
||||||
HAL_Delay(10); |
|
||||||
ad_val = ads1115_read_data( pADS1115_I2C ); |
|
||||||
if ( (ad_val == 0x7FFF) | (ad_val == 0X8000)) // 是否超量程了
|
|
||||||
{ |
|
||||||
ad_val = 0; |
|
||||||
// printf("over PGA\r\n");
|
|
||||||
} |
|
||||||
switch ((0x0E & my_ads1115.config_H) >> 1) // 量程对应的分辨率
|
|
||||||
{ |
|
||||||
case (0x00): |
|
||||||
val = (double)ad_val * 187.5 / 1000.0; //
|
|
||||||
break; |
|
||||||
case (0x01): |
|
||||||
val = (double)ad_val * 125 / 1000.0; |
|
||||||
break; |
|
||||||
case (0x02): |
|
||||||
val = (double)ad_val * 62.5 / 1000.0; |
|
||||||
break; |
|
||||||
case (0x03): |
|
||||||
val = (double)ad_val * 31.25 / 1000.0; |
|
||||||
break; |
|
||||||
case (0x04): |
|
||||||
val = (double)ad_val * 15.625 / 1000.0; |
|
||||||
break; |
|
||||||
case (0x05): |
|
||||||
val = (double)ad_val * 7.8125 / 1000.0; |
|
||||||
break; |
|
||||||
} |
|
||||||
|
|
||||||
return (my_ads1115.unit == ADS1115_OUTPUT_UNIT_mv)?val:(val/1000.0); |
|
||||||
|
|
||||||
} |
|
||||||
@ -1,249 +0,0 @@ |
|||||||
//i2c_ads1115.h
|
|
||||||
#ifndef __IIC_ADS1115_H |
|
||||||
#define __IIC_ADS1115_H |
|
||||||
#include "FreeRTOS.h" |
|
||||||
#include "task.h" |
|
||||||
#include "main.h" |
|
||||||
#include "cmsis_os.h" |
|
||||||
#include "i2c.h" |
|
||||||
|
|
||||||
#define ADS1115_WRITE_ADDRESS 0x90 |
|
||||||
#define ADS1115_READ_ADDRESS 0x91 |
|
||||||
//以下两个预处理作为配置寄存器预处理要更改其配在这里更改
|
|
||||||
//也可以添加新的预处理对不同通道的采集或者选取不同的采样速率等
|
|
||||||
|
|
||||||
/*事件开始 set, 事件完成 clear */ |
|
||||||
typedef enum |
|
||||||
{ |
|
||||||
ADS1115_Event_READY, /*!< Startup finished. */ |
|
||||||
ADS1115_Event_INIT,
|
|
||||||
ADS1115_Event_INIT_SUCCESS,
|
|
||||||
ADS1115_Event_TRANS_ONLY,
|
|
||||||
ADS1115_Event_TRANS_FOR_DATA,
|
|
||||||
ADS1115_Event_DATA_RCV,
|
|
||||||
} ADS1115_Event_TypeDef; |
|
||||||
|
|
||||||
typedef enum { |
|
||||||
ADS1115_WORK_STATE_WAITING, |
|
||||||
ADS1115_WORK_STATE_START, |
|
||||||
ADS1115_WORK_STATE_INIT, |
|
||||||
ADS1115_WORK_STATE_READY_GET_DATA, |
|
||||||
ADS1115_WORK_STATE_GET_DATA, |
|
||||||
ADS1115_WORK_STATE_GET_DATA_OK, |
|
||||||
ADS1115_WORK_STATE_ERROR, |
|
||||||
ADS1115_WORK_STATE_STOP |
|
||||||
}ADS1115_WORK_STATE_TypeDef; |
|
||||||
|
|
||||||
typedef enum { |
|
||||||
ADS1115_OUTPUT_UNIT_v, |
|
||||||
ADS1115_OUTPUT_UNIT_mv |
|
||||||
}ADS1115_OUTPUT_UNIT_TypeDef; |
|
||||||
|
|
||||||
|
|
||||||
//地址指针寄存器
|
|
||||||
typedef enum
|
|
||||||
{ |
|
||||||
ADS1115_REG_POINTER_CONVERT = 0x00, // 转换寄存器
|
|
||||||
ADS1115_REG_POINTER_CONFIG = 0x01 , // 配置寄存器 16bit
|
|
||||||
ADS1115_REG_POINTER_LOWTHRESH = 0x02 ,
|
|
||||||
ADS1115_REG_POINTER_HITHRESH = 0x03
|
|
||||||
} ADS1115_REG_POINTER_TypeDef; |
|
||||||
|
|
||||||
|
|
||||||
// 单次转换开始
|
|
||||||
typedef enum
|
|
||||||
{ |
|
||||||
ADS1115_REG_CONFIG_OS_START = (0x1U << 7),//设备单词转换开启 高字节的最高位
|
|
||||||
ADS1115_REG_CONFIG_OS_NULL = (0x0U << 7) |
|
||||||
} ADS1115_REG_CONFIG_OS_TypeDef; |
|
||||||
|
|
||||||
|
|
||||||
//输入引脚选择和输入方式选择
|
|
||||||
typedef enum
|
|
||||||
{ |
|
||||||
ADS1115_REG_CONFIG_MUX_Diff_01 = (0x0U << 4), // 差分输入0引脚和1引脚
|
|
||||||
ADS1115_REG_CONFIG_MUX_Diff_03 = (0x1U << 4), // 差分输入0引脚和3引脚
|
|
||||||
ADS1115_REG_CONFIG_MUX_Diff_13 = (0x2U << 4), // 差分输入1引脚和3引脚
|
|
||||||
ADS1115_REG_CONFIG_MUX_Diff_23 = (0x3U << 4), // 差分输入2引脚和3引脚
|
|
||||||
ADS1115_REG_CONFIG_MUX_SINGLE_0= (0x4U << 4), //单端输入 0
|
|
||||||
ADS1115_REG_CONFIG_MUX_SINGLE_1= (0x5U << 4), //单端输入 1
|
|
||||||
ADS1115_REG_CONFIG_MUX_SINGLE_2= (0x6U << 4), //单端输入 2
|
|
||||||
ADS1115_REG_CONFIG_MUX_SINGLE_3= (0x7U << 4) //单端输入 3
|
|
||||||
} ADS1115_REG_CONFIG_MUX_Diff_TypeDef; |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//量程选择
|
|
||||||
typedef enum
|
|
||||||
{ |
|
||||||
ADS1115_REG_CONFIG_PGA_6 = (0x0U << 1), // +/- 6.1144
|
|
||||||
ADS1115_REG_CONFIG_PGA_4 =(0x1U << 1), // +/- 4.096
|
|
||||||
ADS1115_REG_CONFIG_PGA_2 = (0x2U << 1), // +/- 2.048
|
|
||||||
ADS1115_REG_CONFIG_PGA_1 = (0x3U << 1) , // +/- 1.024
|
|
||||||
ADS1115_REG_CONFIG_PGA_05 = (0x4U << 1) , // +/- 0.512
|
|
||||||
ADS1115_REG_CONFIG_PGA_02 =(0x5U << 1) , // +/- 0.256
|
|
||||||
} ADS1115_REG_CONFIG_PGA_TypeDef; |
|
||||||
|
|
||||||
|
|
||||||
//运行方式
|
|
||||||
typedef enum
|
|
||||||
{ |
|
||||||
ADS1115_REG_CONFIG_MODE_SINGLE = (0x1U << 0) , // 单次
|
|
||||||
ADS1115_REG_CONFIG_MODE_CONTIN = (0x0U << 0) //连续转换
|
|
||||||
} ADS1115_REG_CONFIG_MODE_TypeDef; |
|
||||||
|
|
||||||
|
|
||||||
//转换速率
|
|
||||||
typedef enum
|
|
||||||
{ |
|
||||||
ADS1115_REG_CONFIG_DR_8 = (0x0U << 5), |
|
||||||
ADS1115_REG_CONFIG_DR_16= (0x1U << 5), |
|
||||||
ADS1115_REG_CONFIG_DR_32 = (0x2U << 5), |
|
||||||
ADS1115_REG_CONFIG_DR_64 = (0x3U << 5), |
|
||||||
ADS1115_REG_CONFIG_DR_128 = (0x4U << 5), |
|
||||||
ADS1115_REG_CONFIG_DR_250 = (0x5U << 5), |
|
||||||
ADS1115_REG_CONFIG_DR_475 = (0x6U << 5), |
|
||||||
ADS1115_REG_CONFIG_DR_860 = (0x7U << 5) |
|
||||||
} ADS1115_REG_CONFIG_DR_TypeDef; |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//比较器模式
|
|
||||||
typedef enum
|
|
||||||
{ |
|
||||||
ADS1115_REG_CONFIG_COMP_MODE_TRADITIONAL = (0x0U << 4),//默认
|
|
||||||
ADS1115_REG_CONFIG_COMP_MODE_WINDOW = (0x1U << 4) |
|
||||||
} ADS1115_REG_CONFIG_COMP_MODE_TypeDef; |
|
||||||
|
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{ |
|
||||||
ADS1115_REG_CONFIG_COMP_POL_LOW = (0x0U << 3),//默认
|
|
||||||
ADS1115_REG_CONFIG_COMP_POL_HIG = (0x1U << 3) |
|
||||||
} ADS1115_REG_CONFIG_COMP_POL_TypeDef; |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{ |
|
||||||
ADS1115_REG_CONFIG_COMP_LAT_NONLATCH = (0x0U << 2), |
|
||||||
ADS1115_REG_CONFIG_COMP_LAT_LATCH = (0x1U << 2) |
|
||||||
} ADS1115_REG_CONFIG_COMP_LAT_TypeDef; |
|
||||||
|
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{ |
|
||||||
ADS1115_REG_CONFIG_COMP_QUE_ONE= (0x0U << 0), |
|
||||||
ADS1115_REG_CONFIG_COMP_QUE_TWO= (0x1U << 0), |
|
||||||
ADS1115_REG_CONFIG_COMP_QUE_THR= (0x2U << 0), |
|
||||||
ADS1115_REG_CONFIG_COMP_QUE_DIS= (0x3U << 0) |
|
||||||
} ADS1115_REG_CONFIG_COMP_QUE_TypeDef; |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct{ |
|
||||||
void (*init)(void); |
|
||||||
I2C_HandleTypeDef *hi2c; |
|
||||||
|
|
||||||
uint8_t config_os; |
|
||||||
uint8_t config_mux; |
|
||||||
uint8_t config_PGA; |
|
||||||
uint8_t config_MODE; |
|
||||||
uint8_t config_DR; |
|
||||||
uint8_t config_COMP_MODE; |
|
||||||
uint8_t config_COMP_POL; |
|
||||||
uint8_t config_COMP_LAT; |
|
||||||
uint8_t config_COMP_QUE; |
|
||||||
uint8_t point_ADDR; // 要读取的数据指针地址
|
|
||||||
volatile uint8_t config_H; |
|
||||||
volatile uint8_t config_L; |
|
||||||
uint8_t reg_data[3]; |
|
||||||
ADS1115_OUTPUT_UNIT_TypeDef unit; |
|
||||||
double result[4]; |
|
||||||
}ADS1115_TypeDef; |
|
||||||
|
|
||||||
extern ADS1115_TypeDef my_ads1115; |
|
||||||
|
|
||||||
int ads1115_init(); |
|
||||||
int ads1115_setup(ADS1115_REG_CONFIG_MUX_Diff_TypeDef mux); |
|
||||||
// void ads1115_config_register(I2C_HandleTypeDef *ads1115_I2cHandle,uint8_t pointADD,uint8_t configH,uint8_t configL);
|
|
||||||
int16_t ads1115_read_data( ); |
|
||||||
double ads1115_get_voltage_val( ); |
|
||||||
#endif |
|
||||||
|
|
||||||
/***************/ |
|
||||||
//配置寄存器说明
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//config register
|
|
||||||
/*CRH[15:8](R/W)
|
|
||||||
BIT 15 14 13 12 11 10 9 8 |
|
||||||
NAME OS MUX2 MUX1 MUX0 PGA2 PGA1 PGA0 MODE |
|
||||||
CRL[7:0] (R/W) |
|
||||||
BIT 7 6 5 4 3 2 1 0 |
|
||||||
NAME DR0 DR1 DR0 COM_MODE COM_POL COM_LAT COM_QUE1 COM_QUE0 |
|
||||||
|
|
||||||
|
|
||||||
----------------------------------------------------------------------------------- |
|
||||||
* 15 | OS | 运行状态会单词转换开始 |
|
||||||
* | | 写时: |
|
||||||
* | | 0 : 无效 |
|
||||||
* | | 1 : 开始单次转换处于掉电状态时 |
|
||||||
* | | 读时: |
|
||||||
* | | 0 : 正在转换 |
|
||||||
* | | 1 : 未执行转换 |
|
||||||
* ----------------------------------------------------------------------------------- |
|
||||||
* 14:12 | MUX [2:0] | 输入复用多路配置 -- 如果多路的话需要每次分开测量 |
|
||||||
* | | 000 : AINP = AIN0 and AINN = AIN1 (default) |
|
||||||
* | | 001 : AINP = AIN0 and AINN = AIN3 |
|
||||||
* | | 010 : AINP = AIN1 and AINN = AIN3 |
|
||||||
* | | 011 : AINP = AIN2 and AINN = AIN3 |
|
||||||
* | | 100 : AINP = AIN0 and AINN = GND |
|
||||||
* | | 101 : AINP = AIN1 and AINN = GND |
|
||||||
* | | 110 : AINP = AIN2 and AINN = GND |
|
||||||
* | | 111 : AINP = AIN3 and AINN = GND |
|
||||||
* ----------------------------------------------------------------------------------- |
|
||||||
* 11:9 | PGA [2:0] | 可编程增益放大器配置(FSR full scale range) |
|
||||||
* | | 000 : FSR = В±6.144 V |
|
||||||
* | | 001 : FSR = В±4.096 V |
|
||||||
* | | 010 : FSR = В±2.048 V (默认) |
|
||||||
* | | 011 : FSR = В±1.024 V |
|
||||||
* | | 100 : FSR = В±0.512 V |
|
||||||
* | | 101 : FSR = В±0.256 V |
|
||||||
* | | 110 : FSR = В±0.256 V |
|
||||||
* | | 111 : FSR = В±0.256 V |
|
||||||
* ----------------------------------------------------------------------------------- |
|
||||||
* 8 | MODE | 工作模式 |
|
||||||
* | | 0 : 连续转换 |
|
||||||
* | | 1 : 单词转换 |
|
||||||
* ----------------------------------------------------------------------------------- |
|
||||||
* 7:5 | DR [2:0] | 采样频率 |
|
||||||
* | | 000 : 8 SPS |
|
||||||
* | | 001 : 16 SPS |
|
||||||
* | | 010 : 32 SPS |
|
||||||
* | | 011 : 64 SPS |
|
||||||
* | | 100 : 128 SPS (默认) |
|
||||||
* | | 101 : 250 SPS |
|
||||||
* | | 110 : 475 SPS |
|
||||||
* | | 111 : 860 SPS |
|
||||||
* ----------------------------------------------------------------------------------- |
|
||||||
* 4 | COMP_MODE | 比较器模式 |
|
||||||
* | | 0 : 传统比较器 (default) |
|
||||||
* | | 1 : 窗口比较器 |
|
||||||
* ----------------------------------------------------------------------------------- |
|
||||||
* 3 | COMP_POL | Comparator polarity |
|
||||||
* | | 0 : 低电平有效 (default) |
|
||||||
* | | 1 : 高电平有效 |
|
||||||
* ----------------------------------------------------------------------------------- |
|
||||||
* 2 | COMP_LAT | Latching comparator |
|
||||||
* | | 0 : 非锁存比较器. (default) |
|
||||||
* | | 1 : 锁存比较器. |
|
||||||
* ----------------------------------------------------------------------------------- |
|
||||||
* 1:0 | COMP_QUE [1:0] | Comparator queue and disable |
|
||||||
* | | 00 : Assert after one conversion |
|
||||||
* | | 01 : Assert after two conversions |
|
||||||
* | | 10 : Assert after four conversions |
|
||||||
* | | 11 : 禁用比较器并将ALERT/RDY设置为高阻抗 (default) |
|
||||||
* ----------------------------------------------------------------------------------- |
|
||||||
*/ |
|
||||||
@ -0,0 +1,194 @@ |
|||||||
|
/**
|
||||||
|
* @file eeprom.c |
||||||
|
* @author Chen Jihang (embedded@eseaoptics.com) |
||||||
|
* @brief EEPROM驱动 |
||||||
|
* @version 1.0 |
||||||
|
* @date 2023-01-04 |
||||||
|
* |
||||||
|
* @copyright ESEA (c) 2020 |
||||||
|
* |
||||||
|
*/ |
||||||
|
|
||||||
|
#include "eeprom.h" |
||||||
|
eeprom_t *eeprom; |
||||||
|
|
||||||
|
eeprom_t *Eeprom_init() |
||||||
|
{ |
||||||
|
eeprom_t *Handle = (eeprom_t *)malloc(sizeof(eeprom_t)); |
||||||
|
if (Handle == NULL) |
||||||
|
{ |
||||||
|
return NULL; |
||||||
|
} |
||||||
|
Handle->writeCplt = 0; |
||||||
|
Handle->readCplt = 0; |
||||||
|
Handle->write_delay_ms = 10; |
||||||
|
Handle->size = 0; |
||||||
|
Handle->WORKMODE = 1; /* IT mode*/ |
||||||
|
Handle->stat = HAL_I2C_STATE_RESET; /* HAL_I2C_STATE_RESET 未初始化 */ |
||||||
|
return Handle; |
||||||
|
} |
||||||
|
|
||||||
|
uint8_t Eeprom_SET_I2C(eeprom_t *eeprom, I2C_HandleTypeDef *i2c) |
||||||
|
{ |
||||||
|
eeprom->i2c = i2c; |
||||||
|
eeprom->stat = HAL_I2C_STATE_READY; |
||||||
|
return 0; |
||||||
|
} |
||||||
|
uint8_t Eeprom_SET_Device_Model(eeprom_t *eeprom, uint16_t model) |
||||||
|
{ |
||||||
|
eeprom->model = model; |
||||||
|
// if (eeprom->model < AT24C16)
|
||||||
|
// {
|
||||||
|
// eeprom->mem_addr_type = I2C_MEMADD_SIZE_8BIT;
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// eeprom->mem_addr_type = I2C_MEMADD_SIZE_16BIT;
|
||||||
|
// }
|
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
uint8_t Eeprom_SET_Device_Addr(eeprom_t *eeprom, uint8_t dev_addr) |
||||||
|
{ |
||||||
|
eeprom->dev_addr = dev_addr; |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
uint8_t Eeprom_SET_Mem_Addr_Type(eeprom_t *eeprom, uint8_t mem_addr_type) |
||||||
|
{ |
||||||
|
eeprom->mem_addr_type = mem_addr_type; |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
uint8_t Eeprom_SET_Workmode(eeprom_t *eeprom, uint8_t workmode) |
||||||
|
{ |
||||||
|
eeprom->WORKMODE = workmode; |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
uint8_t Eeprom_Read_One_Byte(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf) |
||||||
|
{ |
||||||
|
// eeprom->stat = HAL_I2C_Mem_Read_IT(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, 1);
|
||||||
|
return HAL_I2C_Mem_Read(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, 1,eeprom->write_delay_ms); |
||||||
|
} |
||||||
|
|
||||||
|
uint8_t Eeprom_Write_One_Byte(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf) |
||||||
|
{ |
||||||
|
return HAL_I2C_Mem_Write(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, 1,eeprom->write_delay_ms); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
uint8_t Eeprom_Read_One_Byte_IT(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf) |
||||||
|
{ |
||||||
|
// eeprom->stat = HAL_I2C_Mem_Read_IT(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, 1);
|
||||||
|
eeprom->size = 0; |
||||||
|
return HAL_I2C_Mem_Read_IT(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, 1 ); |
||||||
|
} |
||||||
|
|
||||||
|
uint8_t Eeprom_Write_One_Byte_IT(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf) |
||||||
|
{ |
||||||
|
eeprom->size = 0; |
||||||
|
return HAL_I2C_Mem_Write_IT(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, 1 ); |
||||||
|
} |
||||||
|
|
||||||
|
uint8_t Eeprom_Read_Multi_Byte(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf, uint16_t size, uint32_t timeout ) |
||||||
|
{ |
||||||
|
// eeprom->stat = HAL_I2C_Mem_Write_IT(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, size);
|
||||||
|
return HAL_I2C_Mem_Read(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, size,timeout); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
uint8_t Eeprom_Write_Multi_Byte(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf, uint16_t size, uint32_t timeout ) |
||||||
|
{ |
||||||
|
return HAL_I2C_Mem_Write(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, size,timeout); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
uint8_t Eeprom_Read_Multi_Byte_IT(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf, uint16_t size ) |
||||||
|
{ |
||||||
|
// eeprom->stat = HAL_I2C_Mem_Write_IT(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, size);
|
||||||
|
eeprom->stat =HAL_I2C_Mem_Read_IT(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, size ); |
||||||
|
// LOG(" readstat %d",eeprom->stat);
|
||||||
|
return eeprom->stat; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
uint8_t Eeprom_Write_Multi_Byte_IT(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf, uint16_t size ) |
||||||
|
{ |
||||||
|
// 写入数据前端循环调用 Eeprom_send_callback
|
||||||
|
// return HAL_I2C_Mem_Write_IT(eeprom->i2c, eeprom->dev_addr, mem_addr, eeprom->mem_addr_type, buf, size );
|
||||||
|
eeprom->send_buf = buf; |
||||||
|
eeprom->size = size; |
||||||
|
eeprom->mem_addr = mem_addr; |
||||||
|
return 0; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief EEPROM发送回调,须循环调用单字节写入 |
||||||
|
* |
||||||
|
* @param eeprom EEPROM描述符 |
||||||
|
* @return int 0 |
||||||
|
*/ |
||||||
|
uint8_t Eeprom_send(eeprom_t *eeprom) |
||||||
|
{ |
||||||
|
if (eeprom->size == 0) |
||||||
|
{ |
||||||
|
eeprom->send_buf = NULL; |
||||||
|
} |
||||||
|
if (eeprom->send_buf == NULL) |
||||||
|
{ |
||||||
|
return 0; |
||||||
|
} |
||||||
|
if ( HAL_I2C_GetState(eeprom->i2c) == 1 ) |
||||||
|
{ |
||||||
|
return 0; |
||||||
|
} |
||||||
|
if ( (osKernelGetTickCount() -eeprom->time_base) < eeprom->write_delay_ms ) |
||||||
|
{ |
||||||
|
return 0; |
||||||
|
} |
||||||
|
if ( HAL_I2C_GetState(eeprom->i2c) == 2 ) |
||||||
|
{ |
||||||
|
// __HAL_I2C_CLEAR_FLAG(eeprom->i2c,I2C_FLAG_AF); // 清除非应答状态
|
||||||
|
eeprom->i2c->State = HAL_I2C_STATE_READY; |
||||||
|
// i2c_clear_state(eeprom->i2c);
|
||||||
|
eeprom->mem_addr--; |
||||||
|
eeprom->send_buf--; |
||||||
|
eeprom->size++; |
||||||
|
} |
||||||
|
if (eeprom->size == 0) |
||||||
|
{ |
||||||
|
eeprom->send_buf = NULL; |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
// 单个字节写入 ?? 为什么指向的地址内容发送变化了,静态声明
|
||||||
|
// LOG( " send buf : %02x %d", *eeprom->send_buf, eeprom->send_buf);
|
||||||
|
HAL_I2C_Mem_Write_IT(eeprom->i2c, eeprom->dev_addr, eeprom->mem_addr, eeprom->mem_addr_type, eeprom->send_buf, 1 ); |
||||||
|
// i2c_write_memory(eeprom->i2c,eeprom->dev_addr+eeprom->page_addr,eeprom->mem_addr,eeprom->mem_addr_size,eeprom->send_buf,1);
|
||||||
|
// eeprom->time_base = __get_tick_milliseconds();
|
||||||
|
eeprom->time_base = osKernelGetTickCount(); |
||||||
|
eeprom->mem_addr++; |
||||||
|
eeprom->send_buf++; |
||||||
|
eeprom->size--; |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
void Eeprom_send_callback(eeprom_t *eeprom) |
||||||
|
{ |
||||||
|
Eeprom_send(eeprom); |
||||||
|
} |
||||||
|
|
||||||
|
uint8_t Eeprom_get_state(eeprom_t *eeprom) |
||||||
|
{ |
||||||
|
if (eeprom->send_buf != NULL) |
||||||
|
{ |
||||||
|
return 1; |
||||||
|
} |
||||||
|
if ( HAL_I2C_GetState(eeprom->i2c) == HAL_I2C_STATE_READY ) |
||||||
|
{ |
||||||
|
return 0; |
||||||
|
}; |
||||||
|
return 2; |
||||||
|
} |
||||||
@ -0,0 +1,83 @@ |
|||||||
|
#ifndef EEPROM_H_ |
||||||
|
#define EEPROM_H_ |
||||||
|
#include <stdint.h> |
||||||
|
#include <stdlib.h> |
||||||
|
#include <stddef.h> |
||||||
|
#include "main.h" |
||||||
|
#include "stm32f407xx.h" |
||||||
|
|
||||||
|
#include "FreeRTOSConfig.h" |
||||||
|
#include "cmsis_os2.h" |
||||||
|
// #include "i2c.h"
|
||||||
|
// #include "time_clock.h"
|
||||||
|
// enum I2C_WORKMODE {
|
||||||
|
|
||||||
|
|
||||||
|
// enum MEM_ADDR_TYPE{
|
||||||
|
// BIT8_MEM,
|
||||||
|
// BIT16_MEM
|
||||||
|
// };
|
||||||
|
|
||||||
|
// enum EEPROM_MODEL{
|
||||||
|
// AT24C01=127,
|
||||||
|
// AT24C02=255,
|
||||||
|
// AT24C04=511,
|
||||||
|
// AT24C08=1023,
|
||||||
|
// AT24C16=2047,
|
||||||
|
// AT24C32=4095,
|
||||||
|
// AT24C64=8191,
|
||||||
|
// AT24C128=16383,
|
||||||
|
// AT24C256=32767,
|
||||||
|
// };
|
||||||
|
|
||||||
|
|
||||||
|
// typedef void (*read_callback)();
|
||||||
|
// typedef void (*write_callback)();
|
||||||
|
typedef struct _eeprom |
||||||
|
{ |
||||||
|
I2C_HandleTypeDef *i2c; |
||||||
|
uint16_t model; // AT24C01 AT24C02 AT24C256
|
||||||
|
uint8_t mem_addr_type; // 1: 8bit 2: 16bit I2C_MEMADD_SIZE_8BIT I2C_MEMADD_SIZE_16BIT
|
||||||
|
uint8_t dev_addr; |
||||||
|
uint32_t time_base; // 从系统获得一个systick的毫秒数
|
||||||
|
uint8_t page_addr; |
||||||
|
|
||||||
|
uint8_t *send_buf; // 将写的buf放到这里,然后让IIC自己工作
|
||||||
|
uint16_t size; // 多少个字节
|
||||||
|
uint16_t mem_addr; //??
|
||||||
|
uint8_t write_delay_ms; // 5-8ms
|
||||||
|
uint8_t WORKMODE; // polling 0 , it 1, dma 2
|
||||||
|
uint8_t writeCplt; |
||||||
|
uint8_t readCplt; |
||||||
|
|
||||||
|
HAL_I2C_StateTypeDef stat; |
||||||
|
}eeprom_t; |
||||||
|
|
||||||
|
extern eeprom_t *eeprom; |
||||||
|
|
||||||
|
eeprom_t *Eeprom_init( ); |
||||||
|
uint8_t Eeprom_SET_I2C(eeprom_t *eeprom, I2C_HandleTypeDef *i2c); |
||||||
|
uint8_t Eeprom_SET_Device_Model(eeprom_t *eeprom, uint16_t model); |
||||||
|
uint8_t Eeprom_SET_Device_Addr(eeprom_t *eeprom, uint8_t dev_addr); |
||||||
|
uint8_t Eeprom_SET_Mem_Addr_Type(eeprom_t *eeprom, uint8_t mem_addr_type); |
||||||
|
|
||||||
|
// eeprom_t *eeprom_init( eeprom_t *eeprom,struct i2c_buff *i2c,uint8_t dev_addr,uint8_t mem_addr_size,uint8_t write_delay_ms);
|
||||||
|
// uint8_t eeprom_write( eeprom_t *eeprom, uint8_t page_addr, uint16_t mem_addr, uint8_t *buf, uint32_t size );
|
||||||
|
// uint8_t eeprom_read( eeprom_t *eeprom, uint8_t page_addr, uint16_t mem_addr, uint8_t *buf, uint32_t size );
|
||||||
|
// uint8_t eeprom_send_callback( eeprom_t *eeprom);
|
||||||
|
// uint8_t eeprom_get_state( eeprom_t *eeprom);
|
||||||
|
|
||||||
|
uint8_t Eeprom_Read_One_Byte(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf); |
||||||
|
|
||||||
|
uint8_t Eeprom_Write_One_Byte(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf); |
||||||
|
uint8_t Eeprom_Read_One_Byte_IT(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf); |
||||||
|
|
||||||
|
uint8_t Eeprom_Write_One_Byte_IT(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf); |
||||||
|
|
||||||
|
uint8_t Eeprom_Read_Multi_Byte(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf, uint16_t size, uint32_t timeout ); |
||||||
|
uint8_t Eeprom_Write_Multi_Byte(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf, uint16_t size , uint32_t timeout ); |
||||||
|
uint8_t Eeprom_Read_Multi_Byte_IT(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf, uint16_t size ); |
||||||
|
uint8_t Eeprom_Write_Multi_Byte_IT(eeprom_t *eeprom, uint16_t mem_addr, uint8_t *buf, uint16_t size ); |
||||||
|
void Eeprom_send_callback(eeprom_t *eeprom); |
||||||
|
uint8_t Eeprom_send(eeprom_t *eeprom); |
||||||
|
#endif |
||||||
@ -0,0 +1,111 @@ |
|||||||
|
#include "eeprom.h" |
||||||
|
#include "main.h" |
||||||
|
#include "config.h" |
||||||
|
#include "elog.h" |
||||||
|
|
||||||
|
extern int Eeprom_Port(); |
||||||
|
extern void Eeprom_Task(); |
||||||
|
extern int Config_Read_Eeprom( uint8_t numSeconds); |
||||||
|
extern int Config_Write_Eeprom( ); |
||||||
|
|
||||||
|
osThreadId_t eeprom_taskHandle; |
||||||
|
const osThreadAttr_t eeprom_task_attributes = { |
||||||
|
.name = "eeprom_task", |
||||||
|
.stack_size = 256, |
||||||
|
.priority = (osPriority_t) osPriorityLow, |
||||||
|
}; |
||||||
|
|
||||||
|
/* 1: 8bit 2: 16bit I2C_MEMADD_SIZE_8BIT I2C_MEMADD_SIZE_16BIT */
|
||||||
|
|
||||||
|
enum EEPROM_MODEL{
|
||||||
|
AT24C01 =127, |
||||||
|
AT24C02 =255, |
||||||
|
AT24C04 =511, |
||||||
|
AT24C08 =1023, |
||||||
|
AT24C16 =2047, |
||||||
|
AT24C32 =4095, |
||||||
|
AT24C64 =8191, |
||||||
|
AT24C128 =16383, |
||||||
|
AT24C256 =32767,
|
||||||
|
}; |
||||||
|
|
||||||
|
eeprom_t *eeprom; |
||||||
|
extern I2C_HandleTypeDef hi2c1; |
||||||
|
I2C_HandleTypeDef *Eeprom_I2C = &hi2c1; |
||||||
|
|
||||||
|
extern struct config config; |
||||||
|
extern int Config_Read_Eeprom( uint8_t numSeconds); |
||||||
|
|
||||||
|
uint8_t eeprom_buf; |
||||||
|
|
||||||
|
int Eeprom_Port() |
||||||
|
{ |
||||||
|
eeprom = Eeprom_init(); |
||||||
|
Eeprom_SET_I2C( eeprom, &hi2c1 ); |
||||||
|
Eeprom_SET_Device_Model( eeprom, AT24C02 ); |
||||||
|
Eeprom_SET_Device_Addr( eeprom, 0xA0 ); |
||||||
|
if ( eeprom->model < AT24C16 )
|
||||||
|
Eeprom_SET_Mem_Addr_Type( eeprom, I2C_MEMADD_SIZE_8BIT);
|
||||||
|
else |
||||||
|
Eeprom_SET_Mem_Addr_Type( eeprom, I2C_MEMADD_SIZE_16BIT);
|
||||||
|
eeprom->stat = HAL_I2C_STATE_READY; |
||||||
|
|
||||||
|
eeprom_taskHandle = osThreadNew(Eeprom_Task, NULL, &eeprom_task_attributes); |
||||||
|
// if (Config_Read_Eeprom( 8) == 0)
|
||||||
|
// {
|
||||||
|
// HAL_GPIO_TogglePin(RED_GPIO_Port,RED_Pin);
|
||||||
|
// // log_i( "ok>>>>>>>>");
|
||||||
|
// }
|
||||||
|
|
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
void Eeprom_Task() |
||||||
|
{ |
||||||
|
for ( ; ; ) |
||||||
|
{ |
||||||
|
Eeprom_send( eeprom ); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
int Config_Read_Eeprom( uint8_t numSeconds) |
||||||
|
{ |
||||||
|
eeprom->stat= HAL_I2C_STATE_BUSY; |
||||||
|
eeprom->time_base = osKernelGetTickCount(); |
||||||
|
|
||||||
|
uint8_t aa = Eeprom_Read_Multi_Byte_IT( eeprom, 0, (uint8_t *)&config, sizeof(config) ); |
||||||
|
// uint8_t aa = HAL_I2C_Mem_Read_IT( eeprom->i2c, eeprom->dev_addr, 0, I2C_MEMADD_SIZE_8BIT, (uint8_t*)&config, sizeof(config) );
|
||||||
|
// uint8_t aa = HAL_I2C_Mem_Read_IT(eeprom->i2c, eeprom->dev_addr, 0, I2C_MEMADD_SIZE_8BIT, data, 1 );
|
||||||
|
|
||||||
|
while(HAL_I2C_GetState(eeprom->i2c)!=HAL_I2C_STATE_READY ){ |
||||||
|
if (( osKernelGetTickCount() - eeprom->time_base) >numSeconds*1000) |
||||||
|
{
|
||||||
|
return -1; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
log_i("eeprom init ok."); |
||||||
|
|
||||||
|
if(config_check()==0){ |
||||||
|
return 0; |
||||||
|
} |
||||||
|
config_reset(); |
||||||
|
return 0; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
/* config 内容写道eeprom ,一个一个依据时间限写入,启用任务*/ |
||||||
|
int Config_Write_Eeprom( ) |
||||||
|
{ |
||||||
|
// Eeprom_Port_Init();
|
||||||
|
Eeprom_Write_Multi_Byte_IT( eeprom, 0, (uint8_t *)&config, sizeof(config) ); |
||||||
|
for ( ; ; ) |
||||||
|
{ |
||||||
|
if (eeprom->size > 0) |
||||||
|
Eeprom_send_callback( eeprom ); |
||||||
|
else |
||||||
|
return -1; |
||||||
|
} |
||||||
|
return 0; |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,162 @@ |
|||||||
|
//i2c_ads1115.c
|
||||||
|
#include "i2c_ads1115.h" |
||||||
|
#include <stdlib.h> |
||||||
|
#include "i2c.h" |
||||||
|
#include "main.h" |
||||||
|
#include "elog.h" |
||||||
|
|
||||||
|
/*
|
||||||
|
* ads1115_get_voltage_val( hi2c1, 0x00, CONFIG_REG_H, CONFIG_REG_L ) |
||||||
|
*/ |
||||||
|
|
||||||
|
extern I2C_HandleTypeDef hi2c1; |
||||||
|
#define ADS1115_hi2c hi2c1 |
||||||
|
|
||||||
|
int ads1115_test(I2C_HandleTypeDef ads1115_I2cHandle) |
||||||
|
{ |
||||||
|
ads1115_config_register(ads1115_I2cHandle, 0x00, CONFIG_REG_H, CONFIG_REG_L); |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
* @param [in] ads1115_I2cHandle
|
||||||
|
* @param [in] pointADD -- 0x01 写配置寄存器 |
||||||
|
* @param [in] configH
|
||||||
|
* @param [in] configL
|
||||||
|
*
|
||||||
|
* @details
|
||||||
|
*/ |
||||||
|
void ads1115_config_register(I2C_HandleTypeDef ads1115_I2cHandle,uint8_t pointADD,uint8_t configH,uint8_t configL) |
||||||
|
{ |
||||||
|
uint8_t reg_data[3]={pointADD,configH,configL}; |
||||||
|
log_i( "115 %d %d %d ", reg_data[0], reg_data[1], reg_data[2]); |
||||||
|
while(HAL_I2C_Master_Transmit( &ads1115_I2cHandle, ADS1115_WRITE_ADDRESS, reg_data, 3, 2000 ) != HAL_OK) |
||||||
|
{ |
||||||
|
if(HAL_I2C_GetError(&ads1115_I2cHandle) != HAL_I2C_ERROR_AF) |
||||||
|
{ |
||||||
|
log_i( "ads1115 Config Register error!!!\r\n" ); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
int16_t ads1115_read_data(I2C_HandleTypeDef ads1115_I2cHandle) |
||||||
|
{ |
||||||
|
int16_t data; |
||||||
|
uint8_t rx_data[2]={0}; |
||||||
|
|
||||||
|
while( HAL_I2C_Master_Transmit( &ads1115_I2cHandle, ADS1115_WRITE_ADDRESS, 0x00, 1, 2000 ) != HAL_OK ) |
||||||
|
{ |
||||||
|
if(HAL_I2C_GetError(&ads1115_I2cHandle) != HAL_I2C_ERROR_AF) |
||||||
|
{ |
||||||
|
log_i( "ads1115 convert Register error!!!\r\n" ); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
while( HAL_I2C_Master_Receive(&ads1115_I2cHandle, ADS1115_READ_ADDRESS, rx_data, 2, 2000) != HAL_OK ) |
||||||
|
{ |
||||||
|
if(HAL_I2C_GetError(&ads1115_I2cHandle) != HAL_I2C_ERROR_AF) |
||||||
|
{ |
||||||
|
log_i( "ads1115 read data error!!!\r\n" ); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
data = rx_data[0]*256 + rx_data[1]; |
||||||
|
return data; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
double ads1115_get_voltage_val( I2C_HandleTypeDef ads1115_I2cHandle, uint8_t pointADD, uint8_t configH, uint8_t configL) |
||||||
|
{ |
||||||
|
double val; |
||||||
|
int16_t ad_val; |
||||||
|
double coeff_mv = 1000.0; /* 输出 毫伏*/ |
||||||
|
double coeff_v = 1000000.0; /* 输出 伏*/ |
||||||
|
|
||||||
|
// ads1115_config_register( ads1115_I2cHandle, pointADD, configH, configL );
|
||||||
|
// // HAL_Delay(10);
|
||||||
|
// osDelay(10);
|
||||||
|
|
||||||
|
|
||||||
|
// ad_val=ads1115_read_data( ads1115_I2cHandle );
|
||||||
|
// if( (ad_val==0x7FFF)|(ad_val==0X8000) )//是否超量程了
|
||||||
|
// {
|
||||||
|
// ad_val=0;
|
||||||
|
// log_i("over PGA\r\n");
|
||||||
|
// }
|
||||||
|
|
||||||
|
// switch( ( 0x0E&configH )>>1 )//量程对应的分辨率
|
||||||
|
// {
|
||||||
|
// case(0x00):
|
||||||
|
// val=(double)ad_val*187.5/coeff_mv;//
|
||||||
|
// break;
|
||||||
|
// case(0x01):
|
||||||
|
// val=(double)ad_val*125/coeff_mv;
|
||||||
|
// break;
|
||||||
|
// case(0x02):
|
||||||
|
// val=(double)ad_val*62.5/coeff_mv;
|
||||||
|
// break;
|
||||||
|
// case(0x03):
|
||||||
|
// val=(double)ad_val*31.25/coeff_mv;
|
||||||
|
// break;
|
||||||
|
// case(0x04):
|
||||||
|
// val=(double)ad_val*15.625/coeff_mv;
|
||||||
|
// break;
|
||||||
|
// case(0x05):
|
||||||
|
// val=(double)ad_val*7.8125/coeff_mv;
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
return coeff_mv; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
int ads1115_get ( I2C_HandleTypeDef ads1115_I2cHandle, uint8_t pointADD, uint8_t configH, uint8_t configL) |
||||||
|
{ |
||||||
|
double val; |
||||||
|
int16_t ad_val; |
||||||
|
double coeff_mv = 1000.0; /* 输出 毫伏*/ |
||||||
|
double coeff_v = 1000000.0; /* 输出 伏*/ |
||||||
|
|
||||||
|
ads1115_config_register( ads1115_I2cHandle, pointADD, configH, configL ); |
||||||
|
// HAL_Delay(10);
|
||||||
|
osDelay(10); |
||||||
|
|
||||||
|
|
||||||
|
ad_val=ads1115_read_data( ads1115_I2cHandle ); |
||||||
|
// if( (ad_val==0x7FFF)|(ad_val==0X8000) )//是否超量程了
|
||||||
|
// {
|
||||||
|
// ad_val=0;
|
||||||
|
// log_i("over PGA\r\n");
|
||||||
|
// }
|
||||||
|
|
||||||
|
// switch( ( 0x0E&configH )>>1 )//量程对应的分辨率
|
||||||
|
// {
|
||||||
|
// case(0x00):
|
||||||
|
// val=(double)ad_val*187.5/coeff_mv;//
|
||||||
|
// break;
|
||||||
|
// case(0x01):
|
||||||
|
// val=(double)ad_val*125/coeff_mv;
|
||||||
|
// break;
|
||||||
|
// case(0x02):
|
||||||
|
// val=(double)ad_val*62.5/coeff_mv;
|
||||||
|
// break;
|
||||||
|
// case(0x03):
|
||||||
|
// val=(double)ad_val*31.25/coeff_mv;
|
||||||
|
// break;
|
||||||
|
// case(0x04):
|
||||||
|
// val=(double)ad_val*15.625/coeff_mv;
|
||||||
|
// break;
|
||||||
|
// case(0x05):
|
||||||
|
// val=(double)ad_val*7.8125/coeff_mv;
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
return ad_val; |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,186 @@ |
|||||||
|
//i2c_ads1115.h
|
||||||
|
#ifndef __IIC_ADS1115_H |
||||||
|
#define __IIC_ADS1115_H |
||||||
|
|
||||||
|
#include "i2c.h" |
||||||
|
#include "i2chelper.h" |
||||||
|
|
||||||
|
#define ADS1115_WRITE_ADDRESS 0x90 |
||||||
|
#define ADS1115_READ_ADDRESS 0x91 |
||||||
|
//以下两个预处理作为配置寄存器预处理要更改其配在这里更改
|
||||||
|
//也可以添加新的预处理对不同通道的采集或者选取不同的采样速率等
|
||||||
|
#define CONFIG_REG_H ADS1115_REG_CONFIG_OS_START|\ |
||||||
|
ADS1115_REG_CONFIG_MUX_SINGLE_0|\
|
||||||
|
ADS1115_REG_CONFIG_PGA_4|\
|
||||||
|
ADS1115_REG_CONFIG_MODE_SINGLE |
||||||
|
|
||||||
|
#define CONFIG_REG_L ADS1115_REG_CONFIG_DR_128|\ |
||||||
|
ADS1115_REG_CONFIG_COMP_MODE_TRADITIONAL|\
|
||||||
|
ADS1115_REG_CONFIG_COMP_POL_LOW|\
|
||||||
|
ADS1115_REG_CONFIG_COMP_LAT_NONLATCH|\
|
||||||
|
ADS1115_REG_CONFIG_COMP_QUE_DIS |
||||||
|
|
||||||
|
|
||||||
|
/***************/ |
||||||
|
//配置寄存器说明
|
||||||
|
|
||||||
|
//config register
|
||||||
|
/*CRH[15:8](R/W)
|
||||||
|
BIT 15 14 13 12 11 10 9 8 |
||||||
|
NAME OS MUX2 MUX1 MUX0 PGA2 PGA1 PGA0 MODE |
||||||
|
CRL[7:0] (R/W) |
||||||
|
BIT 7 6 5 4 3 2 1 0 |
||||||
|
NAME DR0 DR1 DR0 COM_MODE COM_POL COM_LAT COM_QUE1 COM_QUE0 |
||||||
|
|
||||||
|
|
||||||
|
----------------------------------------------------------------------------------- |
||||||
|
* 15 | OS | 运行状态会单词转换开始 |
||||||
|
* | | 写时: |
||||||
|
* | | 0 : 无效 |
||||||
|
* | | 1 : 开始单次转换处于掉电状态时 |
||||||
|
* | | 读时: |
||||||
|
* | | 0 : 正在转换 |
||||||
|
* | | 1 : 未执行转换 |
||||||
|
* ----------------------------------------------------------------------------------- |
||||||
|
* 14:12 | MUX [2:0] | 输入复用多路配置 |
||||||
|
* | | 000 : AINP = AIN0 and AINN = AIN1 (default) |
||||||
|
* | | 001 : AINP = AIN0 and AINN = AIN3 |
||||||
|
* | | 010 : AINP = AIN1 and AINN = AIN3 |
||||||
|
* | | 011 : AINP = AIN2 and AINN = AIN3 |
||||||
|
* | | 100 : AINP = AIN0 and AINN = GND |
||||||
|
* | | 101 : AINP = AIN1 and AINN = GND |
||||||
|
* | | 110 : AINP = AIN2 and AINN = GND |
||||||
|
* | | 111 : AINP = AIN3 and AINN = GND |
||||||
|
* ----------------------------------------------------------------------------------- |
||||||
|
* 11:9 | PGA [2:0] | 可编程增益放大器配置(FSR full scale range) |
||||||
|
* | | 000 : FSR = В±6.144 V |
||||||
|
* | | 001 : FSR = В±4.096 V |
||||||
|
* | | 010 : FSR = В±2.048 V (默认) |
||||||
|
* | | 011 : FSR = В±1.024 V |
||||||
|
* | | 100 : FSR = В±0.512 V |
||||||
|
* | | 101 : FSR = В±0.256 V |
||||||
|
* | | 110 : FSR = В±0.256 V |
||||||
|
* | | 111 : FSR = В±0.256 V |
||||||
|
* ----------------------------------------------------------------------------------- |
||||||
|
* 8 | MODE | 工作模式 |
||||||
|
* | | 0 : 连续转换 |
||||||
|
* | | 1 : 单词转换 |
||||||
|
* ----------------------------------------------------------------------------------- |
||||||
|
* 7:5 | DR [2:0] | 采样频率 |
||||||
|
* | | 000 : 8 SPS |
||||||
|
* | | 001 : 16 SPS |
||||||
|
* | | 010 : 32 SPS |
||||||
|
* | | 011 : 64 SPS |
||||||
|
* | | 100 : 128 SPS (默认) |
||||||
|
* | | 101 : 250 SPS |
||||||
|
* | | 110 : 475 SPS |
||||||
|
* | | 111 : 860 SPS |
||||||
|
* ----------------------------------------------------------------------------------- |
||||||
|
* 4 | COMP_MODE | 比较器模式 |
||||||
|
* | | 0 : 传统比较器 (default) |
||||||
|
* | | 1 : 窗口比较器 |
||||||
|
* ----------------------------------------------------------------------------------- |
||||||
|
* 3 | COMP_POL | Comparator polarity |
||||||
|
* | | 0 : 低电平有效 (default) |
||||||
|
* | | 1 : 高电平有效 |
||||||
|
* ----------------------------------------------------------------------------------- |
||||||
|
* 2 | COMP_LAT | Latching comparator |
||||||
|
* | | 0 : 非锁存比较器. (default) |
||||||
|
* | | 1 : 锁存比较器. |
||||||
|
* ----------------------------------------------------------------------------------- |
||||||
|
* 1:0 | COMP_QUE [1:0] | Comparator queue and disable |
||||||
|
* | | 00 : Assert after one conversion |
||||||
|
* | | 01 : Assert after two conversions |
||||||
|
* | | 10 : Assert after four conversions |
||||||
|
* | | 11 : 禁用比较器并将ALERT/RDY设置为高阻抗 (default) |
||||||
|
* ----------------------------------------------------------------------------------- |
||||||
|
*/ |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//地址指针寄存器
|
||||||
|
|
||||||
|
#define ADS1015_REG_POINTER_CONVERT (0x00) |
||||||
|
#define ADS1015_REG_POINTER_CONFIG (0x01) |
||||||
|
#define ADS1015_REG_POINTER_LOWTHRESH (0x02) |
||||||
|
#define ADS1015_REG_POINTER_HITHRESH (0x03) |
||||||
|
// 单次转换开始
|
||||||
|
#define ADS1115_REG_CONFIG_OS_START (0x1U << 7)//设备单次转换开启 高字节的最高位
|
||||||
|
#define ADS1115_REG_CONFIG_OS_NULL (0x0U << 7) |
||||||
|
//输入引脚选择和输入方式选择
|
||||||
|
#define ADS1115_REG_CONFIG_MUX_Diff_01 (0x0U << 4) // 差分输入0引脚和1引脚
|
||||||
|
#define ADS1115_REG_CONFIG_MUX_Diff_03 (0x1U << 4) // 差分输入0引脚和3引脚
|
||||||
|
#define ADS1115_REG_CONFIG_MUX_Diff_13 (0x2U << 4) // 差分输入1引脚和3引脚
|
||||||
|
#define ADS1115_REG_CONFIG_MUX_Diff_23 (0x3U << 4) // 差分输入2引脚和3引脚
|
||||||
|
#define ADS1115_REG_CONFIG_MUX_SINGLE_0 (0x4U << 4) //单端输入 0
|
||||||
|
#define ADS1115_REG_CONFIG_MUX_SINGLE_1 (0x5U << 4) //单端输入 1
|
||||||
|
#define ADS1115_REG_CONFIG_MUX_SINGLE_2 (0x6U << 4) //单端输入 2
|
||||||
|
#define ADS1115_REG_CONFIG_MUX_SINGLE_3 (0x7U << 4) //单端输入 3
|
||||||
|
|
||||||
|
//量程选择
|
||||||
|
#define ADS1115_REG_CONFIG_PGA_6 (0x0U << 1) // +/- 6.1144
|
||||||
|
#define ADS1115_REG_CONFIG_PGA_4 (0x1U << 1) // +/- 4.096
|
||||||
|
#define ADS1115_REG_CONFIG_PGA_2 (0x2U << 1) // +/- 2.048
|
||||||
|
#define ADS1115_REG_CONFIG_PGA_1 (0x3U << 1) // +/- 1.024
|
||||||
|
#define ADS1115_REG_CONFIG_PGA_05 (0x4U << 1) // +/- 0.512
|
||||||
|
#define ADS1115_REG_CONFIG_PGA_02 (0x5U << 1) // +/- 0.256
|
||||||
|
|
||||||
|
//运行方式
|
||||||
|
|
||||||
|
#define ADS1115_REG_CONFIG_MODE_SINGLE (0x1U << 0) // 单次
|
||||||
|
#define ADS1115_REG_CONFIG_MODE_CONTIN (0x0U << 0) //连续转换
|
||||||
|
|
||||||
|
//转换速率
|
||||||
|
|
||||||
|
#define ADS1115_REG_CONFIG_DR_8 (0x0U << 5) |
||||||
|
#define ADS1115_REG_CONFIG_DR_16 (0x1U << 5) |
||||||
|
#define ADS1115_REG_CONFIG_DR_32 (0x2U << 5) |
||||||
|
#define ADS1115_REG_CONFIG_DR_64 (0x3U << 5) |
||||||
|
#define ADS1115_REG_CONFIG_DR_128 (0x4U << 5) |
||||||
|
#define ADS1115_REG_CONFIG_DR_250 (0x5U << 5) |
||||||
|
#define ADS1115_REG_CONFIG_DR_475 (0x6U << 5) |
||||||
|
#define ADS1115_REG_CONFIG_DR_860 (0x7U << 5) |
||||||
|
|
||||||
|
//比较器模式
|
||||||
|
#define ADS1115_REG_CONFIG_COMP_MODE_TRADITIONAL (0x0U << 4)//默认
|
||||||
|
#define ADS1115_REG_CONFIG_COMP_MODE_WINDOW (0x1U << 4) |
||||||
|
|
||||||
|
|
||||||
|
#define ADS1115_REG_CONFIG_COMP_POL_LOW (0x0U << 3)//默认
|
||||||
|
#define ADS1115_REG_CONFIG_COMP_POL_HIG (0x1U << 3) |
||||||
|
|
||||||
|
|
||||||
|
#define ADS1115_REG_CONFIG_COMP_LAT_NONLATCH (0x0U << 2) |
||||||
|
#define ADS1115_REG_CONFIG_COMP_LAT_LATCH (0x1U << 2) |
||||||
|
|
||||||
|
|
||||||
|
#define ADS1115_REG_CONFIG_COMP_QUE_ONE (0x0U << 0) |
||||||
|
#define ADS1115_REG_CONFIG_COMP_QUE_TWO (0x1U << 0) |
||||||
|
#define ADS1115_REG_CONFIG_COMP_QUE_THR (0x2U << 0) |
||||||
|
#define ADS1115_REG_CONFIG_COMP_QUE_DIS (0x3U << 0) |
||||||
|
|
||||||
|
int ads1115_test(I2C_HandleTypeDef ads1115_I2cHandle); |
||||||
|
void ads1115_config_register(I2C_HandleTypeDef ads1115_I2cHandle,uint8_t pointADD,uint8_t configH,uint8_t configL); |
||||||
|
int16_t ads1115_read_data(I2C_HandleTypeDef ads1115_I2cHandle); |
||||||
|
double ads1115_get_voltage_val(I2C_HandleTypeDef ads1115_I2cHandle,uint8_t pointADD,uint8_t configH,uint8_t configL); |
||||||
|
|
||||||
|
#endif |
||||||
|
|
||||||
|
/*
|
||||||
|
步骤一:write to config register(写配置寄存器) |
||||||
|
1:发送从机地址0x90(写) |
||||||
|
2:发送0x01 (指向配置寄存器) |
||||||
|
3:配置config register |
||||||
|
发送字节:0x84(高八位) |
||||||
|
发送字节:0x83(低八位) |
||||||
|
|
||||||
|
步骤二:write to pointer register(转向转换寄存器) |
||||||
|
1:发送从机地址0x90(写) |
||||||
|
2:发送0x00(指向转换寄存器) |
||||||
|
|
||||||
|
步骤三:read conversion register(读取转换寄存器的数据) |
||||||
|
1:发送从机地址0x91(读) |
||||||
|
2:接收转换寄存器的高八位 |
||||||
|
3:接收转换寄存器的低八位 |
||||||
|
|
||||||
|
*/ |
||||||
@ -0,0 +1,79 @@ |
|||||||
|
#include "led.h" |
||||||
|
|
||||||
|
static struct led *led_table[LED_MAX_NUM]; |
||||||
|
static uint32_t p_led_table=0; |
||||||
|
/**
|
||||||
|
* @brief 注册LED灯 |
||||||
|
*
|
||||||
|
* @param led struct led 结构指针 |
||||||
|
* @param gpio LED所在的GPIO |
||||||
|
* @param pin LED所在的引脚 |
||||||
|
* @param state LED初始状态 |
||||||
|
* @param level_on LED点亮时的电平 1:高 0:低 |
||||||
|
* @return int 0:成功 非0:失败 |
||||||
|
*/ |
||||||
|
int led_register(struct led *led,GPIO_TypeDef *gpio,uint16_t pin,enum led_state state,uint16_t level_on) |
||||||
|
{ |
||||||
|
if(p_led_table>=LED_MAX_NUM-1){ |
||||||
|
return -1; |
||||||
|
} |
||||||
|
led->gpio=gpio; |
||||||
|
led->pin=pin; |
||||||
|
led->state=state; |
||||||
|
led->level_on=level_on; |
||||||
|
led_table[p_led_table++]=led; |
||||||
|
return 0; |
||||||
|
} |
||||||
|
/**
|
||||||
|
* @brief 设置LED状态 |
||||||
|
*
|
||||||
|
* @param led struct led 结构指针 |
||||||
|
* @param state LED状态 |
||||||
|
* @return int 0:成功 |
||||||
|
*/ |
||||||
|
int led_set_state(struct led *led,enum led_state state) |
||||||
|
{ |
||||||
|
led->state=state; |
||||||
|
return 0; |
||||||
|
} |
||||||
|
/**
|
||||||
|
* @brief led回调函数 每100ms调用一次 |
||||||
|
*
|
||||||
|
*/ |
||||||
|
void led_callback(void) |
||||||
|
{ |
||||||
|
int i; |
||||||
|
static uint32_t tick_con=0; |
||||||
|
tick_con++; |
||||||
|
for(i=0;i<p_led_table;i++){ |
||||||
|
switch (led_table[i]->state) |
||||||
|
{ |
||||||
|
case LED_STATE_OFF: |
||||||
|
HAL_GPIO_WritePin( led_table[i]->gpio,led_table[i]->pin,(~led_table[i]->level_on)&1 ); |
||||||
|
// GPIO_WriteBit(led_table[i]->gpio,led_table[i]->pin,(~led_table[i]->level_on)&1);
|
||||||
|
break; |
||||||
|
case LED_STATE_ON: |
||||||
|
HAL_GPIO_WritePin( led_table[i]->gpio,led_table[i]->pin,led_table[i]->level_on&1 ); |
||||||
|
// GPIO_WriteBit(led_table[i]->gpio,led_table[i]->pin,led_table[i]->level_on&1);
|
||||||
|
break; |
||||||
|
case LED_STATE_FLICKER_QUICK: |
||||||
|
HAL_GPIO_TogglePin( led_table[i]->gpio,led_table[i]->pin); |
||||||
|
// GPIO_WriteBit(led_table[i]->gpio,led_table[i]->pin,!GPIO_ReadOutputDataBit(led_table[i]->gpio,led_table[i]->pin));
|
||||||
|
break; |
||||||
|
case LED_STATE_FLICKER_MEDIUM: |
||||||
|
if((tick_con&0x01)==0){ |
||||||
|
HAL_GPIO_TogglePin( led_table[i]->gpio,led_table[i]->pin); |
||||||
|
// GPIO_WriteBit(led_table[i]->gpio,led_table[i]->pin,!GPIO_ReadOutputDataBit(led_table[i]->gpio,led_table[i]->pin));
|
||||||
|
} |
||||||
|
break; |
||||||
|
case LED_STATE_FLICKER_SLOW: |
||||||
|
if((tick_con&0x03)==0){ |
||||||
|
HAL_GPIO_TogglePin( led_table[i]->gpio,led_table[i]->pin); |
||||||
|
// GPIO_WriteBit(led_table[i]->gpio,led_table[i]->pin,!GPIO_ReadOutputDataBit(led_table[i]->gpio,led_table[i]->pin));
|
||||||
|
} |
||||||
|
break; |
||||||
|
default: |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,35 @@ |
|||||||
|
#ifndef __LED_H |
||||||
|
#define __LED_H |
||||||
|
|
||||||
|
#include "stdint.h" |
||||||
|
#include "main.h" |
||||||
|
#define LED_MAX_NUM 4 |
||||||
|
|
||||||
|
// 回调需要这个参数,控制时开关还是闪烁,闪烁快慢
|
||||||
|
enum led_state{ |
||||||
|
LED_STATE_ON, |
||||||
|
LED_STATE_FLICKER_SLOW, |
||||||
|
LED_STATE_FLICKER_MEDIUM, |
||||||
|
LED_STATE_FLICKER_QUICK, |
||||||
|
LED_STATE_OFF |
||||||
|
|
||||||
|
}; |
||||||
|
|
||||||
|
// 标准库的 GPIO_TypeDef, 改为HAL库
|
||||||
|
struct led |
||||||
|
{ |
||||||
|
enum led_state state; |
||||||
|
GPIO_TypeDef *gpio; |
||||||
|
uint16_t pin; |
||||||
|
uint16_t level_on; |
||||||
|
}; |
||||||
|
|
||||||
|
// 依据GPIO 信息注册
|
||||||
|
int led_register(struct led *led, GPIO_TypeDef *gpio, uint16_t pin, enum led_state state, uint16_t level_on ); |
||||||
|
|
||||||
|
// 初始化状态
|
||||||
|
int led_set_state(struct led *led,enum led_state state); |
||||||
|
|
||||||
|
// 执行 -- 由状态决定
|
||||||
|
void led_callback(void); |
||||||
|
#endif |
||||||
Loading…
Reference in new issue