Fixed memory usage report, check TXE instead of TC.

This commit is contained in:
imi415 2022-03-29 22:43:47 +08:00
parent 83a9bbbc96
commit c7ba52be62
Signed by untrusted user: imi415
GPG Key ID: 885EC2B5A8A6F8A7
5 changed files with 71 additions and 29 deletions

View File

@ -155,14 +155,14 @@ __attribute__((used)) int _write(int fd, char *buf, int size)
for(i = 0; i < size; i++)
{
#if(DEBUG_UART == DEBUG_UART1)
while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
USART_SendData(USART1, *buf++);
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
USART_SendData(USART1, buf[i]);
#elif(DEBUG_UART == DEBUG_UART2)
while(USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET);
USART_SendData(USART2, *buf++);
while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
USART_SendData(USART2, buf[i]);
#elif(DEBUG_UART == DEBUG_UART3)
while(USART_GetFlagStatus(USART3, USART_FLAG_TC) == RESET);
USART_SendData(USART3, *buf++);
while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
USART_SendData(USART3, buf[i]);
#endif
}

View File

@ -1,9 +1,12 @@
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;
PROVIDE( _stack_size = __stack_size );
__heap_size = 2048;
MEMORY
{
@ -150,27 +153,25 @@ SECTIONS
*(.gnu.linkonce.b.*)
*(COMMON*)
. = ALIGN(4);
PROVIDE( _ebss = .);
PROVIDE(_ebss = .);
} >RAM
PROVIDE( _end = _ebss);
PROVIDE( end = . );
.heap :
.heap_stack :
{
. = 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;
PROVIDE( _eusrstack = .);
} >RAM
. = ALIGN(8);
} >RAM
/* Place initial SP to the end of SRAM */
__stack_top = ORIGIN(RAM) + LENGTH(RAM);
PROVIDE(_eusrstack = __stack_top);
}

View File

@ -1,4 +1,8 @@
#ifndef BOARD_H
#define BOARD_H
void BOARD_IOMUX_Init(void);
void BOARD_Peripheral_Init(void);
void BOARD_SystemClock_Config(void);
#endif

View File

@ -1,5 +1,30 @@
#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();
}

View File

@ -4,13 +4,25 @@
#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);
Delay_Init(); /* Silly function, will be replaced next time. */
printf("Hello world?\r\n");
uint32_t i = 0;
for(;;) {
//
Delay_Ms(500);
printf("Dead loop @%lu\r\n", i++);
}
}