generated from Embedded_Projects/MPyATE_Template
Added UART initialization code.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: Yilin Sun <imi415@imi.moe>
This commit is contained in:
parent
ecd9ef8220
commit
3588b957ed
14
LPC804.mex
14
LPC804.mex
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding= "UTF-8" ?>
|
||||
<configuration name="LPC804" xsi:schemaLocation="http://mcuxpresso.nxp.com/XSD/mex_configuration_13 http://mcuxpresso.nxp.com/XSD/mex_configuration_13.xsd" uuid="71d05819-9ff6-47ce-9f37-e7dd46d29728" version="13" xmlns="http://mcuxpresso.nxp.com/XSD/mex_configuration_13" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<configuration name="LPC804" xsi:schemaLocation="http://mcuxpresso.nxp.com/XSD/mex_configuration_14 http://mcuxpresso.nxp.com/XSD/mex_configuration_14.xsd" uuid="71d05819-9ff6-47ce-9f37-e7dd46d29728" version="14" xmlns="http://mcuxpresso.nxp.com/XSD/mex_configuration_14" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<common>
|
||||
<processor>LPC804</processor>
|
||||
<package>LPC804M101JHI33</package>
|
||||
|
@ -17,13 +17,13 @@
|
|||
<generate_registers_defines>false</generate_registers_defines>
|
||||
</preferences>
|
||||
<tools>
|
||||
<pins name="Pins" version="13.1" enabled="true" update_project_code="true">
|
||||
<pins name="Pins" version="14.0" enabled="true" update_project_code="true">
|
||||
<generated_project_files>
|
||||
<file path="board/pin_mux.c" update_enabled="true"/>
|
||||
<file path="board/pin_mux.h" update_enabled="true"/>
|
||||
</generated_project_files>
|
||||
<pins_profile>
|
||||
<processor_version>13.0.1</processor_version>
|
||||
<processor_version>14.0.0</processor_version>
|
||||
<pin_labels>
|
||||
<pin_label pin_num="30" pin_signal="PIO0_22" label="LED_R" identifier="LED_R"/>
|
||||
<pin_label pin_num="31" pin_signal="PIO0_18" label="LED_G" identifier="LED_G"/>
|
||||
|
@ -253,13 +253,13 @@
|
|||
</function>
|
||||
</functions_list>
|
||||
</pins>
|
||||
<clocks name="Clocks" version="11.0" enabled="true" update_project_code="true">
|
||||
<clocks name="Clocks" version="12.0" enabled="true" update_project_code="true">
|
||||
<generated_project_files>
|
||||
<file path="board/clock_config.c" update_enabled="true"/>
|
||||
<file path="board/clock_config.h" update_enabled="true"/>
|
||||
</generated_project_files>
|
||||
<clocks_profile>
|
||||
<processor_version>13.0.1</processor_version>
|
||||
<processor_version>14.0.0</processor_version>
|
||||
</clocks_profile>
|
||||
<clock_configurations>
|
||||
<clock_configuration name="BOARD_BootClockRUN" id_prefix="" prefix_user_defined="false">
|
||||
|
@ -302,13 +302,13 @@
|
|||
</dcdx_profile>
|
||||
<dcdx_configurations/>
|
||||
</dcdx>
|
||||
<periphs name="Peripherals" version="12.0" enabled="true" update_project_code="true">
|
||||
<periphs name="Peripherals" version="13.0" enabled="true" update_project_code="true">
|
||||
<generated_project_files>
|
||||
<file path="board/peripherals.c" update_enabled="true"/>
|
||||
<file path="board/peripherals.h" update_enabled="true"/>
|
||||
</generated_project_files>
|
||||
<peripherals_profile>
|
||||
<processor_version>13.0.1</processor_version>
|
||||
<processor_version>14.0.0</processor_version>
|
||||
</peripherals_profile>
|
||||
<functional_groups>
|
||||
<functional_group name="BOARD_InitPeripherals" uuid="333bc532-5b96-45be-999a-50c34b7bab60" called_from_default_init="true" id_prefix="" core="core0">
|
||||
|
|
2
SDK
2
SDK
|
@ -1 +1 @@
|
|||
Subproject commit e46813114663364b03f7507d3926852fe55b2b58
|
||||
Subproject commit 28c7a119e9910ee9cdbebf682f85e1aa1d76f5f4
|
|
@ -10,11 +10,11 @@
|
|||
|
||||
/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
|
||||
!!GlobalInfo
|
||||
product: Clocks v11.0
|
||||
product: Clocks v12.0
|
||||
processor: LPC804
|
||||
package_id: LPC804M101JHI33
|
||||
mcu_data: ksdk2_0
|
||||
processor_version: 13.0.1
|
||||
processor_version: 14.0.0
|
||||
* BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
|
||||
|
||||
#include "fsl_power.h"
|
||||
|
|
|
@ -42,20 +42,20 @@ void BOARD_InitBootClocks(void);
|
|||
|
||||
|
||||
/* Clock outputs (values are in Hz): */
|
||||
#define BOARD_BOOTCLOCKRUN_ADC_CLOCK 0UL
|
||||
#define BOARD_BOOTCLOCKRUN_CAPT_CLOCK 0UL
|
||||
#define BOARD_BOOTCLOCKRUN_CLKOUT_CLOCK 0UL
|
||||
#define BOARD_BOOTCLOCKRUN_FROHF_CLOCK 30000000UL
|
||||
#define BOARD_BOOTCLOCKRUN_I2C0_CLOCK 0UL
|
||||
#define BOARD_BOOTCLOCKRUN_I2C1_CLOCK 0UL
|
||||
#define BOARD_BOOTCLOCKRUN_LOWPOWER_CLOCK 1000000UL
|
||||
#define BOARD_BOOTCLOCKRUN_PLUCLKIN_CLOCK 0UL
|
||||
#define BOARD_BOOTCLOCKRUN_SPI0_CLOCK 0UL
|
||||
#define BOARD_BOOTCLOCKRUN_SYSTEM_CLOCK 15000000UL
|
||||
#define BOARD_BOOTCLOCKRUN_UART0_CLOCK 0UL
|
||||
#define BOARD_BOOTCLOCKRUN_UART1_CLOCK 0UL
|
||||
#define BOARD_BOOTCLOCKRUN_WWDT_CLOCK 1000000UL
|
||||
#define BOARD_BOOTCLOCKRUN_DIVTO750K_CLOCK 750000UL
|
||||
#define BOARD_BOOTCLOCKRUN_ADC_CLOCK 0UL /* Clock consumers of ADC_clock output : ADC */
|
||||
#define BOARD_BOOTCLOCKRUN_CAPT_CLOCK 0UL /* Clock consumers of CAPT_clock output : CAPT */
|
||||
#define BOARD_BOOTCLOCKRUN_CLKOUT_CLOCK 0UL /* Clock consumers of CLKOUT_clock output : N/A */
|
||||
#define BOARD_BOOTCLOCKRUN_FROHF_CLOCK 30000000UL /* Clock consumers of FROHF_clock output : N/A */
|
||||
#define BOARD_BOOTCLOCKRUN_I2C0_CLOCK 0UL /* Clock consumers of I2C0_clock output : I2C0 */
|
||||
#define BOARD_BOOTCLOCKRUN_I2C1_CLOCK 0UL /* Clock consumers of I2C1_clock output : I2C1 */
|
||||
#define BOARD_BOOTCLOCKRUN_LOWPOWER_CLOCK 1000000UL /* Clock consumers of LowPower_clock output : WKT */
|
||||
#define BOARD_BOOTCLOCKRUN_PLUCLKIN_CLOCK 0UL /* Clock consumers of PLUCLKIN_clock output : PLU */
|
||||
#define BOARD_BOOTCLOCKRUN_SPI0_CLOCK 0UL /* Clock consumers of SPI0_clock output : SPI0 */
|
||||
#define BOARD_BOOTCLOCKRUN_SYSTEM_CLOCK 15000000UL /* Clock consumers of System_clock output : ACOMP, ADC, CAPT, CRC, CTIMER0, DAC0, GPIO, I2C0, I2C1, IOCON, MRT0, PINT, PLU, SPI0, SWM0, USART0, USART1, WKT, WWDT */
|
||||
#define BOARD_BOOTCLOCKRUN_UART0_CLOCK 0UL /* Clock consumers of UART0_clock output : USART0 */
|
||||
#define BOARD_BOOTCLOCKRUN_UART1_CLOCK 0UL /* Clock consumers of UART1_clock output : USART1 */
|
||||
#define BOARD_BOOTCLOCKRUN_WWDT_CLOCK 1000000UL /* Clock consumers of WWDT_clock output : WWDT */
|
||||
#define BOARD_BOOTCLOCKRUN_DIVTO750K_CLOCK 750000UL /* Clock consumers of divto750k_clock output : WKT */
|
||||
|
||||
/*******************************************************************************
|
||||
* API for BOARD_BootClockRUN configuration
|
||||
|
|
|
@ -6,11 +6,11 @@
|
|||
/* clang-format off */
|
||||
/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
|
||||
!!GlobalInfo
|
||||
product: Peripherals v12.0
|
||||
product: Peripherals v13.0
|
||||
processor: LPC804
|
||||
package_id: LPC804M101JHI33
|
||||
mcu_data: ksdk2_0
|
||||
processor_version: 13.0.1
|
||||
processor_version: 14.0.0
|
||||
functionalGroups:
|
||||
- name: BOARD_InitPeripherals
|
||||
UUID: 333bc532-5b96-45be-999a-50c34b7bab60
|
||||
|
|
|
@ -7,11 +7,11 @@
|
|||
/*
|
||||
* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
|
||||
!!GlobalInfo
|
||||
product: Pins v13.1
|
||||
product: Pins v14.0
|
||||
processor: LPC804
|
||||
package_id: LPC804M101JHI33
|
||||
mcu_data: ksdk2_0
|
||||
processor_version: 13.0.1
|
||||
processor_version: 14.0.0
|
||||
pin_labels:
|
||||
- {pin_num: '30', pin_signal: PIO0_22, label: LED_R, identifier: LED_R}
|
||||
- {pin_num: '31', pin_signal: PIO0_18, label: LED_G, identifier: LED_G}
|
||||
|
|
|
@ -15,11 +15,6 @@
|
|||
|
||||
#define APP_GPIO_PIN_COUNT 4
|
||||
|
||||
#define APP_GPIO_CFG_OUTPUT_PP 0
|
||||
#define APP_GPIO_CFG_OUTPUT_OD 1
|
||||
#define APP_GPIO_CFG_INPUT 2
|
||||
#define APP_GPIO_CFG_AF 3
|
||||
|
||||
static const uint8_t s_app_gpio_id_table[APP_GPIO_PIN_COUNT] = {
|
||||
BOARD_INITIOPINS_IO0_PIN,
|
||||
BOARD_INITIOPINS_IO1_PIN,
|
||||
|
@ -27,6 +22,13 @@ static const uint8_t s_app_gpio_id_table[APP_GPIO_PIN_COUNT] = {
|
|||
BOARD_INITIOPINS_IO3_PIN,
|
||||
};
|
||||
|
||||
static const uint8_t s_app_gpio_iocon_table[APP_GPIO_PIN_COUNT] = {
|
||||
IOCON_INDEX_PIO0_15,
|
||||
IOCON_INDEX_PIO0_11,
|
||||
IOCON_INDEX_PIO0_10,
|
||||
IOCON_INDEX_PIO0_20,
|
||||
};
|
||||
|
||||
static const uint32_t s_app_gpio_mask_table[APP_GPIO_PIN_COUNT] = {
|
||||
BOARD_INITIOPINS_IO0_PIN_MASK,
|
||||
BOARD_INITIOPINS_IO1_PIN_MASK,
|
||||
|
@ -101,7 +103,7 @@ static inline uint16_t app_gpio_read_reg_cfg(void) {
|
|||
ret |= (2U << (2 * i));
|
||||
} else {
|
||||
/* Output mode */
|
||||
if ((IOCON->PIO[s_app_gpio_id_table[i]] & IOCON_PIO_OD_MASK) == IOCON_PIO_OD(1)) {
|
||||
if ((IOCON->PIO[s_app_gpio_iocon_table[i]] & IOCON_PIO_OD_MASK) == IOCON_PIO_OD(1)) {
|
||||
/* OD mode */
|
||||
ret |= (1U << (2 * i));
|
||||
}
|
||||
|
@ -122,10 +124,10 @@ static inline void app_gpio_write_reg_cfg(uint16_t data) {
|
|||
|
||||
if (data & (1U << (2 * i))) {
|
||||
/* OD mode */
|
||||
IOCON->PIO[s_app_gpio_id_table[i]] |= IOCON_PIO_OD(1);
|
||||
IOCON->PIO[s_app_gpio_iocon_table[i]] |= IOCON_PIO_OD(1);
|
||||
} else {
|
||||
/* PP mode */
|
||||
IOCON->PIO[s_app_gpio_id_table[i]] &= ~(IOCON_PIO_OD(1));
|
||||
IOCON->PIO[s_app_gpio_iocon_table[i]] &= ~(IOCON_PIO_OD(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
151
src/app_uart.c
151
src/app_uart.c
|
@ -1,11 +1,160 @@
|
|||
/* SDK drivers */
|
||||
#include "fsl_clock.h"
|
||||
#include "fsl_usart.h"
|
||||
|
||||
/* App */
|
||||
#include "app_uart.h"
|
||||
|
||||
#define APP_UART_REG_OFFSET_CFG (0x00U)
|
||||
#define APP_UART_REG_OFFSET_STAT (0x01U)
|
||||
#define APP_UART_REG_OFFSET_FIFO (0x02U)
|
||||
|
||||
#define APP_UART_REG_CFG_EN_Pos (15U)
|
||||
#define APP_UART_REG_CFG_EN_Msk (1U << APP_UART_REG_CFG_EN_Pos)
|
||||
|
||||
#define APP_UART_REG_CFG_BAUD_Pos (0U)
|
||||
#define APP_UART_REG_CFG_BAUD_Msk (0x0FU << APP_UART_REG_CFG_BAUD_Pos)
|
||||
|
||||
typedef struct {
|
||||
uint8_t mul;
|
||||
uint8_t osr;
|
||||
uint8_t brg;
|
||||
} app_uart_clk_preset_t;
|
||||
|
||||
typedef enum {
|
||||
APP_UART_BAUD_2400 = 0U,
|
||||
APP_UART_BAUD_4800,
|
||||
APP_UART_BAUD_9600,
|
||||
APP_UART_BAUD_19200,
|
||||
APP_UART_BAUD_38400,
|
||||
APP_UART_BAUD_57600,
|
||||
APP_UART_BAUD_115200,
|
||||
APP_UART_BAUD_230400,
|
||||
APP_UART_BAUD_460800,
|
||||
APP_UART_BAUD_921600,
|
||||
APP_UART_BAUD_END,
|
||||
} app_uart_baud_t;
|
||||
|
||||
/* Script generated, do not edit. */
|
||||
static const app_uart_clk_preset_t s_clk_preset[] = {
|
||||
[APP_UART_BAUD_2400] = {.mul = 0xaa, .osr = 0x0e, .brg = 0xf9}, /* Actual: 2400.00 baud/s, err: 0.00% */
|
||||
[APP_UART_BAUD_4800] = {.mul = 0xaa, .osr = 0x0e, .brg = 0x7c}, /* Actual: 4800.00 baud/s, err: 0.00% */
|
||||
[APP_UART_BAUD_9600] = {.mul = 0x08, .osr = 0x0e, .brg = 0x64}, /* Actual: 9599.82 baud/s, err: 0.00% */
|
||||
[APP_UART_BAUD_19200] = {.mul = 0xcb, .osr = 0x0e, .brg = 0x1c}, /* Actual: 19198.92 baud/s, err: 0.01% */
|
||||
[APP_UART_BAUD_38400] = {.mul = 0xcc, .osr = 0x06, .brg = 0x1e}, /* Actual: 38402.46 baud/s, err: -0.01% */
|
||||
[APP_UART_BAUD_57600] = {.mul = 0xcb, .osr = 0x04, .brg = 0x1c}, /* Actual: 57596.75 baud/s, err: 0.01% */
|
||||
[APP_UART_BAUD_115200] = {.mul = 0x18, .osr = 0x06, .brg = 0x10}, /* Actual: 115207.37 baud/s, err: -0.01% */
|
||||
[APP_UART_BAUD_230400] = {.mul = 0xa0, .osr = 0x09, .brg = 0x03}, /* Actual: 230421.69 baud/s, err: -0.01% */
|
||||
[APP_UART_BAUD_460800] = {.mul = 0xa0, .osr = 0x09, .brg = 0x01}, /* Actual: 460843.37 baud/s, err: -0.01% */
|
||||
[APP_UART_BAUD_921600] = {.mul = 0xa0, .osr = 0x09, .brg = 0x00}, /* Actual: 921686.75 baud/s, err: -0.01% */
|
||||
};
|
||||
|
||||
static volatile app_uart_baud_t s_cfg_baud; /* Register interface configuration */
|
||||
|
||||
static volatile uint8_t s_rx_fifo[16];
|
||||
static volatile uint8_t s_rx_fifo_w_ptr; /* Incremented by USART RXDAT read */
|
||||
static volatile uint8_t s_rx_fifo_r_ptr; /* Incremented by I2C RX FIFO read */
|
||||
|
||||
static volatile uint8_t s_tx_fifo[16];
|
||||
static volatile uint8_t s_tx_fifo_w_ptr; /* Incremented by I2C TX FIFO write */
|
||||
static volatile uint8_t s_tx_fifo_r_ptr; /* Incremented by USART TXDAT write */
|
||||
|
||||
static inline void app_uart_apply_clock_preset(const app_uart_clk_preset_t *preset);
|
||||
|
||||
static inline uint16_t app_uart_read_reg_cfg(void);
|
||||
static inline void app_uart_write_reg_cfg(uint16_t data);
|
||||
static inline uint16_t app_uart_read_reg_stat(void);
|
||||
|
||||
void app_uart_init(void) {
|
||||
/* Main Clock -> FRG -> USART0 */
|
||||
CLOCK_Select(kFRG0_Clk_From_MainClk);
|
||||
CLOCK_Select(kUART0_Clk_From_Frg0Clk);
|
||||
CLOCK_EnableClock(kCLOCK_Uart0);
|
||||
|
||||
RESET_PeripheralReset(kUART0_RST_N_SHIFT_RSTn);
|
||||
|
||||
s_cfg_baud = APP_UART_BAUD_115200;
|
||||
|
||||
s_rx_fifo_r_ptr = 0x00U;
|
||||
s_rx_fifo_w_ptr = 0x00U;
|
||||
|
||||
s_tx_fifo_r_ptr = 0x00U;
|
||||
s_tx_fifo_w_ptr = 0x00U;
|
||||
|
||||
USART0->CFG = USART_CFG_DATALEN(1); /* 8N1, No parity, No HW FC */
|
||||
USART0->CTL = 0x00U;
|
||||
|
||||
app_uart_apply_clock_preset(&s_clk_preset[s_cfg_baud]);
|
||||
}
|
||||
|
||||
uint16_t app_uart_module_reg_read(uint8_t addr) {
|
||||
return 0x0000;
|
||||
uint16_t ret = 0x5555U;
|
||||
|
||||
switch (addr) {
|
||||
case APP_UART_REG_OFFSET_CFG:
|
||||
ret = app_uart_read_reg_cfg();
|
||||
break;
|
||||
case APP_UART_REG_OFFSET_STAT:
|
||||
ret = app_uart_read_reg_stat();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void app_uart_module_reg_write(uint8_t addr, uint16_t data) {
|
||||
switch (addr) {
|
||||
case APP_UART_REG_OFFSET_CFG:
|
||||
app_uart_write_reg_cfg(data);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void app_uart_apply_clock_preset(const app_uart_clk_preset_t *preset) {
|
||||
SYSCON->FRG[0].FRGDIV = 0xFFU;
|
||||
SYSCON->FRG[0].FRGMULT = preset->mul;
|
||||
|
||||
USART0->BRG = preset->brg;
|
||||
USART0->OSR = preset->osr;
|
||||
}
|
||||
|
||||
static inline uint16_t app_uart_read_reg_cfg(void) {
|
||||
/* CFG register fields:
|
||||
* EN: [15]
|
||||
* BAUD: [3:0]
|
||||
*/
|
||||
|
||||
uint16_t ret = 0x0000;
|
||||
|
||||
ret |= (s_cfg_baud << APP_UART_REG_CFG_BAUD_Pos) & APP_UART_REG_CFG_BAUD_Msk;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline void app_uart_write_reg_cfg(uint16_t data) {
|
||||
app_uart_baud_t baud = (data & APP_UART_REG_CFG_BAUD_Msk) >> APP_UART_REG_CFG_BAUD_Pos;
|
||||
bool uart_en = (data & APP_UART_REG_CFG_EN_Msk) >> APP_UART_REG_CFG_EN_Pos;
|
||||
|
||||
if (uart_en) {
|
||||
/* -- TODO: Enable UART -- */
|
||||
return;
|
||||
}
|
||||
|
||||
/* Baud rate can't be changed when UART is enabled */
|
||||
if (baud >= APP_UART_BAUD_END) {
|
||||
return;
|
||||
}
|
||||
|
||||
app_uart_apply_clock_preset(&s_clk_preset[baud]);
|
||||
s_cfg_baud = baud;
|
||||
}
|
||||
|
||||
static inline uint16_t app_uart_read_reg_stat(void) {
|
||||
uint16_t ret = 0x0000;
|
||||
|
||||
return ret;
|
||||
}
|
Loading…
Reference in New Issue
Block a user