Use newlib heap and printf.

This commit is contained in:
imi415 2022-05-29 22:02:23 +08:00
parent 036c6ed031
commit 11b38ee429
Signed by: imi415
GPG Key ID: 885EC2B5A8A6F8A7
9 changed files with 65 additions and 29 deletions

View File

@ -53,7 +53,6 @@ set(TARGET_SOURCES
"SDK/devices/MK60D10/system_MK60D10.c"
"SDK/devices/MK60D10/utilities/fsl_debug_console.c"
"SDK/devices/MK60D10/utilities/fsl_notifier.c"
"SDK/devices/MK60D10/utilities/fsl_sbrk.c"
"SDK/devices/MK60D10/gcc/startup_MK60D10.S"
"SDK/devices/MK60D10/system_MK60D10.c"
"board/board.c"
@ -74,6 +73,8 @@ set(TARGET_SOURCES
set(TARGET_C_DEFINES
"CPU_MK60DN512VLQ10"
"__STARTUP_CLEAR_BSS"
"USE_RTOS=1"
"FSL_RTOS_FREE_RTOS"
)
set(TARGET_C_INCLUDES

View File

@ -49,7 +49,7 @@
/* Entry Point */
ENTRY(Reset_Handler)
HEAP_SIZE = DEFINED(__heap_size__) ? __heap_size__ : 0x0400;
HEAP_SIZE = DEFINED(__heap_size__) ? __heap_size__ : 0x1000;
STACK_SIZE = DEFINED(__stack_size__) ? __stack_size__ : 0x0400;
M_VECTOR_RAM_SIZE = DEFINED(__ram_vector_table__) ? 0x0400 : 0x0;

View File

@ -12,7 +12,7 @@
#define configUSE_TICKLESS_IDLE 0
#define configCPU_CLOCK_HZ (SystemCoreClock)
#define configTICK_RATE_HZ 1000
#define configMAX_PRIORITIES 56
#define configMAX_PRIORITIES 64
#define configMINIMAL_STACK_SIZE 128
#define configMAX_TASK_NAME_LEN 16
#define configUSE_16_BIT_TICKS 0
@ -26,7 +26,7 @@
#define configQUEUE_REGISTRY_SIZE 10
#define configUSE_QUEUE_SETS 0
#define configUSE_TIME_SLICING 0
#define configUSE_NEWLIB_REENTRANT 0
#define configUSE_NEWLIB_REENTRANT 1
#define configENABLE_BACKWARD_COMPATIBILITY 0
#define configNUM_THREAD_LOCAL_STORAGE_POINTERS 5
#define configSTACK_DEPTH_TYPE uint16_t
@ -57,7 +57,7 @@
/* Software timer related definitions. */
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY 3
#define configTIMER_TASK_PRIORITY 54
#define configTIMER_QUEUE_LENGTH 10
#define configTIMER_TASK_STACK_DEPTH configMINIMAL_STACK_SIZE

View File

@ -90,7 +90,7 @@
#define TCPIP_DEBUG LWIP_DBG_OFF
#define NETIF_DEBUG LWIP_DBG_OFF
#define SOCKETS_DEBUG LWIP_DBG_OFF
#define DNS_DEBUG LWIP_DBG_ON
#define DNS_DEBUG LWIP_DBG_OFF
#define AUTOIP_DEBUG LWIP_DBG_OFF
#define DHCP_DEBUG LWIP_DBG_ON
#define IP_DEBUG LWIP_DBG_OFF
@ -328,6 +328,7 @@ void lwip_platform_assert(const char *msg, int line, const char *file);
#endif
/* FreeRTOS related settings */
#define TCPIP_THREAD_PRIO 47
#define TCPIP_MBOX_SIZE 32
#define TCPIP_THREAD_STACKSIZE 1024

View File

@ -364,7 +364,7 @@ static void enet_init(struct netif *netif, struct ethernetif *ethernetif)
ENET_Init(ethernetif->base, &ethernetif->handle, &config, &buffCfg, netif->hwaddr, sysClock);
#if USE_RTOS && defined(FSL_RTOS_FREE_RTOS)
xTaskCreate(enet_rx_task, "enet_rx_task", 1024, netif, 2, &ethernetif->rxTaskHandle);
xTaskCreate(enet_rx_task, "enet_rx_task", 1024, netif, 48, &ethernetif->rxTaskHandle);
ENET_SetCallback(&ethernetif->handle, ethernet_callback, netif);
#endif

View File

@ -1,3 +1,5 @@
#include <stdio.h>
/* FreeRTOS */
#include "FreeRTOS.h"
#include "task.h"
@ -21,7 +23,7 @@
#define NTP_POOL_ADDR "cn.pool.ntp.org"
#define NETIF_HOSTNAME "k60_server"
static char *s_netif_hostname = NETIF_HOSTNAME;
static char *s_netif_hostname = NETIF_HOSTNAME;
static struct netif fsl_netif0;
/* Report state => string */
@ -43,25 +45,25 @@ static const char *report_type_str[] = {
static void ip_stack_lwiperf_report(void *arg, enum lwiperf_report_type report_type, const ip_addr_t *local_addr,
u16_t local_port, const ip_addr_t *remote_addr, u16_t remote_port,
u32_t bytes_transferred, u32_t ms_duration, u32_t bandwidth_kbitpsec) {
PRINTF("-------------------------------------------------\r\n");
printf("-------------------------------------------------\r\n");
if ((report_type < sizeof(report_type_str)) && local_addr && remote_addr) {
PRINTF(" %s \r\n", report_type_str[report_type]);
PRINTF(" Local address : %u.%u.%u.%u ", ((u8_t *)local_addr)[0], ((u8_t *)local_addr)[1],
printf(" %s \r\n", report_type_str[report_type]);
printf(" Local address : %u.%u.%u.%u ", ((u8_t *)local_addr)[0], ((u8_t *)local_addr)[1],
((u8_t *)local_addr)[2], ((u8_t *)local_addr)[3]);
PRINTF(" Port %d \r\n", local_port);
PRINTF(" Remote address : %u.%u.%u.%u ", ((u8_t *)remote_addr)[0], ((u8_t *)remote_addr)[1],
printf(" Port %d \r\n", local_port);
printf(" Remote address : %u.%u.%u.%u ", ((u8_t *)remote_addr)[0], ((u8_t *)remote_addr)[1],
((u8_t *)remote_addr)[2], ((u8_t *)remote_addr)[3]);
PRINTF(" Port %d \r\n", remote_port);
PRINTF(" Bytes Transferred %d \r\n", bytes_transferred);
PRINTF(" Duration (ms) %d \r\n", ms_duration);
PRINTF(" Bandwidth (kbitpsec) %d \r\n", bandwidth_kbitpsec);
printf(" Port %d \r\n", remote_port);
printf(" Bytes Transferred %ld \r\n", bytes_transferred);
printf(" Duration (ms) %ld \r\n", ms_duration);
printf(" Bandwidth (kbitpsec) %ld \r\n", bandwidth_kbitpsec);
} else {
PRINTF(" IPERF Report error\r\n");
printf(" IPERF Report error\r\n");
}
}
static void ip_stack_sntp_address_found(const char *name, const ip_addr_t *ipaddr, void *callback_arg) {
PRINTF("Resolved IP: %s\r\n", ipaddr_ntoa(ipaddr));
printf("Resolved IP: %s\r\n", ipaddr_ntoa(ipaddr));
sntp_setserver(0, ipaddr);
sntp_init();
}
@ -77,7 +79,7 @@ static void ip_stack_enable_sntp(void) {
sntp_setserver(0, &ntp_addr);
sntp_init();
} else {
PRINTF("No cached DNS result found, wait for callback.\r\n");
printf("No cached DNS result found, wait for callback.\r\n");
}
}
@ -103,7 +105,7 @@ void ip_stack_setup(void) {
vTaskDelay(pdMS_TO_TICKS(500));
}
PRINTF("IP Address: %s\r\n", ipaddr_ntoa(&fsl_netif0.ip_addr));
printf("IP Address: %s\r\n", ipaddr_ntoa(&fsl_netif0.ip_addr));
ip_stack_enable_sntp();

View File

@ -1,3 +1,4 @@
#include <stdio.h>
#include <time.h>
/* HW Related */
@ -49,7 +50,7 @@ static void vTaskHello(void *pvParameters) {
t = time(NULL);
cur_tm = localtime(&t);
PRINTF("Current time: %04d-%02d-%02d %02d:%02d:%02d\r\n", cur_tm->tm_year + 1900, cur_tm->tm_mon + 1,
printf("Current time: %04d-%02d-%02d %02d:%02d:%02d\r\n", cur_tm->tm_year + 1900, cur_tm->tm_mon + 1,
cur_tm->tm_mday, cur_tm->tm_hour, cur_tm->tm_min, cur_tm->tm_sec);
}
}

View File

@ -1,5 +1,8 @@
#include <sys/time.h>
#include <sys/errno.h>
#include "FreeRTOS.h"
#include "task.h"
#include "MK60D10.h"
@ -9,3 +12,31 @@ int _gettimeofday(struct timeval *restrict tp, void *restrict tzp) {
return 0;
}
caddr_t _sbrk(int incr)
{
extern char end __asm("end");
extern char heap_limit __asm("__HeapLimit");
static char *heap_end;
char *prev_heap_end;
taskENTER_CRITICAL();
if (heap_end == NULL)
heap_end = &end;
prev_heap_end = heap_end;
if (heap_end + incr > &heap_limit)
{
errno = ENOMEM;
taskEXIT_CRITICAL();
return (caddr_t)-1;
}
heap_end += incr;
taskEXIT_CRITICAL();
return (caddr_t)prev_heap_end;
}

View File

@ -1,10 +1,10 @@
#include <stdio.h>
#include "board.h"
#include "clock_config.h"
#include "peripherals.h"
#include "pin_mux.h"
#include "fsl_debug_console.h"
#define SRAM_BASE (0x60000000)
#define SRAM_SIZE (512 * 1024)
@ -95,25 +95,25 @@ void print_hardware(void) {
break;
}
PRINTF("This is %s with Rev. (Mask Set): %s, %s pins.\r\n", family_str, rev_str, pin_str);
printf("This is %s with Rev. (Mask Set): %s, %s pins.\r\n", family_str, rev_str, pin_str);
}
void sram_test(void) {
PRINTF("SRAM write... ");
printf("SRAM write... ");
for(uint32_t i = SRAM_BASE; i < SRAM_BASE + SRAM_SIZE; i += 4) {
*(volatile uint32_t *)i = i;
}
PRINTF("done, SRAM read... ");
printf("done, SRAM read... ");
for(uint32_t i = SRAM_BASE; i < SRAM_BASE + SRAM_SIZE; i += 4) {
if(*(volatile uint32_t *)i != i) {
PRINTF("error.\r\n");
printf("error.\r\n");
return;
}
}
PRINTF("done.\r\n");
printf("done.\r\n");
}
int set_rtc_time(int sec) {