Merge pull request #579 from kwagyeman/kwabena/sdram_support_2

Fix SDRAM support
This commit is contained in:
Ibrahim Abd Elkader 2019-09-04 21:52:34 +02:00 committed by GitHub
commit 1a5d463324
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 117 additions and 25 deletions

View File

@ -111,6 +111,9 @@
// Enable find_apriltags() (64 KB) // Enable find_apriltags() (64 KB)
//#define IMLIB_ENABLE_APRILTAGS //#define IMLIB_ENABLE_APRILTAGS
// Enable high res find_apriltags() - uses more RAM
// #define IMLIB_ENABLE_HIGH_RES_APRILTAGS
// Enable find_datamatrices() (26 KB) // Enable find_datamatrices() (26 KB)
//#define IMLIB_ENABLE_DATAMATRICES //#define IMLIB_ENABLE_DATAMATRICES

View File

@ -48,6 +48,9 @@
#define JPEG_QUALITY_LOW 35 #define JPEG_QUALITY_LOW 35
#define JPEG_QUALITY_HIGH 60 #define JPEG_QUALITY_HIGH 60
// FB Heap Block Size
#define OMV_UMM_BLOCK_SIZE 16
// Linker script constants (see the linker script template stm32fxxx.ld.S). // Linker script constants (see the linker script template stm32fxxx.ld.S).
// Note: fb_alloc is a stack-based, dynamically allocated memory on FB. // Note: fb_alloc is a stack-based, dynamically allocated memory on FB.
// The maximum available fb_alloc memory = FB_ALLOC_SIZE + FB_SIZE - (w*h*bpp). // The maximum available fb_alloc memory = FB_ALLOC_SIZE + FB_SIZE - (w*h*bpp).

View File

@ -114,6 +114,9 @@
// Enable find_apriltags() (64 KB) // Enable find_apriltags() (64 KB)
#define IMLIB_ENABLE_APRILTAGS #define IMLIB_ENABLE_APRILTAGS
// Enable high res find_apriltags() - uses more RAM
// #define IMLIB_ENABLE_HIGH_RES_APRILTAGS
// Enable find_datamatrices() (26 KB) // Enable find_datamatrices() (26 KB)
#define IMLIB_ENABLE_DATAMATRICES #define IMLIB_ENABLE_DATAMATRICES

View File

@ -48,6 +48,9 @@
#define JPEG_QUALITY_LOW 35 #define JPEG_QUALITY_LOW 35
#define JPEG_QUALITY_HIGH 60 #define JPEG_QUALITY_HIGH 60
// FB Heap Block Size
#define OMV_UMM_BLOCK_SIZE 16
// Linker script constants (see the linker script template stm32fxxx.ld.S). // Linker script constants (see the linker script template stm32fxxx.ld.S).
// Note: fb_alloc is a stack-based, dynamically allocated memory on FB. // Note: fb_alloc is a stack-based, dynamically allocated memory on FB.
// The maximum available fb_alloc memory = FB_ALLOC_SIZE + FB_SIZE - (w*h*bpp). // The maximum available fb_alloc memory = FB_ALLOC_SIZE + FB_SIZE - (w*h*bpp).

View File

@ -114,6 +114,9 @@
// Enable find_apriltags() (64 KB) // Enable find_apriltags() (64 KB)
#define IMLIB_ENABLE_APRILTAGS #define IMLIB_ENABLE_APRILTAGS
// Enable high res find_apriltags() - uses more RAM
// #define IMLIB_ENABLE_HIGH_RES_APRILTAGS
// Enable find_datamatrices() (26 KB) // Enable find_datamatrices() (26 KB)
#define IMLIB_ENABLE_DATAMATRICES #define IMLIB_ENABLE_DATAMATRICES

View File

@ -55,6 +55,9 @@
#define JPEG_QUALITY_LOW 50 #define JPEG_QUALITY_LOW 50
#define JPEG_QUALITY_HIGH 90 #define JPEG_QUALITY_HIGH 90
// FB Heap Block Size
#define OMV_UMM_BLOCK_SIZE 16
// Linker script constants (see the linker script template stm32fxxx.ld.S). // Linker script constants (see the linker script template stm32fxxx.ld.S).
// Note: fb_alloc is a stack-based, dynamically allocated memory on FB. // Note: fb_alloc is a stack-based, dynamically allocated memory on FB.
// The maximum available fb_alloc memory = FB_ALLOC_SIZE + FB_SIZE - (w*h*bpp). // The maximum available fb_alloc memory = FB_ALLOC_SIZE + FB_SIZE - (w*h*bpp).

View File

@ -114,6 +114,9 @@
// Enable find_apriltags() (64 KB) // Enable find_apriltags() (64 KB)
#define IMLIB_ENABLE_APRILTAGS #define IMLIB_ENABLE_APRILTAGS
// Enable high res find_apriltags() - uses more RAM
#define IMLIB_ENABLE_HIGH_RES_APRILTAGS
// Enable find_datamatrices() (26 KB) // Enable find_datamatrices() (26 KB)
#define IMLIB_ENABLE_DATAMATRICES #define IMLIB_ENABLE_DATAMATRICES

View File

@ -10,7 +10,7 @@
#define __OMV_BOARDCONFIG_H__ #define __OMV_BOARDCONFIG_H__
// Architecture info // Architecture info
#define OMV_ARCH_STR "OMV4R H7 16384 SDRAM" // 33 chars max #define OMV_ARCH_STR "OMV4R H7 32768 SDRAM" // 33 chars max
#define OMV_BOARD_TYPE "H7" #define OMV_BOARD_TYPE "H7"
#define OMV_UNIQUE_ID_ADDR 0x1FF1E800 #define OMV_UNIQUE_ID_ADDR 0x1FF1E800
@ -38,7 +38,7 @@
#define OMV_BOOTLDR_LED_PORT (GPIOC) #define OMV_BOOTLDR_LED_PORT (GPIOC)
// RAW buffer size // RAW buffer size
#define OMV_RAW_BUF_SIZE (409600) #define OMV_RAW_BUF_SIZE (31457280)
// Enable hardware JPEG // Enable hardware JPEG
#define OMV_HARDWARE_JPEG (1) #define OMV_HARDWARE_JPEG (1)
@ -49,31 +49,34 @@
// If buffer size is bigger than this threshold, the quality is reduced. // If buffer size is bigger than this threshold, the quality is reduced.
// This is only used for JPEG images sent to the IDE not normal compression. // This is only used for JPEG images sent to the IDE not normal compression.
#define JPEG_QUALITY_THRESH (320*240*2) #define JPEG_QUALITY_THRESH (1920*1080*2)
// Low and high JPEG QS. // Low and high JPEG QS.
#define JPEG_QUALITY_LOW 50 #define JPEG_QUALITY_LOW 50
#define JPEG_QUALITY_HIGH 90 #define JPEG_QUALITY_HIGH 90
// FB Heap Block Size
#define OMV_UMM_BLOCK_SIZE 256
// Linker script constants (see the linker script template stm32fxxx.ld.S). // Linker script constants (see the linker script template stm32fxxx.ld.S).
// Note: fb_alloc is a stack-based, dynamically allocated memory on FB. // Note: fb_alloc is a stack-based, dynamically allocated memory on FB.
// The maximum available fb_alloc memory = FB_ALLOC_SIZE + FB_SIZE - (w*h*bpp). // The maximum available fb_alloc memory = FB_ALLOC_SIZE + FB_SIZE - (w*h*bpp).
#define OMV_FFS_MEMORY CCM // Flash filesystem cache memory #define OMV_FFS_MEMORY CCM // Flash filesystem cache memory
#define OMV_MAIN_MEMORY SRAM1 // data, bss, stack and heap #define OMV_MAIN_MEMORY SRAM1 // data, bss, stack and heap
#define OMV_DMA_MEMORY AXI_SRAM // DMA buffers memory. #define OMV_DMA_MEMORY AXI_SRAM // DMA buffers memory.
#define OMV_FB_MEMORY AXI_SRAM // Framebuffer, fb_alloc #define OMV_FB_MEMORY DRAM // Framebuffer, fb_alloc
#define OMV_JPEG_MEMORY SRAM3 // JPEG buffer memory. #define OMV_FB_JPEG_MEMORY // JPEG buffer memory.
#define OMV_VOSPI_MEMORY SRAM4 // VoSPI buffer memory. #define OMV_VOSPI_MEMORY SRAM4 // VoSPI buffer memory.
#define OMV_FB_SIZE (400K) // FB memory: header + VGA/GS image #define OMV_FB_SIZE (30M) // FB memory: header + VGA/GS image
#define OMV_FB_ALLOC_SIZE (96K) // minimum fb alloc size #define OMV_FB_ALLOC_SIZE (1M) // minimum fb alloc size
#define OMV_STACK_SIZE (7K) #define OMV_STACK_SIZE (7K)
#define OMV_HEAP_SIZE (240K) #define OMV_HEAP_SIZE (240K)
#define OMV_LINE_BUF_SIZE (3K) // Image line buffer round(640 * 2BPP * 2 buffers). #define OMV_LINE_BUF_SIZE (11K) // Image line buffer round(2592 * 2BPP * 2 buffers).
#define OMV_MSC_BUF_SIZE (12K) // USB MSC bot data #define OMV_MSC_BUF_SIZE (12K) // USB MSC bot data
#define OMV_VFS_BUF_SIZE (1K) // VFS sturct + FATFS file buffer (624 bytes) #define OMV_VFS_BUF_SIZE (1K) // VFS sturct + FATFS file buffer (624 bytes)
#define OMV_JPEG_BUF_SIZE (32 * 1024) // IDE JPEG buffer (header + data). #define OMV_JPEG_BUF_SIZE (1024*1024) // IDE JPEG buffer (header + data).
#define OMV_BOOT_ORIGIN 0x08000000 #define OMV_BOOT_ORIGIN 0x08000000
#define OMV_BOOT_LENGTH 128K #define OMV_BOOT_LENGTH 128K
@ -89,10 +92,12 @@
#define OMV_SRAM4_LENGTH 64K #define OMV_SRAM4_LENGTH 64K
#define OMV_AXI_SRAM_ORIGIN 0x24000000 #define OMV_AXI_SRAM_ORIGIN 0x24000000
#define OMV_AXI_SRAM_LENGTH 512K #define OMV_AXI_SRAM_LENGTH 512K
#define OMV_DRAM_ORIGIN 0xC0000000
#define OMV_DRAM_LENGTH 32M
// Use the MPU to set an uncacheable memory region. // Use the MPU to set an uncacheable memory region.
#define OMV_DMA_REGION_BASE (OMV_AXI_SRAM_ORIGIN+(496*1024)) #define OMV_DMA_REGION_BASE (OMV_AXI_SRAM_ORIGIN)
#define OMV_DMA_REGION_SIZE MPU_REGION_SIZE_16KB #define OMV_DMA_REGION_SIZE MPU_REGION_SIZE_32KB
/* SCCB/I2C */ /* SCCB/I2C */
#define SCCB_I2C (I2C1) #define SCCB_I2C (I2C1)
@ -233,4 +238,8 @@
#define LEPTON_SPI_MOSI_PORT (GPIOB) #define LEPTON_SPI_MOSI_PORT (GPIOB)
#define LEPTON_SPI_SSEL_PORT (GPIOA) #define LEPTON_SPI_SSEL_PORT (GPIOA)
// Enable additional GPIO banks for DRAM...
#define ENABLE_GPIO_BANK_F
#define ENABLE_GPIO_BANK_G
#endif //__OMV_BOARDCONFIG_H__ #endif //__OMV_BOARDCONFIG_H__

View File

@ -9134,10 +9134,14 @@ struct ufrec
{ {
// the parent of this node. If a node's parent is its own index, // the parent of this node. If a node's parent is its own index,
// then it is a root. // then it is a root.
#ifdef IMLIB_ENABLE_HIGH_RES_APRILTAGS
uint32_t parent;
#else
uint16_t parent; uint16_t parent;
#endif
}; };
static inline unionfind_t *unionfind_create(uint16_t maxid) static inline unionfind_t *unionfind_create(uint32_t maxid)
{ {
unionfind_t *uf = (unionfind_t*) fb_alloc(sizeof(unionfind_t)); unionfind_t *uf = (unionfind_t*) fb_alloc(sizeof(unionfind_t));
uf->data = (struct ufrec*) fb_alloc((maxid+1) * sizeof(struct ufrec)); uf->data = (struct ufrec*) fb_alloc((maxid+1) * sizeof(struct ufrec));
@ -9154,7 +9158,7 @@ static inline void unionfind_destroy()
} }
/* /*
static inline uint16_t unionfind_get_representative(unionfind_t *uf, uint16_t id) static inline uint32_t unionfind_get_representative(unionfind_t *uf, uint32_t id)
{ {
// base case: a node is its own parent // base case: a node is its own parent
if (uf->data[id].parent == id) if (uf->data[id].parent == id)
@ -9172,9 +9176,9 @@ static inline uint16_t unionfind_get_representative(unionfind_t *uf, uint16_t id
// this one seems to be every-so-slightly faster than the recursive // this one seems to be every-so-slightly faster than the recursive
// version above. // version above.
static inline uint16_t unionfind_get_representative(unionfind_t *uf, uint16_t id) static inline uint32_t unionfind_get_representative(unionfind_t *uf, uint32_t id)
{ {
uint16_t root = id; uint32_t root = id;
// chase down the root // chase down the root
while (uf->data[root].parent != root) { while (uf->data[root].parent != root) {
@ -9187,7 +9191,7 @@ static inline uint16_t unionfind_get_representative(unionfind_t *uf, uint16_t id
// (e.g. image segmentation), we are actually faster not doing // (e.g. image segmentation), we are actually faster not doing
// this... // this...
while (uf->data[id].parent != root) { while (uf->data[id].parent != root) {
uint16_t tmp = uf->data[id].parent; uint32_t tmp = uf->data[id].parent;
uf->data[id].parent = root; uf->data[id].parent = root;
id = tmp; id = tmp;
} }
@ -9195,10 +9199,10 @@ static inline uint16_t unionfind_get_representative(unionfind_t *uf, uint16_t id
return root; return root;
} }
static inline uint16_t unionfind_connect(unionfind_t *uf, uint16_t aid, uint16_t bid) static inline uint32_t unionfind_connect(unionfind_t *uf, uint32_t aid, uint32_t bid)
{ {
uint16_t aroot = unionfind_get_representative(uf, aid); uint32_t aroot = unionfind_get_representative(uf, aid);
uint16_t broot = unionfind_get_representative(uf, bid); uint32_t broot = unionfind_get_representative(uf, bid);
if (aroot != broot) if (aroot != broot)
uf->data[broot].parent = aroot; uf->data[broot].parent = aroot;
@ -10475,9 +10479,11 @@ zarray_t *apriltag_quad_thresh(apriltag_detector_t *td, image_u8_t *im, bool ove
DO_CONN(1, 0); DO_CONN(1, 0);
DO_CONN(0, 1); DO_CONN(0, 1);
#ifdef IMLIB_ENABLE_HIGH_RES_APRILTAGS
// do 8 connectivity // do 8 connectivity
// DO_CONN(-1, 1); DO_CONN(-1, 1);
// DO_CONN(1, 1); DO_CONN(1, 1);
#endif
} }
} }
#undef DO_CONN #undef DO_CONN

View File

@ -202,7 +202,7 @@ bool jpeg_compress(image_t *src, image_t *dst, int quality, bool realloc)
} }
// NOTE: output buffer size is stored in dst->bpp // NOTE: output buffer size is stored in dst->bpp
if (HAL_JPEG_Encode(&JPEG_Handle, get_mcu(), jpeg_enc.mcu_size, dst->pixels, dst->bpp, 100) != HAL_OK) { if (HAL_JPEG_Encode(&JPEG_Handle, get_mcu(), jpeg_enc.mcu_size, dst->pixels, dst->bpp, 10000) != HAL_OK) {
// Initialization error // Initialization error
return true; return true;
} }

View File

@ -398,6 +398,12 @@ FRESULT exec_boot_script(const char *path, bool selftest, bool interruptible)
int main(void) int main(void)
{ {
#if MICROPY_HW_SDRAM_SIZE
bool sdram_ok = false;
#if MICROPY_HW_SDRAM_STARTUP_TEST
bool sdram_pass = false;
#endif
#endif
int sensor_init_ret = 0; int sensor_init_ret = 0;
bool sdcard_mounted = false; bool sdcard_mounted = false;
bool first_soft_reset = true; bool first_soft_reset = true;
@ -413,6 +419,13 @@ int main(void)
// NOTE: The bootloader enables the CCM/DTCM memory. // NOTE: The bootloader enables the CCM/DTCM memory.
HAL_Init(); HAL_Init();
#if MICROPY_HW_SDRAM_SIZE
sdram_ok = sdram_init();
#if MICROPY_HW_SDRAM_STARTUP_TEST
sdram_pass = sdram_test(false);
#endif
#endif
// Basic sub-system init // Basic sub-system init
led_init(); led_init();
pendsv_init(); pendsv_init();
@ -561,6 +574,22 @@ soft_reset:
pyb_usb_dev_init(USBD_VID, USBD_PID_CDC_MSC, USBD_MODE_CDC_MSC, NULL); pyb_usb_dev_init(USBD_VID, USBD_PID_CDC_MSC, USBD_MODE_CDC_MSC, NULL);
} }
// report if SDRAM failed
#if MICROPY_HW_SDRAM_SIZE
if (first_soft_reset && (!sdram_ok)) {
char buf[512];
snprintf(buf, sizeof(buf), "Failed to init sdram!");
__fatal_error(buf);
}
#if MICROPY_HW_SDRAM_STARTUP_TEST
if (first_soft_reset && (!sdram_pass)) {
char buf[512];
snprintf(buf, sizeof(buf), "SDRAM failed testing!");
__fatal_error(buf);
}
#endif
#endif
// check sensor init result // check sensor init result
if (first_soft_reset && sensor_init_ret != 0) { if (first_soft_reset && sensor_init_ret != 0) {
char buf[512]; char buf[512];

View File

@ -5545,7 +5545,9 @@ static mp_obj_t py_image_find_apriltags(uint n_args, const mp_obj_t *args, mp_ma
rectangle_t roi; rectangle_t roi;
py_helper_keyword_rectangle_roi(arg_img, n_args, args, 1, kw_args, &roi); py_helper_keyword_rectangle_roi(arg_img, n_args, args, 1, kw_args, &roi);
#ifndef IMLIB_ENABLE_HIGH_RES_APRILTAGS
PY_ASSERT_TRUE_MSG((roi.w * roi.h) < 65536, "The maximum supported resolution for find_apriltags() is < 64K pixels."); PY_ASSERT_TRUE_MSG((roi.w * roi.h) < 65536, "The maximum supported resolution for find_apriltags() is < 64K pixels.");
#endif
if ((roi.w < 4) || (roi.h < 4)) { if ((roi.w < 4) || (roi.h < 4)) {
return mp_obj_new_list(0, NULL); return mp_obj_new_list(0, NULL);
} }

View File

@ -29,6 +29,9 @@ MEMORY
#if defined(OMV_AXI_SRAM_ORIGIN) #if defined(OMV_AXI_SRAM_ORIGIN)
AXI_SRAM (xrw) : ORIGIN = OMV_AXI_SRAM_ORIGIN, LENGTH = OMV_AXI_SRAM_LENGTH AXI_SRAM (xrw) : ORIGIN = OMV_AXI_SRAM_ORIGIN, LENGTH = OMV_AXI_SRAM_LENGTH
#endif #endif
#if defined(OMV_DRAM_ORIGIN)
DRAM (xrw) : ORIGIN = OMV_DRAM_ORIGIN, LENGTH = OMV_DRAM_LENGTH
#endif
FLASH_TEXT (rx) : ORIGIN = OMV_TEXT_ORIGIN, LENGTH = OMV_TEXT_LENGTH FLASH_TEXT (rx) : ORIGIN = OMV_TEXT_ORIGIN, LENGTH = OMV_TEXT_LENGTH
} }
@ -88,6 +91,12 @@ SECTIONS
. = ALIGN(4); . = ALIGN(4);
_fballoc = .; _fballoc = .;
#if defined(OMV_FB_JPEG_MEMORY)
. = ALIGN(4);
_jpeg_buf = .; // IDE JPEG buffer
. = . + OMV_JPEG_BUF_SIZE;
#endif
} >OMV_FB_MEMORY } >OMV_FB_MEMORY
/* Misc DMA buffers kept in uncachable region */ /* Misc DMA buffers kept in uncachable region */
@ -111,7 +120,7 @@ SECTIONS
. = . + OMV_FFS_BUF_SIZE; . = . + OMV_FFS_BUF_SIZE;
#endif #endif
#if !defined(OMV_JPEG_MEMORY) #if !defined(OMV_JPEG_MEMORY) && !defined(OMV_FB_JPEG_MEMORY)
. = ALIGN(4); . = ALIGN(4);
_jpeg_buf = .; // IDE JPEG buffer _jpeg_buf = .; // IDE JPEG buffer
. = . + OMV_JPEG_BUF_SIZE; . = . + OMV_JPEG_BUF_SIZE;

View File

@ -84,6 +84,12 @@ void HAL_MspInit(void)
__GPIOC_CLK_ENABLE(); __GPIOC_CLK_ENABLE();
__GPIOD_CLK_ENABLE(); __GPIOD_CLK_ENABLE();
__GPIOE_CLK_ENABLE(); __GPIOE_CLK_ENABLE();
#ifdef ENABLE_GPIO_BANK_F
__GPIOF_CLK_ENABLE();
#endif
#ifdef ENABLE_GPIO_BANK_G
__GPIOG_CLK_ENABLE();
#endif
#if defined(STM32F769xx) #if defined(STM32F769xx)
__GPIOF_CLK_ENABLE(); __GPIOF_CLK_ENABLE();

View File

@ -7,6 +7,7 @@
#include <string.h> #include <string.h>
#include "fb_alloc.h" #include "fb_alloc.h"
#include "umm_malloc.h" #include "umm_malloc.h"
#include "omv_boardconfig.h"
NORETURN void umm_alloc_fail() NORETURN void umm_alloc_fail()
{ {
@ -109,7 +110,7 @@ UMM_H_ATTPACKPRE typedef struct umm_block_t {
} header; } header;
union { union {
umm_ptr free; umm_ptr free;
unsigned char data[16]; unsigned char data[OMV_UMM_BLOCK_SIZE];
} body; } body;
} UMM_H_ATTPACKSUF umm_block; } UMM_H_ATTPACKSUF umm_block;

View File

@ -29,6 +29,9 @@ MEMORY
#if defined(OMV_AXI_SRAM_ORIGIN) #if defined(OMV_AXI_SRAM_ORIGIN)
AXI_SRAM (xrw) : ORIGIN = OMV_AXI_SRAM_ORIGIN, LENGTH = OMV_AXI_SRAM_LENGTH AXI_SRAM (xrw) : ORIGIN = OMV_AXI_SRAM_ORIGIN, LENGTH = OMV_AXI_SRAM_LENGTH
#endif #endif
#if defined(OMV_DRAM_ORIGIN)
DRAM (xrw) : ORIGIN = OMV_DRAM_ORIGIN, LENGTH = OMV_DRAM_LENGTH
#endif
FLASH_TEXT (rx) : ORIGIN = OMV_TEXT_ORIGIN, LENGTH = OMV_TEXT_LENGTH FLASH_TEXT (rx) : ORIGIN = OMV_TEXT_ORIGIN, LENGTH = OMV_TEXT_LENGTH
} }
@ -83,6 +86,12 @@ SECTIONS
. = ALIGN(4); . = ALIGN(4);
_fballoc = .; _fballoc = .;
#if defined(OMV_FB_JPEG_MEMORY)
. = ALIGN(4);
_jpeg_buf = .; // IDE JPEG buffer
. = . + OMV_JPEG_BUF_SIZE;
#endif
} >OMV_FB_MEMORY } >OMV_FB_MEMORY
/* Misc DMA buffers kept in uncachable region */ /* Misc DMA buffers kept in uncachable region */
@ -107,7 +116,7 @@ SECTIONS
. = . + OMV_FFS_BUF_SIZE; . = . + OMV_FFS_BUF_SIZE;
#endif #endif
#if !defined(OMV_JPEG_MEMORY) #if !defined(OMV_JPEG_MEMORY) && !defined(OMV_FB_JPEG_MEMORY)
. = ALIGN(4); . = ALIGN(4);
_jpeg_buf = .; // IDE JPEG buffer _jpeg_buf = .; // IDE JPEG buffer
. = . + OMV_JPEG_BUF_SIZE; . = . + OMV_JPEG_BUF_SIZE;