Browse Source

Add extmem_smalloc_pool for PSRAM on Teensy 4.1

teensy4-core
PaulStoffregen 4 years ago
parent
commit
e207bcff0a
2 changed files with 15 additions and 1 deletions
  1. +4
    -0
      teensy4/smalloc.h
  2. +11
    -1
      teensy4/startup.c

+ 4
- 0
teensy4/smalloc.h View File

/* a default one which is initialised with sm_set_default_pool. */ /* a default one which is initialised with sm_set_default_pool. */
extern struct smalloc_pool smalloc_curr_pool; extern struct smalloc_pool smalloc_curr_pool;


#ifdef ARDUINO_TEENSY41
extern struct smalloc_pool extmem_smalloc_pool;
#endif

/* undefined behavior handler is called on typical malloc UB situations */ /* undefined behavior handler is called on typical malloc UB situations */
typedef void (*smalloc_ub_handler)(struct smalloc_pool *, const void *); typedef void (*smalloc_ub_handler)(struct smalloc_pool *, const void *);



+ 11
- 1
teensy4/startup.c View File

#include "wiring.h" #include "wiring.h"
#include "usb_dev.h" #include "usb_dev.h"
#include "avr/pgmspace.h" #include "avr/pgmspace.h"
#include "smalloc.h"


#include "debug/printf.h" #include "debug/printf.h"


extern unsigned long _ebss; extern unsigned long _ebss;
extern unsigned long _flexram_bank_config; extern unsigned long _flexram_bank_config;
extern unsigned long _estack; extern unsigned long _estack;
extern unsigned long _extram_start;
extern unsigned long _extram_end;


__attribute__ ((used, aligned(1024))) __attribute__ ((used, aligned(1024)))
void (* _VectorsRam[NVIC_NUM_INTERRUPTS+16])(void); void (* _VectorsRam[NVIC_NUM_INTERRUPTS+16])(void);
extern void __libc_init_array(void); // C++ standard library extern void __libc_init_array(void); // C++ standard library


uint8_t external_psram_size = 0; uint8_t external_psram_size = 0;
#ifdef ARDUINO_TEENSY41
struct smalloc_pool extmem_smalloc_pool;
#endif


extern int main (void); extern int main (void);
void startup_default_early_hook(void) {} void startup_default_early_hook(void) {}
} }
// TODO: zero uninitialized EXTMEM variables // TODO: zero uninitialized EXTMEM variables
// TODO: copy from flash to initialize EXTMEM variables // TODO: copy from flash to initialize EXTMEM variables
// TODO: set up for malloc_extmem()
sm_set_pool(&extmem_smalloc_pool, &_extram_end,
external_psram_size * 0x100000 -
((uint32_t)&_extram_end - (uint32_t)&_extram_start),
1, NULL);
} else { } else {
// No PSRAM // No PSRAM
memset(&extmem_smalloc_pool, 0, sizeof(extmem_smalloc_pool));
} }
} }



Loading…
Cancel
Save