Skip to content

Commit 5a2aad1

Browse files
Re-add video and PDM libraries on Portenta H7
1 parent 687b510 commit 5a2aad1

File tree

15 files changed

+67
-56
lines changed

15 files changed

+67
-56
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ cores/arduino/api*
33
**/.vscode/
44
**/.development
55
.DS_Store
6+
7+
# CLion
68
cmake-build-*/
9+
.idea/runConfigurations

libraries/Arduino_H7_Video/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ add_library(arduino-Arduino_H7_Video STATIC ${ARDUINO_H7_VIDEO_SOURCES})
1111
target_link_libraries(arduino-Arduino_H7_Video PUBLIC arduino-core arduino-Portenta_SDRAM)
1212
target_include_directories(arduino-Arduino_H7_Video PUBLIC src)
1313

14-
build_arduino_examples(Arduino_H7_Video examples)
15-
14+
# For this library, we cannot build the examples as part of Mbed CE, because they rely on driver libraries
15+
# which are maintained outside this repo.
1616
install(DIRECTORY . DESTINATION libraries/Arduino_H7_Video)

libraries/CMakeLists.txt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,19 @@ if("ARDUINO_PORTENTA_H7" IN_LIST MBED_TARGET_LABELS)
6464
add_subdirectory(Arduino_CAN)
6565
add_subdirectory(GSM)
6666
add_subdirectory(GPS)
67+
add_subdirectory(Portenta_SDCARD)
68+
add_subdirectory(PDM)
69+
add_subdirectory(Portenta_Audio)
70+
add_subdirectory(Arduino_H7_Video)
71+
add_subdirectory(Camera)
72+
add_subdirectory(Himax_HM01B0)
73+
add_subdirectory(Himax_HM0360)
74+
6775
# TODO add missing libraries for Portenta
68-
# add_subdirectory(PDM)
69-
# add_subdirectory(Arduino_H7_Video)
70-
# add_subdirectory(Himax_HM01B0)
71-
# add_subdirectory(Himax_HM0360)
72-
# add_subdirectory(Portenta_Audio)
7376
# add_subdirectory(RPC)
74-
# add_subdirectory(Portenta_lvgl)
75-
# add_subdirectory(Camera)
7677
# add_subdirectory(rpclib)
7778
# add_subdirectory(USBHOST)
7879
# add_subdirectory(mbed-memory-status)
79-
# add_subdirectory(Portenta_SDCARD)
80-
# add_subdirectory(GPS)
8180
# add_subdirectory(MCUboot)
8281
#
8382
endif()

libraries/Camera/CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
set(CAMERA_SOURCES
2+
src/camera.cpp)
3+
4+
add_library(arduino-Camera STATIC ${CAMERA_SOURCES})
5+
target_link_libraries(arduino-Camera PUBLIC arduino-core arduino-Wire)
6+
target_include_directories(arduino-Camera PUBLIC src)
7+
8+
set(EXAMPLES_TO_SKIP GigaCameraDisplay)
9+
if(NOT "ARDUINO_NICLA_VISION" IN_LIST MBED_TARGET_LABELS)
10+
list(APPEND EXAMPLES_TO_SKIP CameraCaptureZoomPan)
11+
endif()
12+
13+
build_arduino_examples(Camera examples ${EXAMPLES_TO_SKIP})
14+
15+
if("ARDUINO_PORTENTA_H7" IN_LIST MBED_TARGET_LABELS)
16+
target_link_libraries(Camera-example-CameraCaptureRawBytes arduino-Himax_HM0360)
17+
target_link_libraries(Camera-example-CameraMotionDetect arduino-Himax_HM0360)
18+
endif()

libraries/Camera/src/camera.cpp

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "camera.h"
2121
#include "Wire.h"
2222
#include "stm32h7xx_hal_dcmi.h"
23+
#include "stm_dma_utils.h"
2324

2425
// Workaround for the broken UNUSED macro.
2526
#undef UNUSED
@@ -73,10 +74,11 @@ arduino::MbedI2C CameraWire(I2C_SDA1, I2C_SCL1);
7374

7475
#define DCMI_IRQ_PRI NVIC_EncodePriority(NVIC_PRIORITYGROUP_4, 2, 0)
7576

76-
#define DCMI_DMA_CLK_ENABLE() __HAL_RCC_DMA2_CLK_ENABLE()
77-
#define DCMI_DMA_STREAM DMA2_Stream3
78-
#define DCMI_DMA_IRQ DMA2_Stream3_IRQn
79-
#define DCMI_DMA_IRQ_PRI NVIC_EncodePriority(NVIC_PRIORITYGROUP_4, 3, 0)
77+
const static DMALinkInfo dcmiDMALink{
78+
.dmaIdx = 2,
79+
.channelIdx = 3,
80+
.sourceNumber = DMA_REQUEST_DCMI
81+
};
8082

8183
// DCMI GPIO pins struct
8284
static const struct { GPIO_TypeDef *port; uint16_t pin; } dcmi_pins[] = {
@@ -121,7 +123,6 @@ static const struct { GPIO_TypeDef *port; uint16_t pin; } dcmi_pins[] = {
121123
#define NUM_DCMI_PINS (sizeof(dcmi_pins)/sizeof(dcmi_pins[0]))
122124

123125
static TIM_HandleTypeDef htim = {0};
124-
static DMA_HandleTypeDef hdma = {0};
125126
static DCMI_HandleTypeDef hdcmi = {0};
126127

127128
/// Table to store the amount of bytes per pixel for each pixel format
@@ -207,8 +208,7 @@ void HAL_DCMI_MspDeInit(DCMI_HandleTypeDef* hdcmi)
207208
// Disable DCMI IRQs.
208209
HAL_NVIC_DisableIRQ(DCMI_IRQn);
209210

210-
// Disable DMA IRQs.
211-
HAL_NVIC_DisableIRQ(DCMI_DMA_IRQ);
211+
stm_free_dma_link(&dcmiDMALink);
212212

213213
// Deinit the DMA stream.
214214
if (hdcmi->DMA_Handle != NULL) {
@@ -270,29 +270,7 @@ __weak int camera_extclk_config(int frequency)
270270
uint8_t camera_dcmi_config(bool bsm_skip)
271271
{
272272
// DMA Stream configuration
273-
hdma.Instance = DCMI_DMA_STREAM;
274-
hdma.Init.Request = DMA_REQUEST_DCMI;
275-
hdma.Init.Direction = DMA_PERIPH_TO_MEMORY;
276-
hdma.Init.MemInc = DMA_MINC_ENABLE;
277-
hdma.Init.PeriphInc = DMA_PINC_DISABLE;
278-
hdma.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
279-
hdma.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
280-
hdma.Init.Mode = DMA_NORMAL;
281-
hdma.Init.Priority = DMA_PRIORITY_HIGH;
282-
hdma.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
283-
hdma.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
284-
hdma.Init.MemBurst = DMA_MBURST_INC4;
285-
hdma.Init.PeriphBurst = DMA_PBURST_SINGLE;
286-
287-
// Enable DMA clock
288-
DCMI_DMA_CLK_ENABLE();
289-
290-
// Initialize the DMA stream
291-
HAL_DMA_Init(&hdma);
292-
293-
// Configure and enable DMA IRQ Channel
294-
NVIC_SetPriority(DCMI_DMA_IRQ, DCMI_DMA_IRQ_PRI);
295-
HAL_NVIC_EnableIRQ(DCMI_DMA_IRQ);
273+
DMA_HandleTypeDef * handle = stm_init_dma_link(&dcmiDMALink, DMA_PERIPH_TO_MEMORY, false, true, 4, 4, DMA_NORMAL);
296274

297275
// Configure the DCMI interface.
298276
hdcmi.Instance = DCMI;
@@ -309,7 +287,7 @@ uint8_t camera_dcmi_config(bool bsm_skip)
309287
hdcmi.Init.LineSelectStart = DCMI_OELS_ODD; // Ignored, unless LSM != ALL
310288

311289
// Link the DMA handle to the DCMI handle.
312-
__HAL_LINKDMA(&hdcmi, DMA_Handle, hdma);
290+
__HAL_LINKDMA(&hdcmi, DMA_Handle, *handle);
313291

314292
// Initialize the DCMI
315293
HAL_DCMI_Init(&hdcmi);
@@ -325,12 +303,6 @@ void DCMI_IRQHandler(void)
325303
{
326304
HAL_DCMI_IRQHandler(&hdcmi);
327305
}
328-
329-
void DMA2_Stream3_IRQHandler(void)
330-
{
331-
HAL_DMA_IRQHandler(&hdma);
332-
}
333-
334306
} // extern "C"
335307

336308
FrameBuffer::FrameBuffer(int32_t x, int32_t y, int32_t bpp) :

libraries/Himax_HM01B0/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ set(HIMAX_HM01B0_SOURCES
22
himax.cpp)
33

44
add_library(arduino-Himax_HM01B0 STATIC ${HIMAX_HM01B0_SOURCES})
5-
target_link_libraries(arduino-Himax_HM01B0 PUBLIC arduino-core arduino-Wire)
5+
target_link_libraries(arduino-Himax_HM01B0 PUBLIC arduino-core arduino-Wire arduino-Camera)
66
target_include_directories(arduino-Himax_HM01B0 PUBLIC .)
77

88
install(DIRECTORY . DESTINATION libraries/Himax_HM01B0)

libraries/Himax_HM0360/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ set(HIMAX_HM0360_SOURCES
22
hm0360.cpp)
33

44
add_library(arduino-Himax_HM0360 STATIC ${HIMAX_HM0360_SOURCES})
5-
target_link_libraries(arduino-Himax_HM0360 PUBLIC arduino-core arduino-Wire)
5+
target_link_libraries(arduino-Himax_HM0360 PUBLIC arduino-core arduino-Wire arduino-Camera)
66
target_include_directories(arduino-Himax_HM0360 PUBLIC .)
77

88
install(DIRECTORY . DESTINATION libraries/Himax_HM0360)

libraries/PDM/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ endif()
1919

2020
add_library(arduino-PDM STATIC ${PDM_SOURCES})
2121
target_link_libraries(arduino-PDM PUBLIC arduino-core)
22+
23+
if("ARDUINO_PORTENTA_H7" IN_LIST MBED_TARGET_LABELS)
24+
target_link_libraries(arduino-PDM PUBLIC arduino-Portenta_Audio)
25+
endif()
26+
2227
target_include_directories(arduino-PDM PUBLIC src)
2328

2429
build_arduino_examples(PDM examples)

libraries/PDM/src/STM32H747_SAI/PDM.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
Boston, MA 02111-1307 USA
2121
*/
2222

23-
#ifdef TARGET_PORTENTA_H7
23+
#ifdef TARGET_ARDUINO_PORTENTA_H7
2424

2525
#include "PDM.h"
2626
#include "mbed.h"

libraries/PDM/src/STM32H747_SAI/audio.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ static volatile uint32_t xfer_status = 0;
4949
//int8_t* PDM_BUFFER = (uint16_t*)0x38000000;
5050
uint8_t PDM_BUFFER[PDM_BUFFER_SIZE] __attribute__ ((section(".pdm_buffer")));
5151

52+
// Defined in PDM.cpp
5253
void PDMIrqHandler(bool halftranfer);
5354
void PDMsetBufferSize(int size);
55+
size_t PDMgetBufferSize();
5456

5557
void AUDIO_SAI_DMA_IRQHandler(void)
5658
{

0 commit comments

Comments
 (0)