Multiple tidying and warnings fixed, added LICENSE

This commit is contained in:
imi415 2022-03-29 01:00:15 +08:00
parent a25b896bb0
commit a069d0ba20
Signed by untrusted user: imi415
GPG Key ID: 885EC2B5A8A6F8A7
10 changed files with 98 additions and 63 deletions

View File

@ -88,7 +88,7 @@ void USART_Printf_Init(uint32_t baudrate)
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
#if(DEBUG == DEBUG_UART1)
#if(DEBUG_UART == DEBUG_UART1)
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
@ -96,7 +96,7 @@ void USART_Printf_Init(uint32_t baudrate)
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
#elif(DEBUG == DEBUG_UART2)
#elif(DEBUG_UART == DEBUG_UART2)
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
@ -105,7 +105,7 @@ void USART_Printf_Init(uint32_t baudrate)
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
#elif(DEBUG == DEBUG_UART3)
#elif(DEBUG_UART == DEBUG_UART3)
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
@ -123,15 +123,15 @@ void USART_Printf_Init(uint32_t baudrate)
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Tx;
#if(DEBUG == DEBUG_UART1)
#if(DEBUG_UART == DEBUG_UART1)
USART_Init(USART1, &USART_InitStructure);
USART_Cmd(USART1, ENABLE);
#elif(DEBUG == DEBUG_UART2)
#elif(DEBUG_UART == DEBUG_UART2)
USART_Init(USART2, &USART_InitStructure);
USART_Cmd(USART2, ENABLE);
#elif(DEBUG == DEBUG_UART3)
#elif(DEBUG_UART == DEBUG_UART3)
USART_Init(USART3, &USART_InitStructure);
USART_Cmd(USART3, ENABLE);
@ -154,13 +154,13 @@ __attribute__((used)) int _write(int fd, char *buf, int size)
for(i = 0; i < size; i++)
{
#if(DEBUG == DEBUG_UART1)
#if(DEBUG_UART == DEBUG_UART1)
while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
USART_SendData(USART1, *buf++);
#elif(DEBUG == DEBUG_UART2)
#elif(DEBUG_UART == DEBUG_UART2)
while(USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET);
USART_SendData(USART2, *buf++);
#elif(DEBUG == DEBUG_UART3)
#elif(DEBUG_UART == DEBUG_UART3)
while(USART_GetFlagStatus(USART3, USART_FLAG_TC) == RESET);
USART_SendData(USART3, *buf++);
#endif

View File

@ -11,7 +11,7 @@
#ifndef __DEBUG_H
#define __DEBUG_H
#include "stdio.h"
#include <stdio.h>
#include "ch32v30x.h"
/* UART Printf Definition */
@ -19,8 +19,8 @@
#define DEBUG_UART2 2
#define DEBUG_UART3 3
/* DEBUG UATR Definition */
#define DEBUG DEBUG_UART1
/* DEBUG UART Definition */
#define DEBUG_UART DEBUG_UART1
//#define DEBUG DEBUG_UART2
//#define DEBUG DEBUG_UART3

View File

@ -7,8 +7,8 @@ PROVIDE( _stack_size = __stack_size );
MEMORY
{
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 288K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 288K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K
}
@ -22,13 +22,13 @@ SECTIONS
KEEP(*(SORT_NONE(.init)))
. = ALIGN(4);
_einit = .;
} >FLASH AT>FLASH
} >FLASH
.vector :
{
*(.vector);
. = ALIGN(64);
} >FLASH AT>FLASH
} >FLASH
.text :
{
@ -41,13 +41,13 @@ SECTIONS
*(.glue_7t)
*(.gnu.linkonce.t.*)
. = ALIGN(4);
} >FLASH AT>FLASH
} >FLASH
.fini :
{
KEEP(*(SORT_NONE(.fini)))
. = ALIGN(4);
} >FLASH AT>FLASH
} >FLASH
PROVIDE( _etext = . );
PROVIDE( _eitcm = . );
@ -57,7 +57,7 @@ SECTIONS
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
} >FLASH AT>FLASH
} >FLASH
.init_array :
{
@ -65,7 +65,7 @@ SECTIONS
KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
PROVIDE_HIDDEN (__init_array_end = .);
} >FLASH AT>FLASH
} >FLASH
.fini_array :
{
@ -73,38 +73,40 @@ SECTIONS
KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
PROVIDE_HIDDEN (__fini_array_end = .);
} >FLASH AT>FLASH
} >FLASH
.ctors :
{
/* gcc uses crtbegin.o to find the start of
the constructors, so we make sure it is
first. Because this is a wildcard, it
doesn't matter if the user does not
actually link against crtbegin.o; the
linker won't look for a file to match a
wildcard. The wildcard also means that it
doesn't matter which directory crtbegin.o
is in. */
KEEP (*crtbegin.o(.ctors))
KEEP (*crtbegin?.o(.ctors))
/* We don't want to include the .ctor section from
the crtend.o file until after the sorted ctors.
The .ctor section from the crtend file contains the
end of ctors marker and it must be last */
/* gcc uses crtbegin.o to find the start of
the constructors, so we make sure it is
first. Because this is a wildcard, it
doesn't matter if the user does not
actually link against crtbegin.o; the
linker won't look for a file to match a
wildcard. The wildcard also means that it
doesn't matter which directory crtbegin.o
is in.
*/
KEEP (*crtbegin.o(.ctors))
KEEP (*crtbegin?.o(.ctors))
/* We don't want to include the .ctor section from
the crtend.o file until after the sorted ctors.
The .ctor section from the crtend file contains the
end of ctors marker and it must be last
*/
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
} >FLASH AT>FLASH
} >FLASH
.dtors :
{
KEEP (*crtbegin.o(.dtors))
KEEP (*crtbegin?.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
} >FLASH AT>FLASH
KEEP (*crtbegin.o(.dtors))
KEEP (*crtbegin?.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
} >FLASH
.dalign :
{
@ -142,18 +144,23 @@ SECTIONS
{
. = ALIGN(4);
PROVIDE( _sbss = .);
*(.sbss*)
*(.sbss*)
*(.gnu.linkonce.sb.*)
*(.bss*)
*(.gnu.linkonce.b.*)
*(.gnu.linkonce.b.*)
*(COMMON*)
. = ALIGN(4);
PROVIDE( _ebss = .);
} >RAM AT>FLASH
} >RAM
PROVIDE( _end = _ebss);
PROVIDE( end = . );
.heap :
{
}
.stack ORIGIN(RAM) + LENGTH(RAM) - __stack_size :
{
PROVIDE( _heap_end = . );

View File

@ -947,11 +947,11 @@ Wake-UpFrame Filter Re7 : Filter3 CRC16 - Filter2 CRC16 */
#define ETH_MACA3HR_MACA3H ((unsigned int)0x0000FFFF) /* MAC address3 high */
#define ETH_MACA3LR_MACA3L ((unsigned int)0xFFFFFFFF) /* MAC address3 low */
/******************************************************************************/
/*
/* ETH MMC Register
/*
/******************************************************************************/
/******************************************************************************
*
* ETH MMC Register
*
******************************************************************************/
#define ETH_MMCCR_MCFHP ((unsigned int)0x00000020) /* MMC counter Full-Half preset */
#define ETH_MMCCR_MCP ((unsigned int)0x00000010) /* MMC counter preset */
#define ETH_MMCCR_MCF ((unsigned int)0x00000008) /* MMC Counter Freeze */
@ -988,11 +988,11 @@ Wake-UpFrame Filter Re7 : Filter3 CRC16 - Filter2 CRC16 */
#define ETH_MMCRGUFCR_RGUFC ((unsigned int)0xFFFFFFFF) /* Number of good unicast frames received. */
/******************************************************************************/
/*
/* ETH Precise Clock Protocol Register
/*
/******************************************************************************/
/******************************************************************************
*
* ETH Precise Clock Protocol Register
*
******************************************************************************/
#define ETH_PTPTSCR_TSCNT ((unsigned int)0x00030000) /* Time stamp clock node type */
#define ETH_PTPTSSR_TSSMRME ((unsigned int)0x00008000) /* Time stamp snapshot for message relevant to master enable */
#define ETH_PTPTSSR_TSSEME ((unsigned int)0x00004000) /* Time stamp snapshot for event message enable */
@ -1031,11 +1031,11 @@ Wake-UpFrame Filter Re7 : Filter3 CRC16 - Filter2 CRC16 */
#define ETH_PTPTSSR_TSTTR ((unsigned int)0x00000020) /* Time stamp target time reached */
#define ETH_PTPTSSR_TSSO ((unsigned int)0x00000010) /* Time stamp seconds overflow */
/******************************************************************************/
/*
/* ETH DMA Register
/*
/******************************************************************************/
/******************************************************************************
*
* ETH DMA Register
*
******************************************************************************/
#define ETH_DMABMR_AAB ((unsigned int)0x02000000) /* Address-Aligned beats */
#define ETH_DMABMR_FPM ((unsigned int)0x01000000) /* 4xPBL mode */
#define ETH_DMABMR_USP ((unsigned int)0x00800000) /* Use separate PBL */

View File

@ -1285,7 +1285,7 @@ FlagStatus ETH_GetSoftwareResetStatus(void)
{
bitstatus = RESET;
}
printf("ETH->DMABMR is:%08x\n", ETH->DMABMR);
printf("ETH->DMABMR is:%08lx\n", ETH->DMABMR);
return bitstatus;
}
@ -1432,7 +1432,7 @@ ITStatus ETH_GetDMAITStatus(uint32_t ETH_DMA_IT)
/*********************************************************************
* @fn ETH_DMAClearITPendingBit
*
* @brief Clears the ETHERNETs DMA IT pending bit.
* @brief Clears the ETHERNET<EFBFBD>s DMA IT pending bit.
*
* @param ETH_DMA_IT - specifies the interrupt pending bit to clear.
* ETH_DMA_IT_NIS - Normal interrupt summary

View File

@ -1,3 +1,5 @@
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.10)
project(ch32v307_template)

8
LICENSE Normal file
View File

@ -0,0 +1,8 @@
Copyright 2021 imi415
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

8
LICENSE.wch Normal file
View File

@ -0,0 +1,8 @@
THIS SOFTWARE CONTAINS A LOT OF UNLICENSED CODE FROM WCH.
These code can be downloaded from www.wch.cn, without *ANY* licenses provided,
assuming they can be reproduced and re distributed.
So, USE THEM AT YOUR OWN RISKS, modifications are made, see commit log or diff them manually.
Anything comes without a SPDX-License-Identifier header are subject to this LICENSE.
Fly safe and godspeed.

View File

@ -1,3 +1,5 @@
<!-- SPDX-License-Identifier: MIT -->
# Template for WCH CH32V30x series MCU
## How to use
@ -25,3 +27,9 @@ The first file is used for CH32V303 devices, which lacks of the following periph
* DVP
** Change the startup file to the correct version for the hardware in use. **
## Compilers
These MCUs uses something called "RISC-V4A" core without further documentation provided, AFAIK.
Here is the list of features proprietary or incompatible with upstream toolchain:
* Fast IRQ handlers: uses a special attribute of `interrupt`, which value is `WCH-Interrupt-fast`

View File

@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
int main(void) {
for(;;) {
//