2024-08-21 08:40 PM - edited 2024-08-21 08:41 PM
It seems like a used ram size fit to External SDRAM in STM32H757i- EVAL Board.
However, I can see the error when doing analyze.
Also, I cannot see any TFLite Micro runtime generated code.
I can see empty function.
I was totally fine with STM32CUBE AI runtime.
2024-08-26 03:17 AM
You have to select the Template code, System performance application or Validation application to have code generated in those sections
2024-08-26 11:39 PM
I selected the Validation application.
I was wondering if TFlite model Used Ram: 1.29MiB, then MCU need x10 size RAM?
It is showing that 1.29 MiB. However, 8 MiB External SDRAM is not enough.
2024-08-27 12:18 AM
with tflite runtime we don't manage automatically the use of external RAM.
That said you can generate the code and modify the linker script to place the activation buffer in external sdram (with of course an impact on the performance)
Regards
2024-08-28 05:32 PM
Thanks for your reply.
Is there any way to make a network_data.bin manually?
I would like to flash the network_data.bin file to external memory using STMCubeProgrammer.
However, STM32CubeMX cannot convert my model to .bin File.
2024-08-29 01:04 AM
I wrote a code to use the external flash and the sdram. However, I failed when doing aiBootstrap
Could you check whether it is right or not
1. External SDRAM (linker script, code)
MEMORY
{
RAM_D1 (xrw) : ORIGIN = 0x24000000, LENGTH = 512K
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K /* Memory is divided. Actual start is 0x08000000 and actual length is 2048K */
DTCMRAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
RAM_D2 (xrw) : ORIGIN = 0x30000000, LENGTH = 288K
RAM_D3 (xrw) : ORIGIN = 0x38000000, LENGTH = 64K
ITCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 64Kf
SDRAM (xrw) : ORIGIN = 0xD0000000, LENGTH = 8M
}
.sdram_section (NOLOAD):
{
. = ALIGN(4);
*(.Tensor_Arena)
*(.Tensor_Arena*)
. = ALIGN(4);
} >SDRAM
#if defined(__ICCARM__)
#pragma location = "Tensor_Arena"
#pragma data_alignment=4
#elif defined(__CC_ARM)
__attribute__((section(".Tensor_Arena"), zero_init))
__attribute__ ((aligned (4)))
#elif defined(__GNUC__)
__attribute__((section(".Tensor_Arena")))
__attribute__ ((aligned (4)))
#else
#error Unknown compiler
#endif
MEM_ALIGNED(4)
static uint8_t tensor_arena[TFLM_NETWORK_TENSOR_AREA_SIZE+32];
2.I programmed network_data.bin(tflite) External Flash (0x90000000)
3. set memory address
#include <stdint.h>
#include <network_tflite_data.h>
#ifdef __cplusplus
extern "C"
{
#endif
#ifdef __has_attribute
#define HAVE_ATTRIBUTE(x) __has_attribute(x)
#else
#define HAVE_ATTRIBUTE(x) 0
#endif
#if HAVE_ATTRIBUTE(aligned) || (defined(__GNUC__) && !defined(__clang__))
#define DATA_ALIGN_ATTRIBUTE __attribute__((aligned(4)))
#else
#define DATA_ALIGN_ATTRIBUTE
#endif
const uint8_t * g_tflm_network_model_data DATA_ALIGN_ATTRIBUTE = (uint8_t *)0x90000000;
const int g_tflm_network_model_data_len = 4065740;
#ifdef __cplusplus
}
#endif
4. It is failed when create tensor.
static int aiBootstrap(struct tflm_context *ctx)
{
TfLiteStatus res;
struct tflm_c_version ver;
/* Creating an instance of the network ------------------------- */
LC_PRINT("\r\nInstancing the network (TFLM)..\r\n");
/* TFLm runtime expects that the tensor arena is aligned on 16-bytes */
uint32_t uaddr = (uint32_t)tensor_arena;
uaddr = (uaddr + (16 - 1)) & (uint32_t)(-16); // Round up to 16-byte boundary
MON_ALLOC_RESET();
MON_ALLOC_ENABLE();
//res is not okay.
res = tflm_c_create(g_tflm_network_model_data, (uint8_t*)uaddr,
TFLM_NETWORK_TENSOR_AREA_SIZE, &ctx->hdl);
MON_ALLOC_DISABLE();
if (res != kTfLiteOk) {
ctx->hdl = 0;
ctx->error = -1;
return -1;
}
}