Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
02a85438
Commit
02a85438
authored
11 years ago
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
stmhal: Check CDC tx buffer has free space before filling with data.
parent
ecd58aec
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
stmhal/usbd_cdc_interface.c
+393
-553
393 additions, 553 deletions
stmhal/usbd_cdc_interface.c
with
393 additions
and
553 deletions
stmhal/usbd_cdc_interface.c
+
393
−
553
View file @
02a85438
...
...
@@ -33,15 +33,6 @@
#include
"pendsv.h"
#include
"usb.h"
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
* @{
*/
/** @defgroup USBD_CDC
* @brief usbd core module
* @{
*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define APP_RX_DATA_SIZE 1024 // I think this must be at least CDC_DATA_FS_OUT_PACKET_SIZE (was 2048)
...
...
@@ -72,8 +63,6 @@ static int8_t CDC_Itf_DeInit (void);
static
int8_t
CDC_Itf_Control
(
uint8_t
cmd
,
uint8_t
*
pbuf
,
uint16_t
length
);
static
int8_t
CDC_Itf_Receive
(
uint8_t
*
pbuf
,
uint32_t
*
Len
);
static
void
Error_Handler
(
void
);
//static void ComPort_Config(void);
static
void
TIM_Config
(
void
);
const
USBD_CDC_ItfTypeDef
USBD_CDC_fops
=
{
...
...
@@ -133,7 +122,6 @@ static int8_t CDC_Itf_Init(void)
if
(
HAL_TIM_Base_Start_IT
(
&
USBD_CDC_TimHandle
)
!=
HAL_OK
)
{
/* Starting Error */
Error_Handler
();
}
/*##-5- Set Application Buffers ############################################*/
...
...
@@ -162,7 +150,6 @@ static int8_t CDC_Itf_DeInit(void)
if(HAL_UART_DeInit(&UartHandle) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
#endif
return
(
USBD_OK
);
...
...
@@ -209,7 +196,6 @@ static int8_t CDC_Itf_Control (uint8_t cmd, uint8_t* pbuf, uint16_t length)
LineCoding.datatype = pbuf[6];
/* Set the new configuration */
ComPort_Config();
#endif
break
;
...
...
@@ -285,28 +271,6 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
}
}
#if 0
/**
* @brief Rx Transfer completed callback
* @param huart: UART handle
* @retval None
*/
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
/* Increment Index for buffer writing */
UserTxBufPtrIn++;
/* To avoid buffer overflow */
if(UserTxBufPtrIn == APP_RX_DATA_SIZE)
{
UserTxBufPtrIn = 0;
}
/* Start another reception: provide the buffer pointer with offset and the buffer size */
HAL_UART_Receive_IT(huart, (uint8_t *)(UserTxBuffer + UserTxBufPtrIn), 1);
}
#endif
/**
* @brief CDC_Itf_DataRx
* Data received over USB OUT endpoint is processed here.
...
...
@@ -371,6 +335,13 @@ void USBD_CDC_SetInterrupt(int chr, void *data) {
void
USBD_CDC_Tx
(
const
char
*
str
,
uint32_t
len
)
{
for
(
int
i
=
0
;
i
<
len
;
i
++
)
{
uint
timeout
=
200
;
while
(
UserTxBufPtrIn
+
1
==
UserTxBufPtrOut
)
{
if
(
timeout
--
==
0
)
{
break
;
}
HAL_Delay
(
1
);
}
UserTxBuffer
[
UserTxBufPtrIn
]
=
str
[
i
];
UserTxBufPtrIn
=
(
UserTxBufPtrIn
+
1
)
&
(
APP_TX_DATA_SIZE
-
1
);
}
...
...
@@ -395,102 +366,6 @@ int USBD_CDC_RxGet(void) {
return
c
;
}
#if 0
/**
* @brief Tx Transfer completed callback
* @param huart: UART handle
* @retval None
*/
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
{
/* Initiate next USB packet transfer once UART completes transfer (transmitting data over Tx line) */
USBD_CDC_ReceivePacket(&hUSBDDevice);
}
/**
* @brief ComPort_Config
* Configure the COM Port with the parameters received from host.
* @param None.
* @retval None.
* @note When a configuration is not supported, a default value is used.
*/
static void ComPort_Config(void)
{
if(HAL_UART_DeInit(&UartHandle) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/* set the Stop bit */
switch (LineCoding.format)
{
case 0:
UartHandle.Init.StopBits = UART_STOPBITS_1;
break;
case 2:
UartHandle.Init.StopBits = UART_STOPBITS_2;
break;
default :
UartHandle.Init.StopBits = UART_STOPBITS_1;
break;
}
/* set the parity bit*/
switch (LineCoding.paritytype)
{
case 0:
UartHandle.Init.Parity = UART_PARITY_NONE;
break;
case 1:
UartHandle.Init.Parity = UART_PARITY_ODD;
break;
case 2:
UartHandle.Init.Parity = UART_PARITY_EVEN;
break;
default :
UartHandle.Init.Parity = UART_PARITY_NONE;
break;
}
/*set the data type : only 8bits and 9bits is supported */
switch (LineCoding.datatype)
{
case 0x07:
/* With this configuration a parity (Even or Odd) must be set */
UartHandle.Init.WordLength = UART_WORDLENGTH_8B;
break;
case 0x08:
if(UartHandle.Init.Parity == UART_PARITY_NONE)
{
UartHandle.Init.WordLength = UART_WORDLENGTH_8B;
}
else
{
UartHandle.Init.WordLength = UART_WORDLENGTH_9B;
}
break;
default :
UartHandle.Init.WordLength = UART_WORDLENGTH_8B;
break;
}
UartHandle.Init.BaudRate = LineCoding.bitrate;
UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
UartHandle.Init.Mode = UART_MODE_TX_RX;
if(HAL_UART_Init(&UartHandle) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/* Start reception: provide the buffer pointer with offset and the buffer size */
HAL_UART_Receive_IT(&UartHandle, (uint8_t *)(UserTxBuffer + UserTxBufPtrIn), 1);
}
#endif
/**
* @brief TIM_Config: Configure TIMx timer
* @param None.
...
...
@@ -514,40 +389,5 @@ static void TIM_Config(void)
if
(
HAL_TIM_Base_Init
(
&
USBD_CDC_TimHandle
)
!=
HAL_OK
)
{
/* Initialization Error */
Error_Handler
();
}
}
#if 0
/**
* @brief UART error callbacks
* @param UartHandle: UART handle
* @retval None
*/
void HAL_UART_ErrorCallback(UART_HandleTypeDef *UartHandle)
{
/* Transfer error occured in reception and/or transmission process */
Error_Handler();
}
#endif
/**
* @brief This function is executed in case of error occurrence.
* @param None
* @retval None
*/
static
void
Error_Handler
(
void
)
{
/* Add your own code here */
}
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment