forked from Embedded_Projects/CH32V307_Template
Fixed memory usage report, check TXE instead of TC.
This commit is contained in:
parent
83a9bbbc96
commit
c7ba52be62
|
@ -155,14 +155,14 @@ __attribute__((used)) int _write(int fd, char *buf, int size)
|
||||||
for(i = 0; i < size; i++)
|
for(i = 0; i < size; i++)
|
||||||
{
|
{
|
||||||
#if(DEBUG_UART == DEBUG_UART1)
|
#if(DEBUG_UART == DEBUG_UART1)
|
||||||
while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
|
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
|
||||||
USART_SendData(USART1, *buf++);
|
USART_SendData(USART1, buf[i]);
|
||||||
#elif(DEBUG_UART == DEBUG_UART2)
|
#elif(DEBUG_UART == DEBUG_UART2)
|
||||||
while(USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET);
|
while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
|
||||||
USART_SendData(USART2, *buf++);
|
USART_SendData(USART2, buf[i]);
|
||||||
#elif(DEBUG_UART == DEBUG_UART3)
|
#elif(DEBUG_UART == DEBUG_UART3)
|
||||||
while(USART_GetFlagStatus(USART3, USART_FLAG_TC) == RESET);
|
while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
|
||||||
USART_SendData(USART3, *buf++);
|
USART_SendData(USART3, buf[i]);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
ENTRY( _start )
|
ENTRY( _start )
|
||||||
|
|
||||||
|
/* Configure heap and stack space reserved for application.
|
||||||
|
* Too low may cause standard library failed,
|
||||||
|
* too high may cause SRAM overflow.
|
||||||
|
* Collision may occur with heap when stack gets too deep.
|
||||||
|
*/
|
||||||
__stack_size = 2048;
|
__stack_size = 2048;
|
||||||
|
__heap_size = 2048;
|
||||||
PROVIDE( _stack_size = __stack_size );
|
|
||||||
|
|
||||||
|
|
||||||
MEMORY
|
MEMORY
|
||||||
{
|
{
|
||||||
|
@ -150,27 +153,25 @@ SECTIONS
|
||||||
*(.gnu.linkonce.b.*)
|
*(.gnu.linkonce.b.*)
|
||||||
*(COMMON*)
|
*(COMMON*)
|
||||||
. = ALIGN(4);
|
. = ALIGN(4);
|
||||||
PROVIDE( _ebss = .);
|
PROVIDE(_ebss = .);
|
||||||
} >RAM
|
} >RAM
|
||||||
|
|
||||||
PROVIDE( _end = _ebss);
|
.heap_stack :
|
||||||
PROVIDE( end = . );
|
|
||||||
|
|
||||||
.heap :
|
|
||||||
{
|
{
|
||||||
|
. = ALIGN(8);
|
||||||
|
PROVIDE(_end = .);
|
||||||
|
PROVIDE(end = . );
|
||||||
|
|
||||||
}
|
. = . + __heap_size;
|
||||||
|
. = ALIGN(8);
|
||||||
|
PROVIDE(_heap_end = .);
|
||||||
|
|
||||||
.stack ORIGIN(RAM) + LENGTH(RAM) - __stack_size :
|
|
||||||
{
|
|
||||||
PROVIDE( _heap_end = . );
|
|
||||||
. = ALIGN(4);
|
|
||||||
PROVIDE(_susrstack = . );
|
|
||||||
. = . + __stack_size;
|
. = . + __stack_size;
|
||||||
PROVIDE( _eusrstack = .);
|
. = ALIGN(8);
|
||||||
} >RAM
|
} >RAM
|
||||||
|
|
||||||
|
|
||||||
|
/* Place initial SP to the end of SRAM */
|
||||||
|
__stack_top = ORIGIN(RAM) + LENGTH(RAM);
|
||||||
|
PROVIDE(_eusrstack = __stack_top);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
#ifndef BOARD_H
|
#ifndef BOARD_H
|
||||||
#define BOARD_H
|
#define BOARD_H
|
||||||
|
|
||||||
|
void BOARD_IOMUX_Init(void);
|
||||||
|
void BOARD_Peripheral_Init(void);
|
||||||
|
void BOARD_SystemClock_Config(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
29
src/board.c
29
src/board.c
|
@ -1,5 +1,30 @@
|
||||||
#include "ch32v30x_conf.h"
|
#include "ch32v30x_conf.h"
|
||||||
|
|
||||||
void BOARD_LED_Init(void) {
|
/**
|
||||||
|
* @brief Initialize IOMUX.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void BOARD_IOMUX_Init(void) {
|
||||||
|
/* The official devkit (CH32V307V-R1-1v0)
|
||||||
|
* does not have any LEDs directly connected to the MCU,
|
||||||
|
* and does not have any buttons directly connected to the MCU either...
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Initialize on-board peripherals.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void BOARD_Peripheral_Init(void) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Configure system clock,
|
||||||
|
* If you are not satisfied with the default options.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void BOARD_SystemClock_Config(void) {
|
||||||
|
|
||||||
|
// After you are done playing with RCC...
|
||||||
|
SystemCoreClockUpdate();
|
||||||
}
|
}
|
16
src/main.c
16
src/main.c
|
@ -4,13 +4,25 @@
|
||||||
|
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
int main(void) {
|
#include "board.h"
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
/* Initialize board components. */
|
||||||
|
BOARD_SystemClock_Config();
|
||||||
|
BOARD_IOMUX_Init();
|
||||||
|
BOARD_Peripheral_Init();
|
||||||
|
|
||||||
|
|
||||||
|
/* Initialize UART for libc function calls. */
|
||||||
USART_Printf_Init(115200);
|
USART_Printf_Init(115200);
|
||||||
|
Delay_Init(); /* Silly function, will be replaced next time. */
|
||||||
|
|
||||||
printf("Hello world?\r\n");
|
printf("Hello world?\r\n");
|
||||||
|
|
||||||
|
uint32_t i = 0;
|
||||||
|
|
||||||
for(;;) {
|
for(;;) {
|
||||||
//
|
Delay_Ms(500);
|
||||||
|
printf("Dead loop @%lu\r\n", i++);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue