Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bouffalolab] Fix crash issue caused by button action and fix UART tx/rx for command line #25267

Merged
merged 11 commits into from
Mar 7, 2023
13 changes: 9 additions & 4 deletions examples/lighting-app/bouffalolab/bl602/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,16 @@
#define LED_B_PIN_PORT 2
#define LED_B_PIN 17

#define LED_R_PIN_PORT 0
#define LED_R_PIN 20
#define LED_R_PIN_PORT 4
#define LED_R_PIN 14

#define LED_G_PIN_PORT 1
#define LED_G_PIN 21
#define LED_G_PIN 11

// comment out for last hardware
//#define LED_R_PIN_PORT 0
//#define LED_R_PIN 20
//#define LED_G_PIN 21

#define MAX_PWM_CHANNEL 3

Expand All @@ -62,4 +67,4 @@
#define LED_BTN_RESET 8

#define CHIP_UART_PIN_RX 7
#define CHIP_UART_PIN_TX 16
#define CHIP_UART_PIN_TX 16
7 changes: 4 additions & 3 deletions examples/lighting-app/bouffalolab/common/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,18 +646,19 @@ void AppTask::ButtonEventHandler(void * arg)
uint32_t presstime;
if (ButtonPressed())
{
hosal_gpio_irq_set(&gpio_key, HOSAL_IRQ_TRIG_NEG_LEVEL, GetAppTask().ButtonEventHandler, NULL);
// hosal_gpio_irq_set(&gpio_key, HOSAL_IRQ_TRIG_NEG_LEVEL, GetAppTask().ButtonEventHandler, NULL);
bl_set_gpio_intmod(gpio_key.port, 1, HOSAL_IRQ_TRIG_NEG_LEVEL);

GetAppTask().mButtonPressedTime = chip::System::SystemClock().GetMonotonicMilliseconds64().count();
GetAppTask().PostEvent(APP_EVENT_BTN_FACTORY_RESET_PRESS);
}
else
{
hosal_gpio_irq_set(&gpio_key, HOSAL_IRQ_TRIG_POS_PULSE, GetAppTask().ButtonEventHandler, NULL);
// hosal_gpio_irq_set(&gpio_key, HOSAL_IRQ_TRIG_POS_PULSE, GetAppTask().ButtonEventHandler, NULL);
bl_set_gpio_intmod(gpio_key.port, 1, HOSAL_IRQ_TRIG_POS_PULSE);

if (GetAppTask().mButtonPressedTime)
{

presstime = chip::System::SystemClock().GetMonotonicMilliseconds64().count() - GetAppTask().mButtonPressedTime;
if (presstime >= APP_BUTTON_PRESS_LONG)
{
Expand Down
11 changes: 4 additions & 7 deletions examples/platform/bouffalolab/common/plat/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,33 +51,30 @@ static int uartTxCallback(void * p_arg)

static int uartRxCallback(void * p_arg)
{
uint32_t len = 0, readlen = 0;
uint32_t len = 0;
BaseType_t xHigherPriorityTaskWoken = 1;

if (chipUart_var.head >= chipUart_var.tail)
{
if (chipUart_var.head < MAX_BUFFER_SIZE)
{
readlen = len =
hosal_uart_receive(&uart_stdio, chipUart_var.rxbuf + chipUart_var.head, MAX_BUFFER_SIZE - chipUart_var.head);
len = hosal_uart_receive(&uart_stdio, chipUart_var.rxbuf + chipUart_var.head, MAX_BUFFER_SIZE - chipUart_var.head);
chipUart_var.head = (chipUart_var.head + len) % MAX_BUFFER_SIZE;
}

if (0 == chipUart_var.head)
{
len = hosal_uart_receive(&uart_stdio, chipUart_var.rxbuf, chipUart_var.tail - 1);
chipUart_var.head += len;
readlen += len;
}
}
else
{
readlen =
chipUart_var.head +=
hosal_uart_receive(&uart_stdio, chipUart_var.rxbuf + chipUart_var.head, chipUart_var.tail - chipUart_var.head - 1);
chipUart_var.head += readlen;
}

if (0 == readlen || (chipUart_var.head + 1) % MAX_BUFFER_SIZE == chipUart_var.tail)
if (chipUart_var.head != chipUart_var.tail)
{
xSemaphoreGiveFromISR(chipUart_var.sema, &xHigherPriorityTaskWoken);
}
Expand Down