This commit is contained in:
cfif 2024-12-04 13:10:47 +03:00
commit 59102c006e
14 changed files with 828 additions and 0 deletions

41
bsp/inc/delay.h Normal file
View File

@ -0,0 +1,41 @@
/*****************************************************************************
* Copyright (c) 2019, Nations Technologies Inc.
*
* 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 disclaimer below.
*
* Nations' name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OPT
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL NATIONS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OPT CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OPT SERVICES; LOSS OF USE, DATA,
* OPT PROFITS; OPT BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OPT TORT (INCLUDING
* NEGLIGENCE OPT OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ****************************************************************************/
/**
* @file delay.h
* @author Nations
* @version v1.0.0
*
* @copyright Copyright (c) 2019, Nations Technologies Inc. All rights reserved.
*/
#ifndef __DELAY_H__
#define __DELAY_H__
#include "n32g45x.h"
void systick_delay_us(u32 nus);
void systick_delay_ms(u16 nms);
#endif /* __DELAY_H__ */

104
bsp/inc/log.h Normal file
View File

@ -0,0 +1,104 @@
/*****************************************************************************
* Copyright (c) 2019, Nations Technologies Inc.
*
* 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 disclaimer below.
*
* Nations' name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL NATIONS 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.
* ****************************************************************************/
/**
* @file log.h
* @author Nations
* @version v1.0.1
*
* @copyright Copyright (c) 2019, Nations Technologies Inc. All rights reserved.
*/
#ifndef __LOG_H__
#define __LOG_H__
#ifndef LOG_ENABLE
#define LOG_ENABLE 1
#endif
#if LOG_ENABLE
#include "n32g45x.h"
#include <stdio.h>
#define LOG_USARTx USART1
#define LOG_PERIPH RCC_APB2_PERIPH_USART1
#define LOG_ENABLE_PERIPH_CLK RCC_EnableAPB2PeriphClk
#define LOG_GPIO GPIOA
#define LOG_PERIPH_GPIO RCC_APB2_PERIPH_GPIOA
#define LOG_REMAP 0
#define LOG_TX_PIN GPIO_PIN_9
#define LOG_RX_PIN GPIO_PIN_10
#define LOG_NONE 0
#define LOG_ERROR 10
#define LOG_WARNING 20
#define LOG_INFO 30
#define LOG_DEBUG 40
#ifndef LOG_LEVEL
#define LOG_LEVEL LOG_DEBUG
#endif
#if LOG_LEVEL >= LOG_INFO
#define log_info(...) printf(__VA_ARGS__)
#else
#define log_info(...)
#endif
#if LOG_LEVEL >= LOG_ERROR
#define log_error(...) printf(__VA_ARGS__)
#else
#define log_error(...)
#endif
#if LOG_LEVEL >= LOG_WARNING
#define log_warning(...) printf(__VA_ARGS__)
#else
#define log_warning(...)
#endif
#if LOG_LEVEL >= LOG_DEBUG
#define log_debug(...) printf(__VA_ARGS__)
#else
#define log_debug(...)
#endif
void log_init(void);
#else /* !LOG_ENABLE */
#define log_info(...)
#define log_warning(...)
#define log_error(...)
#define log_debug(...)
#define log_init()
#endif
#define log_func() log_debug("call %s\r\n", __FUNCTION__)
#endif /* __LOG_H__ */

10
bsp/modular.json Normal file
View File

@ -0,0 +1,10 @@
{
"cmake": {
"inc_dirs": [
"inc/"
],
"srcs": [
"src/**.c"
]
}
}

79
bsp/src/delay.c Normal file
View File

@ -0,0 +1,79 @@
/*****************************************************************************
* Copyright (c) 2019, Nations Technologies Inc.
*
* 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 disclaimer below.
*
* Nations' name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OPT
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL NATIONS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OPT CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OPT SERVICES; LOSS OF USE, DATA,
* OPT PROFITS; OPT BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OPT TORT (INCLUDING
* NEGLIGENCE OPT OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ****************************************************************************/
/**
* @file delay.c
* @author Nations
* @version v1.0.0
*
* @copyright Copyright (c) 2019, Nations Technologies Inc. All rights reserved.
*/
#include "delay.h"
/**
* @brief us delay program function.
* @param nus: the setting us value.
* note: The system clock should be an integer multiple of 1M .
* It is ensure accuracy .
*/
void systick_delay_us(u32 nus)
{
u32 temp;
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK); //select system clock
SysTick->LOAD=nus*(SystemCoreClock/1000000); //time relode
SysTick->VAL=0x00; //clear timer value
SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk ; //Start countdown
do
{
temp=SysTick->CTRL;
}
while(temp&0x01&&!(temp&(1<<16)));//wait for the time reach
SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk; //close the count
SysTick->VAL =0X00; //clear timer value
}
/**
* @brief us delay program function.
* @param nus: the setting us value.
* note: The system clock should be an integer multiple of 1M .
* It is ensure accuracy .
*/
void systick_delay_ms(u16 nms)
{
u32 temp;
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK); //select system clock
SysTick->LOAD=(u32)nms*((SystemCoreClock/1000000)*1000);//time relode(SysTick->LOAD is 24bit)
SysTick->VAL =0x00; //clear timer value
SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk ; //Start countdown
do
{
temp=SysTick->CTRL;
}
while(temp&0x01&&!(temp&(1<<16)));//wait for the time reach
SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk; //close the count
SysTick->VAL =0X00; //clear timer value
}

126
bsp/src/log.c Normal file
View File

@ -0,0 +1,126 @@
/*****************************************************************************
* Copyright (c) 2019, Nations Technologies Inc.
*
* 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 disclaimer below.
*
* Nations' name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL NATIONS 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.
* ****************************************************************************/
/**
* @file log.c
* @author Nations
* @version v1.0.1
*
* @copyright Copyright (c) 2019, Nations Technologies Inc. All rights reserved.
*/
#include "log.h"
#if LOG_ENABLE
void log_init(void)
{
GPIO_InitType GPIO_InitStructure;
USART_InitType USART_InitStructure;
// close JTAG
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_AFIO | LOG_PERIPH_GPIO, ENABLE);
if (LOG_REMAP)
{
if (LOG_REMAP == GPIO_RMP3_USART2)
{
// release PB4
GPIO_ConfigPinRemap(GPIO_RMP_SW_JTAG_NO_NJTRST, ENABLE);
}
GPIO_ConfigPinRemap(LOG_REMAP, ENABLE);
}
LOG_ENABLE_PERIPH_CLK(LOG_PERIPH, ENABLE);
GPIO_InitStructure.Pin = LOG_TX_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitPeripheral(LOG_GPIO, &GPIO_InitStructure);
//GPIO_InitStructure.Pin = LOG_RX_PIN;
//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
//GPIO_InitPeripheral(LOG_GPIO, &GPIO_InitStructure);
USART_InitStructure.BaudRate = 115200;
USART_InitStructure.WordLength = USART_WL_8B;
USART_InitStructure.StopBits = USART_STPB_1;
USART_InitStructure.Parity = USART_PE_NO;
USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE;
USART_InitStructure.Mode = USART_MODE_TX;
// init uart
USART_Init(LOG_USARTx, &USART_InitStructure);
// enable uart
USART_Enable(LOG_USARTx, ENABLE);
}
static int is_lr_sent = 0;
int fputc(int ch, FILE* f)
{
if (ch == '\r')
{
is_lr_sent = 1;
}
else if (ch == '\n')
{
if (!is_lr_sent)
{
USART_SendData(LOG_USARTx, (uint8_t)'\r');
/* Loop until the end of transmission */
while (USART_GetFlagStatus(LOG_USARTx, USART_FLAG_TXC) == RESET)
{
}
}
is_lr_sent = 0;
}
else
{
is_lr_sent = 0;
}
USART_SendData(LOG_USARTx, (uint8_t)ch);
/* Loop until the end of transmission */
while (USART_GetFlagStatus(LOG_USARTx, USART_FLAG_TXC) == RESET)
{
}
return ch;
}
#ifdef USE_FULL_ASSERT
__WEAK void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line)
{
log_error("assertion failed: `%s` at %s:%d", expr, file, line);
while (1)
{
}
}
#endif // USE_FULL_ASSERT
#endif // LOG_ENABLE

73
bsp/src/print_remap.c Normal file
View File

@ -0,0 +1,73 @@
/*****************************************************************************
* Copyright (c) 2019, Nations Technologies Inc.
*
* 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 disclaimer below.
*
* Nations' name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL NATIONS 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.
* ****************************************************************************/
/**
* @file print_remap.c
* @author Nations Solution Team
* @version v1.0.0
*
* @copyright Copyright (c) 2019, Nations Technologies Inc. All rights reserved.
*/
#include "stdio.h"
#include "stdlib.h"
#include "n32g45x.h"
#include "main2.h"
/** @addtogroup N32G45X_StdPeriph_Template
* @{
*/
int _write (int fd, char *pBuffer, int size)
{
// uint16_t timeout = 0xFF;
uint32_t i;
for (i = 0; i < size; i++)
{
fputc((uint8_t)pBuffer[i], stdout);
/*
USART_SendData(USARTx, (uint8_t)pBuffer[i]);
while (USART_GetFlagStatus(USARTx, USART_FLAG_TXDE) == RESET)
{
if (!timeout--)
{
break;
}
}
*/
}
return size;
}
int _read (int fd, char *pBuffer, int size)
{
return size;
}
/**
* @}
*/

BIN
can.zip Normal file

Binary file not shown.

10
modular.json Normal file
View File

@ -0,0 +1,10 @@
{
"cmake": {
"inc_dirs": [
"can"
],
"srcs": [
"can/**.c"
]
}
}

65
prj/CMakeLists.txt Executable file
View File

@ -0,0 +1,65 @@
#-- Service --------------------------------------------------------------------
SET(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/MODULES/CmakeConfig_GCC_CortexM4/gcc_cm4f.cmake)
ENABLE_LANGUAGE(ASM)
CMAKE_MINIMUM_REQUIRED(VERSION 3.8.0)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0")
IF (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
MESSAGE(
FATAL_ERROR
"In-source builds not allowed.
Please make a new directory (called a build directory) and run CMake from there.
You may need to remove CMakeCache.txt."
)
ENDIF ()
SET(CMAKE_EXPORT_COMPILE_COMMANDS ON)
#-- Project config -------------------------------------------------------------
PROJECT(HW_TEST) # Project name
SET(MCUNAME N32G45X) # MCU name
SET(USE_STDPERIPH_DRIVER 0) # OSECLK value in Hz (0 if disconnected)
SET(OSECLK_VAL 12000000) # OSECLK value in Hz (0 if disconnected)
SET(SYSCLK PLL) # SYSCLK source: PLL, OSI, OSE
SET(CKO NONE) # Clockout source: PLL, NONE (no clockout)
SET(RETARGET 1) # Enable(1) or disable(0) printf retarget
SET(RETARGET_USE UART) # ITM or UART printf retarget
SET(PRINTF_FLOAT 0) # Enable(1) or disable(0) printf float support
SET(SCANF_FLOAT 0) # Enable(1) or disable(0) scanf float support
#-- Defines --------------------------------------------------------------------
ADD_DEFINITIONS(-D${MCUNAME})
ADD_DEFINITIONS(-DUSE_STDPERIPH_DRIVER)
ADD_DEFINITIONS(-DHSE_VALUE=16000000)
ADD_DEFINITIONS(-DCMSIS_device_header="n32g45x.h")
#-- Project paths, Include dirs, Sources list ---------------------------------
include(modular.cmake)
#-- Options --------------------------------------------------------------------
IF (PRINTF_FLOAT STREQUAL "1")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -u_printf_float")
ENDIF ()
IF (SCANF_FLOAT STREQUAL "1")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -u_scanf_float")
ENDIF ()
#-- Linker script --------------------------------------------------------------
SET(LDSCRIPT ${CMAKE_SOURCE_DIR}/MODULES/DeviceStartup_NATION_N32G45X/Ld/n32g45x_flash.ld)
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -T ${LDSCRIPT} -Wl,-Map=${CMAKE_BINARY_DIR}/${PROJECT_NAME}.map -Wl,--print-memory-usage")
#-- Project linking ------------------------------------------------------------
ADD_EXECUTABLE(${PROJECT_NAME}.elf ${SOURCES})
TARGET_LINK_LIBRARIES(${PROJECT_NAME}.elf)
#-- Custom commands ------------------------------------------------------------
ADD_CUSTOM_COMMAND(TARGET ${PROJECT_NAME}.elf POST_BUILD
COMMAND ${CMAKE_OBJCOPY} "-Oihex" ${PROJECT_NAME}.elf ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.hex
COMMAND ${CMAKE_OBJCOPY} "-Obinary" ${PROJECT_NAME}.elf ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.bin
COMMAND ${CMAKE_OBJDUMP} "-DS" ${PROJECT_NAME}.elf > ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.dasm
COMMAND ${CMAKE_SIZE} ${PROJECT_NAME}.elf)

30
prj/modular.json Normal file
View File

@ -0,0 +1,30 @@
{
"dep": [
{
"type": "git",
"provider": "NAVIGATOR_UVEOS_NATION_TELIT",
"repo": "CmakeConfig_GCC_CortexM4"
},
{
"type": "git",
"provider": "NAVIGATOR_UVEOS_NATION_TELIT",
"repo": "DeviceStartup_NATION_N32G45X"
},
{
"type": "local",
"dir": "../bsp"
},
{
"type": "local",
"dir": "../i2cTest"
}
],
"cmake": {
"inc_dirs": [
"inc/"
],
"srcs": [
"src/**.c"
]
}
}

2
readme.md Normal file
View File

@ -0,0 +1,2 @@
Подпроект для тестирования железа на основе примеров от Nation.
Для запуска следует выполнить modular -c в папке prj, и работать с CMakeList.txt проектом из этой же папки

169
uartTest/main.c Normal file
View File

@ -0,0 +1,169 @@
#include <stdio.h>
#include "main.h"
USART_InitType USART_InitStructure;
void RCC_Configuration1(void);
void GPIO_Configuration1(void);
void NVIC_Configuration1(void);
void send(uint8_t *data, size_t size) {
uint8_t *end = data + size;
while (data < end) {
while (USART_GetFlagStatus(USARTx, USART_FLAG_TXDE) == RESET);
USART_SendData(USARTx, *data);
while (USART_GetFlagStatus(USARTx, USART_FLAG_TXDE) == RESET);
++data;
}
}
void delay(uint32_t ms) {
ms = ms * SystemCoreClock / 1000;
while (ms) {
--ms;
}
}
void USART1_IRQHandler() {
uint8_t byte;
while (USART_GetFlagStatus(USARTx, USART_FLAG_RXDNE) == SET) {
byte = USART_ReceiveData(USARTx);
send(&byte, 1);
}
}
void USART2_IRQHandler() {
uint8_t byte;
while (USART_GetFlagStatus(USARTx, USART_FLAG_RXDNE) == SET) {
byte = USART_ReceiveData(USARTx);
send(&byte, 1);
}
}
void UART4_IRQHandler() {
uint8_t byte;
while (USART_GetFlagStatus(USARTx, USART_FLAG_RXDNE) == SET) {
byte = USART_ReceiveData(USARTx);
send(&byte, 1);
}
}
void NVIC_Configuration1(void) {
NVIC_InitType NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStructure.NVIC_IRQChannel = UARTx_IRQn;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
int main(void) {
RCC_Configuration1();
NVIC_Configuration1();
GPIO_Configuration1();
USART_InitStructure.BaudRate = 115200;
USART_InitStructure.WordLength = USART_WL_8B;
USART_InitStructure.StopBits = USART_STPB_1;
USART_InitStructure.Parity = USART_PE_NO;
USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE;
USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX;
USART_Init(USARTx, &USART_InitStructure);
USART_ConfigInt(USARTx, USART_INT_RXDNE, ENABLE);
// USART_ConfigInt(USARTx, USART_INT_TXDE, ENABLE);
USART_Enable(USARTx, ENABLE);
char msg[] = "0 helo world\n";
#define STR(VAL) (uint8_t *)VAL,(sizeof (VAL)-1)
for (;;) {
++*msg;
if (*msg > '9') {
*msg = '0';
}
// send(STR(msg));
delay(3000);
}
}
/**
* @brief Configures the different system clocks.
*/
void RCC_Configuration1(void) {
GPIO_APBxClkCmd(USARTx_GPIO_CLK | RCC_APB2_PERIPH_AFIO, ENABLE);
USART_APBxClkCmd(USARTx_CLK, ENABLE);
}
void GPIO_Configuration1(void) {
GPIO_InitType GPIO_InitStructure;
GPIO_InitStructure.Pin = USARTx_TxPin;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure);
GPIO_InitStructure.Pin = USARTx_RxPin;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitPeripheral(USARTx_GPIO, &GPIO_InitStructure);
GPIO_ConfigPinRemap(GPIO_RMP_USART1, ENABLE);
// GPIO_ConfigPinRemap(GPIO_RMP1_USART2, ENABLE);
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file pointer to the source file name
* @param line assert_param error line source number
*/
void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
/**
* @}
*/
/**
* @}
*/

109
uartTest/main.h Normal file
View File

@ -0,0 +1,109 @@
/*****************************************************************************
* Copyright (c) 2019, Nations Technologies Inc.
*
* 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 disclaimer below.
*
* Nations' name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL NATIONS 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.
* ****************************************************************************/
/**
* @file main.h
* @author Nations
* @version v1.0.0
*
* @copyright Copyright (c) 2019, Nations Technologies Inc. All rights reserved.
*/
#ifndef __MAIN_H__
#define __MAIN_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "n32g45x.h"
#define _USART1_COM_
//#define _USART4_COM_
//#define _USART2_COM_
// A 10 9
#ifdef _USART1_COM_
#define USARTx USART1
#define USARTx_GPIO GPIOB
#define USARTx_CLK RCC_APB2_PERIPH_USART1
#define USARTx_GPIO_CLK RCC_APB2_PERIPH_GPIOB
#define USARTx_RxPin GPIO_PIN_7
#define USARTx_TxPin GPIO_PIN_6
#define UARTx_IRQn USART1_IRQn
#define GPIO_APBxClkCmd RCC_EnableAPB2PeriphClk
#define USART_APBxClkCmd RCC_EnableAPB2PeriphClk
#endif
//#ifdef _USART1_COM_
//#define USARTx USART1
//#define USARTx_GPIO GPIOA
//#define USARTx_CLK RCC_APB2_PERIPH_USART1
//#define USARTx_GPIO_CLK RCC_APB2_PERIPH_GPIOA
//#define USARTx_RxPin GPIO_PIN_10
//#define USARTx_TxPin GPIO_PIN_9
//
//#define UARTx_IRQn USART1_IRQn
//#define GPIO_APBxClkCmd RCC_EnableAPB2PeriphClk
//#define USART_APBxClkCmd RCC_EnableAPB2PeriphClk
//#endif
//#ifdef _USART4_COM_
//#define USARTx UART4
//#define USARTx_GPIO GPIOC
//#define USARTx_CLK RCC_APB1_PERIPH_UART4
//#define USARTx_GPIO_CLK RCC_APB2_PERIPH_GPIOC
//#define USARTx_RxPin GPIO_PIN_11
//#define USARTx_TxPin GPIO_PIN_10
//
//#define GPIO_APBxClkCmd RCC_EnableAPB2PeriphClk
//#define USART_APBxClkCmd RCC_EnableAPB1PeriphClk
//#define UARTx_IRQn UART4_IRQn
//#endif
//
//#ifdef _USART2_COM_
//#define USARTx USART2
//#define USARTx_GPIO GPIOD
//#define USARTx_CLK RCC_APB1_PERIPH_USART2
//#define USARTx_GPIO_CLK RCC_APB2_PERIPH_GPIOD
//#define USARTx_RxPin GPIO_PIN_6
//#define USARTx_TxPin GPIO_PIN_5
//
//#define GPIO_APBxClkCmd RCC_EnableAPB2PeriphClk
//#define USART_APBxClkCmd RCC_EnableAPB1PeriphClk
//#define UARTx_IRQn USART2_IRQn
//
//#endif
//
//#ifdef __cplusplus
//}
//#endif
#endif /* __MAIN_H__ */

10
uartTest/modular.json Normal file
View File

@ -0,0 +1,10 @@
{
"cmake": {
"inc_dirs": [
"./"
],
"srcs": [
"./**.c"
]
}
}