【简介】
现在接触的主流的MCU 都会支持图形化的配置工具,同样TI 的MSPM0L1306 也是支持的,我们可以使用TI System Configuration Tool 工具来配置clock/pin/及外设参数的配置。
【时钟配置】
MSPM0L1306 没有外接晶振,使用内部SYSOSC作为时钟源,内部配置为32M的时钟,配置如下
【UART配置】
从框图上可以看出MSPM0L1306 的一路串口通过调试器的虚拟串口连接到USB,我们可以使用该路UART来调试从而不需要外接USB串口来调试。
对应的引脚为PA8/A9
使用配置工具配置uart 参数
配置pinmux
配置后会生成如下的配置代码
ti_msp_dl_config.c
/* * Copyright (c) 2023, 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. */ /* * ============ ti_msp_dl_config.c ============= * Configured MSPM0 DriverLib module definitions * * DO NOT EDIT - This file is generated for the LP_MSPM0L1306 * by the SysConfig tool. */ #include "ti_msp_dl_config.h" /* * ======== SYSCFG_DL_init ======== * Perform any initialization needed before using any board APIs */ SYSCONFIG_WEAK void SYSCFG_DL_init(void) { SYSCFG_DL_initPower(); SYSCFG_DL_GPIO_init(); /* Module-Specific Initializations*/ SYSCFG_DL_SYSCTL_init(); SYSCFG_DL_UART_0_init(); } SYSCONFIG_WEAK void SYSCFG_DL_initPower(void) { DL_GPIO_reset(GPIOA); DL_UART_Main_reset(UART_0_INST); DL_GPIO_enablePower(GPIOA); DL_UART_Main_enablePower(UART_0_INST); delay_cycles(POWER_STARTUP_DELAY); } SYSCONFIG_WEAK void SYSCFG_DL_GPIO_init(void) { DL_GPIO_initPeripheralOutputFunction( GPIO_UART_0_IOMUX_TX, GPIO_UART_0_IOMUX_TX_FUNC); DL_GPIO_initPeripheralInputFunction( GPIO_UART_0_IOMUX_RX, GPIO_UART_0_IOMUX_RX_FUNC); } SYSCONFIG_WEAK void SYSCFG_DL_SYSCTL_init(void) { //Low Power Mode is configured to be SLEEP0 DL_SYSCTL_setBORThreshold(DL_SYSCTL_BOR_THRESHOLD_LEVEL_0); DL_SYSCTL_setSYSOSCFreq(DL_SYSCTL_SYSOSC_FREQ_BASE); DL_SYSCTL_setMCLKDivider(DL_SYSCTL_MCLK_DIVIDER_DISABLE); } static const DL_UART_Main_ClockConfig gUART_0ClockConfig = { .clockSel = DL_UART_MAIN_CLOCK_BUSCLK, .divideRatio = DL_UART_MAIN_CLOCK_DIVIDE_RATIO_1 }; static const DL_UART_Main_Config gUART_0Config = { .mode = DL_UART_MAIN_MODE_NORMAL, .direction = DL_UART_MAIN_DIRECTION_TX_RX, .flowControl = DL_UART_MAIN_FLOW_CONTROL_NONE, .parity = DL_UART_MAIN_PARITY_NONE, .wordLength = DL_UART_MAIN_WORD_LENGTH_8_BITS, .stopBits = DL_UART_MAIN_STOP_BITS_ONE }; SYSCONFIG_WEAK void SYSCFG_DL_UART_0_init(void) { DL_UART_Main_setClockConfig(UART_0_INST, (DL_UART_Main_ClockConfig *) &gUART_0ClockConfig); DL_UART_Main_init(UART_0_INST, (DL_UART_Main_Config *) &gUART_0Config); /* * Configure baud rate by setting oversampling and baud rate divisors. * Target baud rate: 115200 * Actual baud rate: 115211.52 */ DL_UART_Main_setOversampling(UART_0_INST, DL_UART_OVERSAMPLING_RATE_16X); DL_UART_Main_setBaudRateDivisor(UART_0_INST, UART_0_IBRD_32_MHZ_115200_BAUD, UART_0_FBRD_32_MHZ_115200_BAUD); DL_UART_Main_enable(UART_0_INST); }
ti_msp_dl_config.h
/* * Copyright (c) 2023, Texas Instruments Incorporated - http://www.ti.com * 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. */ /* * ============ ti_msp_dl_config.h ============= * Configured MSPM0 DriverLib module declarations * * DO NOT EDIT - This file is generated for the LP_MSPM0L1306 * by the SysConfig tool. */ #ifndef ti_msp_dl_config_h #define ti_msp_dl_config_h #define CONFIG_LP_MSPM0L1306 #define CONFIG_MSPM0L1306 #if defined(__ti_version__) || defined(__TI_COMPILER_VERSION__) #define SYSCONFIG_WEAK __attribute__((weak)) #elif defined(__IAR_SYSTEMS_ICC__) #define SYSCONFIG_WEAK __weak #elif defined(__GNUC__) #define SYSCONFIG_WEAK __attribute__((weak)) #endif #include <ti/devices/msp/msp.h> #include <ti/driverlib/driverlib.h> #include <ti/driverlib/m0p/dl_core.h> #ifdef __cplusplus extern "C" { #endif /* * ======== SYSCFG_DL_init ======== * Perform all required MSP DL initialization * * This function should be called once at a point before any use of * MSP DL. */ /* clang-format off */ #define POWER_STARTUP_DELAY (16) #define CPUCLK_FREQ 32000000 /* Defines for UART_0 */ #define UART_0_INST UART0 #define UART_0_INST_FREQUENCY 32000000 #define UART_0_INST_IRQHandler UART0_IRQHandler #define UART_0_INST_INT_IRQN UART0_INT_IRQn #define GPIO_UART_0_RX_PORT GPIOA #define GPIO_UART_0_TX_PORT GPIOA #define GPIO_UART_0_RX_PIN DL_GPIO_PIN_9 #define GPIO_UART_0_TX_PIN DL_GPIO_PIN_8 #define GPIO_UART_0_IOMUX_RX (IOMUX_PINCM10) #define GPIO_UART_0_IOMUX_TX (IOMUX_PINCM9) #define GPIO_UART_0_IOMUX_RX_FUNC IOMUX_PINCM10_PF_UART0_RX #define GPIO_UART_0_IOMUX_TX_FUNC IOMUX_PINCM9_PF_UART0_TX #define UART_0_BAUD_RATE (115200) #define UART_0_IBRD_32_MHZ_115200_BAUD (17) #define UART_0_FBRD_32_MHZ_115200_BAUD (23) /* clang-format on */ void SYSCFG_DL_init(void); void SYSCFG_DL_initPower(void); void SYSCFG_DL_GPIO_init(void); void SYSCFG_DL_SYSCTL_init(void); void SYSCFG_DL_UART_0_init(void); #ifdef __cplusplus } #endif #endif /* ti_msp_dl_config_h */
【测试验证】
我们在main 函数内添加如下测试代码回显接收到的串口数据
#include "ti_msp_dl_config.h" int main(void) { SYSCFG_DL_init(); uint8_t data; while (1) { /* Wait to receive UART_PACKET_SIZE bytes of data */ data = DL_UART_Extend_receiveDataBlocking(UART_0_INST); /* Echo back the received data */ DL_UART_Extend_transmitDataBlocking(UART_0_INST,data); } return 0; }
下载运行后跟预期的一致对输入的数据进行回显显示