Skip to content

Commit

Permalink
cmsis_uart: generic DAPLink adapter to CMSIS UART drivers
Browse files Browse the repository at this point in the history
From lpc55xx HIC
  • Loading branch information
mbrossard committed Nov 9, 2021
1 parent 465003f commit 6f8f558
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
1 change: 1 addition & 0 deletions records/hic_hal/lpc55s69.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ common:
- source/hic_hal/nxp/lpc55xx
- source/hic_hal/nxp/lpc55xx/LPC55S69
- source/hic_hal/nxp/lpc55xx/LPC55S69/drivers
- source/hic_hal/cmsis-driver/uart

tool_specific:
uvision:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,13 @@
*/

#include "string.h"
#include "fsl_device_registers.h"
#include "fsl_usart_cmsis.h"
#include "uart.h"
#include "util.h"
#include "cortex_m.h"
#include "circ_buf.h"
#include "settings.h" // for config_get_overflow_detect

#define USART_INSTANCE (Driver_USART0)
#define USART_IRQ (FLEXCOMM0_IRQn)

extern uint32_t SystemCoreClock;
#include "Driver_USART.h"
#include "IO_Config.h"

static void clear_buffers(void);

Expand Down Expand Up @@ -64,18 +59,18 @@ int32_t uart_initialize(void)
{
clear_buffers();
cb_buf.tx_size = 0;
USART_INSTANCE.Initialize(uart_handler);
USART_INSTANCE.PowerControl(ARM_POWER_FULL);
CMSIS_UART_INSTANCE.Initialize(uart_handler);
CMSIS_UART_INSTANCE.PowerControl(ARM_POWER_FULL);

return 1;
}

int32_t uart_uninitialize(void)
{
USART_INSTANCE.Control(ARM_USART_CONTROL_RX, 0);
USART_INSTANCE.Control(ARM_USART_ABORT_RECEIVE, 0U);
USART_INSTANCE.PowerControl(ARM_POWER_OFF);
USART_INSTANCE.Uninitialize();
CMSIS_UART_INSTANCE.Control(ARM_USART_CONTROL_RX, 0);
CMSIS_UART_INSTANCE.Control(ARM_USART_ABORT_RECEIVE, 0U);
CMSIS_UART_INSTANCE.PowerControl(ARM_POWER_OFF);
CMSIS_UART_INSTANCE.Uninitialize();
clear_buffers();
cb_buf.tx_size = 0;

Expand All @@ -85,10 +80,10 @@ int32_t uart_uninitialize(void)
int32_t uart_reset(void)
{
// disable interrupt
NVIC_DisableIRQ(USART_IRQ);
NVIC_DisableIRQ(CMSIS_UART_IRQ);
clear_buffers();
// enable interrupt
NVIC_EnableIRQ(USART_IRQ);
NVIC_EnableIRQ(CMSIS_UART_IRQ);

return 1;
}
Expand Down Expand Up @@ -157,23 +152,23 @@ int32_t uart_set_configuration(UART_Configuration *config)
break;
}

NVIC_DisableIRQ(USART_IRQ);
NVIC_DisableIRQ(CMSIS_UART_IRQ);
clear_buffers();

// If there was no Receive() call in progress aborting it is harmless.
USART_INSTANCE.Control(ARM_USART_CONTROL_RX, 0U);
USART_INSTANCE.Control(ARM_USART_ABORT_RECEIVE, 0U);
CMSIS_UART_INSTANCE.Control(ARM_USART_CONTROL_RX, 0U);
CMSIS_UART_INSTANCE.Control(ARM_USART_ABORT_RECEIVE, 0U);

uint32_t r = USART_INSTANCE.Control(control, config->Baudrate);
uint32_t r = CMSIS_UART_INSTANCE.Control(control, config->Baudrate);
if (r != ARM_DRIVER_OK) {
return 0;
}
USART_INSTANCE.Control(ARM_USART_CONTROL_TX, 1);
USART_INSTANCE.Control(ARM_USART_CONTROL_RX, 1);
USART_INSTANCE.Receive(&(cb_buf.rx), 1);
CMSIS_UART_INSTANCE.Control(ARM_USART_CONTROL_TX, 1);
CMSIS_UART_INSTANCE.Control(ARM_USART_CONTROL_RX, 1);
CMSIS_UART_INSTANCE.Receive(&(cb_buf.rx), 1);

NVIC_ClearPendingIRQ(USART_IRQ);
NVIC_EnableIRQ(USART_IRQ);
NVIC_ClearPendingIRQ(CMSIS_UART_IRQ);
NVIC_EnableIRQ(CMSIS_UART_IRQ);

return 1;
}
Expand Down Expand Up @@ -203,7 +198,7 @@ static void uart_start_tx_transfer() {
}
cb_buf.tx_size = tx_size;
if (tx_size) {
USART_INSTANCE.Send(buf, tx_size);
CMSIS_UART_INSTANCE.Send(buf, tx_size);
}
}

Expand Down Expand Up @@ -242,7 +237,7 @@ void uart_handler(uint32_t event) {
} else {
// Drop character
}
USART_INSTANCE.Receive(&(cb_buf.rx), 1);
CMSIS_UART_INSTANCE.Receive(&(cb_buf.rx), 1);
}

if (event & ARM_USART_EVENT_SEND_COMPLETE) {
Expand Down
6 changes: 5 additions & 1 deletion source/hic_hal/nxp/lpc55xx/IO_Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ COMPILER_ASSERT(DAPLINK_HIC_ID == DAPLINK_HIC_ID_LPC55XX);
#define PIN_UART_TX (25U)
#define PIN_UART_TX_MASK (1U << PIN_UART_TX)

// cmsis-driver/uart/uart.c configuration
#include "fsl_usart_cmsis.h"
#define CMSIS_UART_INSTANCE (Driver_USART0)
#define CMSIS_UART_IRQ (FLEXCOMM0_IRQn)


// Debug Unit LEDs

Expand All @@ -117,5 +122,4 @@ COMPILER_ASSERT(DAPLINK_HIC_ID == DAPLINK_HIC_ID_LPC55XX);
#define LED_CONNECTED (5U)
#define LED_CONNECTED_MASK (1U << LED_CONNECTED)


#endif

0 comments on commit 6f8f558

Please sign in to comment.