diff --git a/builder/family/realtek-ambz2.py b/builder/family/realtek-ambz2.py index 51a0db7..acdb0fc 100644 --- a/builder/family/realtek-ambz2.py +++ b/builder/family/realtek-ambz2.py @@ -92,6 +92,7 @@ queue.AppendPublic( "-Wl,-wrap,memset", # TODO remove this if possible "-Wl,-wrap,putc", + # rt_printf wrappers are not here, as they're just changing code using #defines ], ) @@ -104,17 +105,6 @@ queue.AddLibrary( # cmsis "+", "+", - # console - "+", - "+", - "+", - "+", - "+", - "+", - "+", - "+", - "+", - "+", # utilities "+", "+", @@ -147,13 +137,9 @@ queue.AddLibrary( "+", "+", "+", - # TODO remove this - "+", - "+", ], includes=[ "+<$SDK_DIR/project/realtek_amebaz2_v0_example/inc>", - "+", "+", "+", "+", @@ -175,7 +161,6 @@ queue.AddLibrary( "+", "+", "+", - "+", "+", "+", "+", @@ -286,6 +271,7 @@ queue.AddLibrary( # "+", "+", "+", + "-", ], includes=[ "+<.>", diff --git a/cores/realtek-ambz/base/fixups/basic_types.h b/cores/realtek-amb/base/fixups/basic_types.h similarity index 100% rename from cores/realtek-ambz/base/fixups/basic_types.h rename to cores/realtek-amb/base/fixups/basic_types.h diff --git a/cores/realtek-ambz/base/fixups/machine/endian.h b/cores/realtek-amb/base/fixups/machine/endian.h similarity index 100% rename from cores/realtek-ambz/base/fixups/machine/endian.h rename to cores/realtek-amb/base/fixups/machine/endian.h diff --git a/cores/realtek-ambz/base/fixups/platform/platform_stdlib.h b/cores/realtek-amb/base/fixups/platform/platform_stdlib.h similarity index 100% rename from cores/realtek-ambz/base/fixups/platform/platform_stdlib.h rename to cores/realtek-amb/base/fixups/platform/platform_stdlib.h diff --git a/cores/realtek-ambz/base/fixups/platform_stdlib.h b/cores/realtek-amb/base/fixups/platform_stdlib.h similarity index 82% rename from cores/realtek-ambz/base/fixups/platform_stdlib.h rename to cores/realtek-amb/base/fixups/platform_stdlib.h index ebe54e1..1d7af6b 100644 --- a/cores/realtek-ambz/base/fixups/platform_stdlib.h +++ b/cores/realtek-amb/base/fixups/platform_stdlib.h @@ -16,7 +16,9 @@ #include #include "basic_types.h" // fixup: replaces typedef boolean for Arduino compatibility -#include "memproc.h" // fixup: redirects to stdlib -#include "strproc.h" // fixup: redirects to stdlib +#ifdef LT_RTL8710B +#include "memproc.h" // fixup: redirects to stdlib +#endif +#include "strproc.h" // fixup: redirects to stdlib #include "diag.h" diff --git a/cores/realtek-ambz/base/fixups/section_config.h b/cores/realtek-amb/base/fixups/section_config.h similarity index 100% rename from cores/realtek-ambz/base/fixups/section_config.h rename to cores/realtek-amb/base/fixups/section_config.h diff --git a/cores/realtek-amb/base/port/fal_flash_ambz_port.c b/cores/realtek-amb/base/port/fal_flash_ambz_port.c index cea509b..8eb033d 100644 --- a/cores/realtek-amb/base/port/fal_flash_ambz_port.c +++ b/cores/realtek-amb/base/port/fal_flash_ambz_port.c @@ -7,24 +7,26 @@ #define FLASH_ERASE_MIN_SIZE (4 * 1024) +static flash_t flash_obj; + static int init() { - flash_get_status(NULL); + flash_get_status(&flash_obj); return 0; } static int read(long offset, uint8_t *buf, size_t size) { - return size * flash_stream_read(NULL, offset, size, buf); + return size * flash_stream_read(&flash_obj, offset, size, buf); } static int write(long offset, const uint8_t *buf, size_t size) { - return size * flash_stream_write(NULL, offset, size, (uint8_t *)buf); + return size * flash_stream_write(&flash_obj, offset, size, (uint8_t *)buf); } static int erase(long offset, size_t size) { offset &= ~(FLASH_ERASE_MIN_SIZE - 1); size = ((size - 1) / FLASH_ERASE_MIN_SIZE) + 1; for (uint16_t i = 0; i < size; i++) { - flash_erase_sector(NULL, offset + i * FLASH_ERASE_MIN_SIZE); + flash_erase_sector(&flash_obj, offset + i * FLASH_ERASE_MIN_SIZE); } return size * FLASH_ERASE_MIN_SIZE; } diff --git a/cores/realtek-ambz2/base/config/platform_conf.h b/cores/realtek-ambz2/base/config/platform_conf.h new file mode 100644 index 0000000..4b5d67d --- /dev/null +++ b/cores/realtek-ambz2/base/config/platform_conf.h @@ -0,0 +1,19 @@ +/* Copyright (c) Kuba Szczodrzyński 2023-05-23. */ + +#pragma once + +#include_next "platform_conf.h" + +#undef CONFIG_DEBUG_LOG +#undef CONFIG_DEBUG_ERROR +#undef CONFIG_DEBUG_WARN +#undef CONFIG_DEBUG_INFO +#define CONFIG_DEBUG_LOG 0 +#define CONFIG_DEBUG_ERROR 0 +#define CONFIG_DEBUG_WARN 0 +#define CONFIG_DEBUG_INFO 0 + +// diag.h doesn't define this if CONFIG_DEBUG_LOG is 0 +#define DBG_SCE_ERR(...) +#define DBG_SCE_WARN(...) +#define DBG_SCE_INFO(...) diff --git a/cores/realtek-ambz2/base/fixups/cmd_shell.c b/cores/realtek-ambz2/base/fixups/cmd_shell.c index d90ccab..622802c 100644 --- a/cores/realtek-ambz2/base/fixups/cmd_shell.c +++ b/cores/realtek-ambz2/base/fixups/cmd_shell.c @@ -1,3 +1,7 @@ /* Copyright (c) Kuba Szczodrzyński 2023-04-12. */ -void shell_cmd_init() {} +extern void lt_main(); + +void shell_cmd_init() { + lt_main(); +} diff --git a/cores/realtek-ambz2/base/fixups/cmsis.h b/cores/realtek-ambz2/base/fixups/cmsis.h new file mode 100644 index 0000000..1124176 --- /dev/null +++ b/cores/realtek-ambz2/base/fixups/cmsis.h @@ -0,0 +1,10 @@ +/* Copyright (c) Kuba Szczodrzyński 2023-05-23. */ + +// use platform_conf.h from realtek-ambz2/base/config +#include +// use basic_types.h from realtek-amb/base/fixups +#include +// use basic_types.h from realtek-ambz2/base/fixups +#include "diag.h" + +#include_next "cmsis.h" diff --git a/cores/realtek-ambz2/base/fixups/diag.h b/cores/realtek-ambz2/base/fixups/diag.h new file mode 100644 index 0000000..96e30da --- /dev/null +++ b/cores/realtek-ambz2/base/fixups/diag.h @@ -0,0 +1,19 @@ +/* Copyright (c) Kuba Szczodrzyński 2023-05-23. */ + +// remove component/soc/realtek/8710c/app/rtl_printf/include/rt_printf.h +// replace with #defines below +#ifndef _RT_PRINTF__H +#define _RT_PRINTF__H +#endif + +#undef log_printf +#include_next "diag.h" +#undef log_printf + +#define rt_printf(...) __wrap_rt_printf(__VA_ARGS__) +#define rt_printfl(...) __wrap_rt_printf(__VA_ARGS__) +#define rt_sprintf(...) __wrap_rt_sprintf(__VA_ARGS__) +#define rt_sprintfl(...) __wrap_rt_sprintf(__VA_ARGS__) +#define rt_snprintf(...) __wrap_rt_snprintf(__VA_ARGS__) +#define rt_snprintfl(...) __wrap_rt_snprintf(__VA_ARGS__) +#define rt_log_printf(...) __wrap_rt_log_printf(__VA_ARGS__) diff --git a/cores/realtek-ambz2/base/lt_api.c b/cores/realtek-ambz2/base/lt_api.c new file mode 100644 index 0000000..53b838c --- /dev/null +++ b/cores/realtek-ambz2/base/lt_api.c @@ -0,0 +1,19 @@ +/* Copyright (c) Kuba Szczodrzyński 2023-05-22. */ + +#include +#include + +extern uint8_t lt_uart_port; + +void lt_init_family() { + // make the SDK less verbose by default + ConfigDebugErr = 0; + ConfigDebugWarn = 0; + ConfigDebugInfo = 0; + lt_uart_port = LT_UART_DEFAULT_PORT; +} + +lt_reboot_reason_t lt_get_reboot_reason() { + // TODO + return REBOOT_REASON_UNKNOWN; +} diff --git a/cores/realtek-ambz2/base/port/printf.c b/cores/realtek-ambz2/base/port/printf.c index 74b5200..1ec6a0b 100644 --- a/cores/realtek-ambz2/base/port/printf.c +++ b/cores/realtek-ambz2/base/port/printf.c @@ -19,20 +19,11 @@ void putchar_(char c) { } void putchar_p(char c, unsigned long port) { - // while (UART_Writable(uart_dev[port]) == 0) {} + while (uart_dev[port]->lsr_b.txfifo_empty == 0) {} uart_dev[port]->thr = c; } -WRAP_PRINTF(rtl_printf); -WRAP_SPRINTF(rtl_sprintf); -WRAP_SNPRINTF(rtl_snprintf); -WRAP_VSNPRINTF(rtl_vsnprintf); -WRAP_VSNPRINTF(rtl_vsnprintf_r); -WRAP_VPRINTF(rtl_vprintf); -WRAP_PRINTF(DiagPrintf); -WRAP_SPRINTF(DiagSPrintf); -WRAP_SNPRINTF(DiagSnPrintf); -WRAP_PRINTF(prvDiagPrintf); -WRAP_SPRINTF(prvDiagSPrintf); -WRAP_VSPRINTF(VSprintf); -WRAP_PRINTF(LOG_PRINTF); +WRAP_PRINTF(rt_printf); +WRAP_SPRINTF(rt_sprintf); +WRAP_SNPRINTF(rt_snprintf); +WRAP_PRINTF(rt_log_printf); diff --git a/cores/realtek-ambz2/base/port/printf_port.h b/cores/realtek-ambz2/base/port/printf_port.h index 74d770e..4c65b6c 100644 --- a/cores/realtek-ambz2/base/port/printf_port.h +++ b/cores/realtek-ambz2/base/port/printf_port.h @@ -8,10 +8,8 @@ extern "C" { #endif // __cplusplus -WRAP_DISABLE_DEF(rtl_printf); -WRAP_DISABLE_DEF(DiagPrintf); -WRAP_DISABLE_DEF(prvDiagPrintf); -WRAP_DISABLE_DEF(LOG_PRINTF); +WRAP_DISABLE_DEF(rt_printf); +WRAP_DISABLE_DEF(rt_log_printf); #ifdef __cplusplus } // extern "C"