このコードを使用してUSB経由でデータを取得しています。文字が受信されると、トップコードはプログラムをクラッシュさせます。一番下はうまく動作しますが、私が望むようにデータを保存することはできません。 CDC_Receive_FS()
...を呼び出す前であっても、一番上のクラッシュ(無限ループ)は呼び出されません。ボトムはCDC_Receive_FS()
を期待どおりに呼び出します。STM32F0 CubeMXを使用したUSB CDC_Init_FS()およびCDC_Receive_FS()
私の人生は、私がループしているバッファの配列を保持している私の構造体をどのように呼び出しているのか分かりません。
/* Send Data over USB CDC are stored in this buffer */
uint8_t UserTxBufferFS[APP_TX_DATA_SIZE];
#define MAX_COMMANDS_IN_BUFFER 10 //max commands that can be received and saved without overwriting. Each command has a max size of APP_RX_DATA_SIZE
/* Define size for the receive and transmit buffer over CDC */
/* It's up to user to redefine and/or remove those define */
#define APP_RX_DATA_SIZE 256
#define APP_TX_DATA_SIZE 256
uint8_t UserTxBufferFS[APP_TX_DATA_SIZE];
static struct
{
uint32_t Buffer_Number_Receiving, Buffer_Number_Processing; //Buffer_Number_Receiving is the current position in buffer to receive incoming data. Buffer_Number_Processing is the index of buffer which is being processed.
uint8_t IsCommandDataReceived; // > 0 , data were received. 0 means no data is available
uint8_t UserRxBufferFS[MAX_COMMANDS_IN_BUFFER][APP_RX_DATA_SIZE];//it could save <MaxCommandsInBuffer> number of commands
uint8_t CommandsLens[MAX_COMMANDS_IN_BUFFER]; //save the len of each command
} s_RxBuffers;
static int8_t CDC_Init_FS(void)
{
hUsbDevice_0 = &hUsbDeviceFS;
/* USER CODE BEGIN 3 */
/* Set Application Buffers */
USBD_CDC_SetTxBuffer(hUsbDevice_0, UserTxBufferFS, 0);
USBD_CDC_SetRxBuffer(hUsbDevice_0, s_RxBuffers.UserRxBufferFS[s_RxBuffers.Buffer_Number_Receiving]);//Set the buffer to receive incoming data
USBD_CDC_ReceivePacket(hUsbDevice_0);
return (USBD_OK);
/* USER CODE END 3 */
}
これにはない:
/* Received Data over USB are stored in this buffer */
uint8_t UserRxBufferFS[APP_RX_DATA_SIZE];
/* Send Data over USB CDC are stored in this buffer */
uint8_t UserTxBufferFS[APP_TX_DATA_SIZE];
static int8_t CDC_Init_FS(void)
{
hUsbDevice_0 = &hUsbDeviceFS;
/* USER CODE BEGIN 3 */
/* Set Application Buffers */
USBD_CDC_SetTxBuffer(hUsbDevice_0, UserTxBufferFS, 0);
USBD_CDC_SetRxBuffer(hUsbDevice_0, UserRxBufferFS);
USBD_CDC_ReceivePacket(hUsbDevice_0);
return (USBD_OK);
}
ここライン(このバッファの使用は)犯人のようだ:
USBD_CDC_SetRxBuffer(hUsbDevice_0, s_RxBuffers.UserRxBufferFS[s_RxBuffers.Buffer_Number_Receiving]);//Set the buffer to receive incoming data
すべてのヘルプ/洞察力大いに感謝します。
"クラッシュ"?あれは何でしょう?エラー?データは中止されますか?爆発?何か特別なもの? –
私はスクリーンショット "Loop"を与えました。それは無限ループでDefault_Handlerに終わる。 – willworknow
次に、どの例外が割り込みステータスとフォールトレジスタを調べるかを調べます。 –