Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(MiscDrivers,PeriphDrivers,Examples): CSI2/ImgCapture Image Processing Pipeline Rework, New MAX78002 QSPI Example, New RetinaNet Example #583

Merged
merged 127 commits into from
Jun 6, 2023

Conversation

Jake-Carter
Copy link
Contributor

@Jake-Carter Jake-Carter commented May 9, 2023

Overview

This is a big one...

  • Add APS6404 (external SRAM on the MAX78002EVKIT) drivers.

    • This enables a higher capacity buffer destination for captured images.
    • The drivers include a refactored SPI implementation ("fastspi") local to the ImgCapture and CSI2 projects.
    • aps6404 + fastspi drivers will be moved to MiscDrivers pending @sihyung-maxim's work on the PeriphDrivers SPI API. For now, they will live local to the projects to avoid conflicts.
  • Refactor CSI2 RevA drivers and MIPI camera API

    • These were previously not usable for real-world captures due to poor implementation and significant hardware issues related to the built-in debayering engine.
    • Hardware issues have been tracked in Jira, while software workarounds have been put in place to get the drivers functional.
    • Abstracts away the complexity of the CSI2 hardware/drivers.
    • Decoupled CSI2 drivers from application-side memory management. Application code provides a line handler to offload data to any arbitrary destination.
    • Use APS6404 external SRAM as buffer destination for ImgCapture and CSI2 examples
    • Improved OV5640 performance by leveraging its built-in debayering engine
  • Add the PascalVOC-RetinaNetv7_3 object detection demo for the MAX78002

    • Captures 320x256 image over CSI2
    • Runs RetinaNet object detection
    • Draws captured image and overlays bounding boxes to NewHaven TFT display
  • Add QSPI example for MAX78002EVKIT

  • Miscellaneous ImgCapture/README fixes

Related PRs

Model training & synthesis files for PascalVOC-RetinaNet

Tests

  • MAX78002 Internal EVKIT Rev A + Pcam 5C
  • MAX78002 External EVKIT Rev A + Pcam 5C

RGB565 works at the improved framerate up to 320x320. Beyond that, it works up to 672x514 at reduced framerate.

  • 160x120 (QQVGA) RGB565 (10-15 fps)
    OV5640_160x120_RGB565

  • 320x240 (QVGA) RGB565 (10-15 fps)
    OV5640_320x240_RGB565

  • 320x320 RGB565 (10-15 fps)
    OV5640_320x320_RGB565

  • 640x480 RGB565 (2-3 fps)
    OV5640_640x480_RGB565

RAW8 also works at all the resolutions above. It can push farther up to 800x600 (SVGA) before operation becomes unreliable.

  • 800x600 RAW8 (2-3 fps)
    OV5640_800x600_RAW8

  • 928x768 RAW8 (2-3 fps)
    OV5640_928x728_RAW8

- Working standard reads/writes
- Working QSPI reads/writes
- If the value of the dummy byte was defined locally inside of the
  spi_transmit function, it would introduce some glitches on the SPI
  MOSI line.  Suspected compiler optimization issue.

  For some reason, these glitches also corrupted the MISO line.  This
  caused RX data to be corrupted, and ram reads would return incorrect
  values.
- Working standard reads/writes
- Working QSPI reads/writes
- If the value of the dummy byte was defined locally inside of the
  spi_transmit function, it would introduce some glitches on the SPI
  MOSI line.  Suspected compiler optimization issue.

  For some reason, these glitches also corrupted the MISO line.  This
  caused RX data to be corrupted, and ram reads would return incorrect
  values.
@Jake-Carter
Copy link
Contributor Author

/clang-format-run


// Used for Non-DMA CSI2 Cases
static volatile uint32_t bits_per_pixel;
static volatile uint32_t fifo_burst_size;
static volatile mxc_csi2_reva_fifo_trig_t fifo_int_trig;
static volatile mxc_csi2_ahbwait_t ahbwait_en;

typedef enum { SELECT_A, SELECT_B } lb_sel_t;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Delete this (unused)


mxc_csi2_capture_stats_t MXC_CSI2_GetCaptureStats()
{
mxc_csi2_reva_capture_stats_t stats = MXC_CSI2_RevA_DMA_GetCaptureStats();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you just return stats here? Or return the RevA function call? I forget how the casting works for structs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mxc_csi2_capture_stats_t MXC_CSI2_GetCaptureStats()
{
    mxc_csi2_reva_capture_stats_t stats = MXC_CSI2_RevA_DMA_GetCaptureStats();
    return (mxc_csi2_capture_stats_t)stats;
}

Gives

/home/jakecarter/repos/fork/msdk/Libraries/CMSIS/../PeriphDrivers/Source/CSI2/csi2_ai87.c: In function 'MXC_CSI2_GetCaptureStats':
/home/jakecarter/repos/fork/msdk/Libraries/CMSIS/../PeriphDrivers/Source/CSI2/csi2_ai87.c:325:5: error: conversion to non-scalar type requested
  325 |     return (mxc_csi2_capture_stats_t)stats;
      |     ^~~~~~

I think we need to return a pointer to do the type cast but I just wanted to return the struct directly.

I'll see if I can clean this up a bit

@@ -67,32 +73,82 @@
(MXC_F_CSI2_REVA_RX_EINT_VFF_IE_FNEMP_MD | MXC_F_CSI2_REVA_RX_EINT_VFF_IE_FTHD_MD | \
MXC_F_CSI2_REVA_RX_EINT_VFF_IE_FFUL_MD)

// A macro to convert a DMA channel number to an IRQn number
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessarily for this PR, but we should add this to all <part_number>.h's

* @brief Interrupt Handler Function.
* @return #E_NO_ERROR if everything is successful.
*/
int MXC_CSI2_Handler(void);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the mxc_csi2_line_handler_cb_t supposed to replace this function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, but I wanted to intentionally remove the publicly exposed handler. The drivers are completely interrupt driven from MXC_CSI2_RevAHandler so there is no option to override the CSI2 IRQ handler (yet).

@Jacob-Scheiffler Jacob-Scheiffler self-requested a review June 6, 2023 21:25
@Jake-Carter Jake-Carter changed the title CSI2/ImgCapture: Image Processing Pipeline Rework, MAX78002: New QSPI Example, RetinaNet Example feat(MiscDrivers,PeriphDrivers,Examples): CSI2/ImgCapture Image Processing Pipeline Rework, New MAX78002 QSPI Example, New RetinaNet Example Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Change This issue or pull request involves a change to the current MSDK API MAX78000 Related to the MAX78000 (AI85) MAX78002 Related to the MAX78002 (AI87)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

imgCapture Stream "Image received failed, Only received 3/247808"
3 participants