My UART is working on Callback-mode, I prepare to update my firmware from SDK6.10 to SDK6.20. But I try to use UART2 to replace UART, the UART2 send callback has never been executed
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
My UART is working on Callback-mode, I prepare to update my firmware from SDK6.10 to SDK6.20. But I try to use UART2 to replace UART, the UART2 send callback has never been executed
Hi,
I have modified the uart2callback in the following fashion, and I can see the write callback being executed:
/*
* Copyright (c) 2020, Texas Instruments Incorporated
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* ======== uart2callback.c ========
*/
#include <stdint.h>
#include <stddef.h>
/* POSIX Header files */
#include <semaphore.h>
/* Driver Header files */
#include <ti/drivers/GPIO.h>
#include <ti/drivers/UART2.h>
/* Driver configuration */
#include "ti_drivers_config.h"
static sem_t sem;
static volatile size_t numBytesRead;
static volatile size_t numBytesWrite;
/*
* ======== callbackReadFxn ========
*/
void callbackReadFxn(UART2_Handle handle, void *buffer, size_t count,
void *userArg, int_fast16_t status)
{
if (status != UART2_STATUS_SUCCESS) {
/* RX error occured in UART2_read() */
while (1);
}
numBytesRead = count;
sem_post(&sem);
}
/*
* ======== callbackWriteFxn ========
*/
void callbackWriteFxn(UART2_Handle handle, void *buffer, size_t count,
void *userArg, int_fast16_t status)
{
if (status != UART2_STATUS_SUCCESS) {
/* RX error occured in UART2_read() */
while (1);
}
numBytesWrite = count;
}
/*
* ======== mainThread ========
*/
void *mainThread(void *arg0)
{
char input;
const char echoPrompt[] = "Echoing characters:\r\n";
UART2_Handle uart;
UART2_Params uartParams;
int32_t semStatus;
uint32_t status = UART2_STATUS_SUCCESS;
/* Call driver init functions */
GPIO_init();
/* Configure the LED pin */
GPIO_setConfig(CONFIG_GPIO_LED_0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
/* Create semaphore */
semStatus = sem_init(&sem, 0, 0);
if (semStatus != 0) {
/* Error creating semaphore */
while (1);
}
/* Create a UART in CALLBACK read mode */
UART2_Params_init(&uartParams);
uartParams.readMode = UART2_Mode_CALLBACK;
uartParams.readCallback = callbackReadFxn;
uartParams.writeMode = UART2_Mode_CALLBACK;
uartParams.writeCallback = callbackWriteFxn;
uartParams.baudRate = 115200;
uart = UART2_open(CONFIG_UART2_0, &uartParams);
if (uart == NULL) {
/* UART2_open() failed */
while (1);
}
/* Turn on user LED to indicate successful initialization */
GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);
/* Pass NULL for bytesWritten since it's not used in this example */
UART2_write(uart, echoPrompt, sizeof(echoPrompt), NULL);
/* Loop forever echoing */
while (1) {
numBytesRead = 0;
/* Pass NULL for bytesRead since it's not used in this example */
status = UART2_read(uart, &input, 1, NULL);
if (status != UART2_STATUS_SUCCESS) {
/* UART2_read() failed */
while (1);
}
/* Do not write until read callback executes */
sem_wait(&sem);
if (numBytesRead > 0) {
status = UART2_write(uart, &input, 1, NULL);
if (status != UART2_STATUS_SUCCESS) {
/* UART2_write() failed */
while (1);
}
}
}
}
Please make sure that you configured the writeMode to UART2_Mode_CALLBACK.
Regards,
Arthur
In SDK 6.10,the UART2 Send Callback can't trigger. But I really update into SDK 6.20, it can work.
Hi, I made the example I sent previously with SDK 6.10. It does trigger on send. Can you share your source code?
Regards,
Arthur
UART2_Handle cmdUartHandle;
uint8_t* pCmdUartRxBuf;
void cmd_uartReadCallback(UART2_Handle handle, void *buf, size_t count, void *userArg, int_fast16_t status);
void cmd_uartWriteCallback(UART2_Handle handle, void *buf, size_t count, void *userArg, int_fast16_t status);
void cmd_uartInit(uint32_t baud)
{
UART2_Params params;
UART2_Params_init(¶ms);
params.readMode = UART2_Mode_CALLBACK;
params.writeMode = UART2_Mode_CALLBACK;
params.baudRate = baud;
params.readCallback = cmd_uartReadCallback;
params.writeCallback = cmd_uartWriteCallback;
params.dataLength = UART2_DataLen_8;
params.stopBits = UART2_StopBits_1;
params.readReturnMode = UART2_ReadReturnMode_PARTIAL; //Enable Partial Reads
cmdUartHandle = UART2_open(CMD_UART_PORT, ¶ms);
UART2_rxEnable(cmdUartHandle);
//UART_control(cmdUartHandle, CMD_RETURN_PARTIAL_ENABLE, NULL);
//start rx
MFG_CSState key;
key = MFG_enterCS();
pCmdUartRxBuf = MFG_malloc(CMD_UART_BUF_SIZE);
UART2_read(cmdUartHandle, pCmdUartRxBuf, CMD_UART_BUF_SIZE, NULL);
MFG_leaveCS(key);
}
uint8_t NullSend;
uint8_t uartSendCnt;
bool cmd_uartSend(uint8_t* buff, uint16_t size)
{
if(size == 0)
{
asm("NOP");
NullSend ++;
}
if(UART2_STATUS_SUCCESS != UART2_write(cmdUartHandle, buff, size, &uartSendCnt))
{
return false;
}
//uartSendCnt ++;
return true;
}
void cmd_uartReadCallback(UART2_Handle handle, void *buf, size_t count, void *userArg, int_fast16_t status)
{
MFG_CSState key;
key = MFG_enterCS();
//Input received data
CmdPkt_RxInd(buf, count);
//set next rx
UART2_read(cmdUartHandle, buf, CMD_UART_BUF_SIZE, NULL);
MFG_leaveCS(key);
}
uint8_t SendCb;
void cmd_uartWriteCallback(UART2_Handle handle, void *buf, size_t count, void *userArg, int_fast16_t status)
{
SendCb ++;
MFG_CSState key;
key = MFG_enterCS();
CmdPkt_TxCnf(buf);
MFG_leaveCS(key);
}Hi,
Using the example I provided, can you see the send callback being executed? Using a breakpoint for instance.
Regards,
Arthur