Example programs for GR-MANGO

Dependencies:   opencv-lib mbed-http

This is a collection of sample programs that work on RZ/A2M boards. You can try Mbed OS for RZ/A2M with GR-MANGO board.

Overview

Sample program files are located under the sample_programs folder. You can try each sample program by changing the following macro in sample_select.h.

insample_select.h

#define SAMPLE_PROGRAM_NO  0
No.Program fileDescription
0sample_00_led_rtc_analogin.cppDigitalOut, InterruptIn, RTC, Timer and AnalogIn
1sample_01_flash_write.cppFlashAPI sample
2sample_02_ssif_loop_back.cppSSIF loop back sample
4sample_04_ssif_wav_playback.cppSSIF wav playback sample (use USB memory or SD card)
7sample_07_usb_func_serial.cppUSBSerial (CDC) sample
8sample_08_usb_func_mouse.cppUSBMouse sample
9sample_09_usb_func_keyboard.cppUSBKeyboard sample
10sample_10_usb_func_midi.cppUSBMIDI sample
11sample_11_usb_func_audio_1.cppUSBAudio sample
12sample_12_usb_func_audio_2.cppUSBAudio and SSIF sample
13sample_13_ether_http.cppEther HTTP sample
14sample_14_ether_https.cppEther HTTPS sample
16sample_16_usb_func_msd_1.cppUSBMSD and FlashAPI sample
17sample_17_usb_func_msd_2.cppUSBMSD and FlashAPI sample advanced version
18sample_18_mipi_drp_lcd.cppMIPI, DRP and LCD sample
19sample_19_mipi_drp_diplayapp.cppMIPI, DRP and USBSerial (CDC) sample (use "DisplayApp")
20sample_20_drp_dynamic_loading.cppDRP Dynamic Loading Sample
21sample_21_deep_standby_alarm.cppDeep standby and RTC alarm sample
22sample_22_hdmi_disp_ssif.cppHDMI output and SSIF wav playback Sample
23sample_23_mipi_hdmi.cppHDMI output and MIPI Sample
24sample_24_facedetection.cppHDMI output and face detection using OpenCV
25sample_25_hdmi_mouse.cppHDMI output and Mouse Sample

Notice

sample_24_facedetection.cpp only can be compiled with GNU Compiler Collection.

About sample_24_facedetection.cpp, this is a demonstration that can detect the face of a person without a mask. It will surround the face of a person without a mask with a red rectangle and sound alarm at the same time. To use OpenCV for face recognition, you need to prepare the followings:
・USB drive or SD card
・ Raspberry Pi Camera Module V2
・ HDMI monitor

Perform the following steps to complete face recognition sample.
1. Copy the lbpcascade_frontalface.xml to the root folder of USB drive or SD card and save it.
2. Copy the alarm.wav to the root folder of USB drive or SD card and save it.
3. Set "camera-type" value to "CAMERA_RASPBERRY_PI_832X480" in mbed_app.json

About custom boot loaders

This sample uses custom bootloader revision 5, and you can drag & drop the "xxxx_application.bin" file to write the program. Please see here for the detail.

How to write program

When using DAPLink, please use xxxx.bin as following.

  1. Connect the micro USB type B terminal to the PC using a USB cable.
  2. You can find the MBED directory.
  3. Drag & drop xxxx.bin to the MBED directory.
  4. When writing is completed, press the reset button.

When using custom bootloader, please use xxxx_application.bin as following.

  1. Connect the USB type C terminal to the PC using a USB cable.
  2. Hold down USB0 and press the reset button.
  3. You can find the GR-MANG directory.
  4. Drag & drop xxxx_application.bin to the GR-MANGO directory.

When writing is completed, press the reset button.

Attention!

For the first time only, you need to write a custom bootloader using DAPLink.

Terminal setting

If you want to confirm the serial communication the terminal soft on your PC, please specify the below values. You can change the baud rate by platform.stio-baud-rate of mbed_app.json.

Baud rate115,200
Data8bit
Paritynone
Stop1bit
Flow controlnone
Committer:
luyao@os.mbed.com
Date:
Thu Mar 04 18:22:21 2021 +0900
Revision:
16:f4798796b4a2
Parent:
4:2da9e0f275a1
Modified EP952 Parameters.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 1 /*******************************************************************************
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 2 * DISCLAIMER
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 3 * This software is supplied by Renesas Electronics Corporation and is only
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 4 * intended for use with Renesas products. No other uses are authorized. This
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 5 * software is owned by Renesas Electronics Corporation and is protected under
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 6 * all applicable laws, including copyright laws.
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 7 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 8 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 9 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 10 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 11 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 12 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 13 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 14 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 15 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 16 * Renesas reserves the right, without notice, to make changes to this software
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 17 * and to discontinue the availability of this software. By using this software,
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 18 * you agree to the additional terms and conditions found by accessing the
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 19 * following link:
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 20 * http://www.renesas.com/disclaimer
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 21 *
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 22 * Copyright (C) 2019 Renesas Electronics Corporation. All rights reserved.
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 23 *******************************************************************************/
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 24 #include "sample_select.h"
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 25
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 26 #if (SAMPLE_PROGRAM_NO == 12)
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 27 // SAMPLE_PROGRAM_NO 12 : USBAudio and SSIF sample
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 28 // Sound from PC will be output to SSIF. (speaker)
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 29 // Sound from SSIF will be input to the PC. (microphone)
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 30 // [Attention!] Delete the "OVERRIDE_CONSOLE_USBSERIAL" macro in "mbed_app.json" file if it is set.
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 31
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 32 #if defined(TARGET_SEMB1402) || defined(TARGET_RZ_A2M_SBEV)
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 33 #error "Audio is not supported."
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 34 #endif
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 35
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 36 #include "mbed.h"
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 37 #include "USBAudio.h"
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 38 #include "AUDIO_GRBoard.h"
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 39
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 40 #define AUDIO_OUT_BUFF_NUM (8)
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 41 #define AUDIO_IN_BUFF_NUM (8)
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 42 #define AUDIO_BUFF_SIZE (4096)
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 43 AUDIO_GRBoard i2s_audio(0x80, AUDIO_OUT_BUFF_NUM - 1, AUDIO_IN_BUFF_NUM);
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 44
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 45 //32 bytes aligned! No cache memory
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 46 static uint8_t audio_out_buff[AUDIO_OUT_BUFF_NUM][AUDIO_BUFF_SIZE] __attribute((section("NC_BSS"),aligned(32)));
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 47 static uint8_t audio_in_buff[AUDIO_IN_BUFF_NUM][AUDIO_BUFF_SIZE] __attribute((section("NC_BSS"),aligned(32)));
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 48
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 49 Semaphore mic_in_sem(0);
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 50
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 51 static void callback_audio_in(void * p_data, int32_t result, void * p_app_data) {
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 52 mic_in_sem.release();
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 53 }
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 54
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 55 void mic_task(USBAudio * p_usb_audio) {
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 56 rbsp_data_conf_t audio_in_cb = {&callback_audio_in, NULL};
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 57 uint8_t * p_buf;
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 58 int audio_in_idx = 0;
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 59
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 60 // Read buffer setting
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 61 for (int i = 0; i < AUDIO_IN_BUFF_NUM; i++) {
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 62 i2s_audio.read(audio_in_buff[i], AUDIO_BUFF_SIZE, &audio_in_cb);
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 63 }
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 64
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 65 while (1) {
RyoheiHagimoto@os.mbed.com 4:2da9e0f275a1 66 mic_in_sem.acquire();
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 67 p_buf = audio_in_buff[audio_in_idx++];
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 68 if (audio_in_idx >= AUDIO_IN_BUFF_NUM) {
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 69 audio_in_idx = 0;
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 70 }
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 71 if (i2s_audio.read(p_buf, AUDIO_BUFF_SIZE, &audio_in_cb) < 0) {
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 72 memset(p_buf, 0, AUDIO_BUFF_SIZE);
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 73 }
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 74 p_usb_audio->write(p_buf, AUDIO_BUFF_SIZE);
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 75 }
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 76 }
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 77
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 78 int main() {
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 79 USBAudio usb_audio(true, 44100, 2, 44100, 2);
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 80 rbsp_data_conf_t audio_out_cb = {NULL, NULL};
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 81 uint8_t * p_buf;
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 82 int audio_out_idx = 0;
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 83
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 84 i2s_audio.power(); // For GR-PEACH and GR-LYCHEE
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 85 i2s_audio.outputVolume(0.5, 0.5); // For GR-PEACH and GR-LYCHEE
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 86 i2s_audio.micVolume(0.7); // For GR-PEACH and GR-LYCHEE
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 87
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 88 Thread micTask;
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 89 micTask.start(callback(mic_task, &usb_audio));
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 90
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 91 while (1) {
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 92 p_buf = audio_out_buff[audio_out_idx++];
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 93 if (audio_out_idx >= AUDIO_OUT_BUFF_NUM) {
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 94 audio_out_idx = 0;
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 95 }
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 96 if (!usb_audio.read(p_buf, AUDIO_BUFF_SIZE)) {
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 97 memset(p_buf, 0, AUDIO_BUFF_SIZE);
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 98 }
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 99 i2s_audio.write(p_buf, AUDIO_BUFF_SIZE, &audio_out_cb);
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 100 }
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 101 }
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 102
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 103 #endif