AUDIO DISCO_F746NG audioloop basic example

Dependencies:   BSP_DISCO_F746NG

Files at this revision

API Documentation at this revision

Comitter:
Jerome Coutant
Date:
Wed Nov 20 11:10:32 2019 +0100
Parent:
4:bf9ab5993081
Commit message:
Update with STM32Cube_FW_F7_V1.15.0

Changed in this revision

.hgignore Show annotated file Show diff for this revision Revisions of this file
AUDIO_DISCO_F746NG.lib Show diff for this revision Revisions of this file
BSP_DISCO_F746NG.lib Show annotated file Show diff for this revision Revisions of this file
SDRAM_DISCO_F746NG.lib Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore	Wed Nov 20 11:10:32 2019 +0100
@@ -0,0 +1,2 @@
+BUILD
+mbed-os/
--- a/AUDIO_DISCO_F746NG.lib	Thu Jun 08 13:21:00 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-https://developer.mbed.org/teams/ST/code/AUDIO_DISCO_F746NG/#7046ce26b7ed
--- a/BSP_DISCO_F746NG.lib	Thu Jun 08 13:21:00 2017 +0000
+++ b/BSP_DISCO_F746NG.lib	Wed Nov 20 11:10:32 2019 +0100
@@ -1,1 +1,1 @@
-https://developer.mbed.org/teams/ST/code/BSP_DISCO_F746NG/#56384bddaba5
+https://mbed.org/teams/ST/code/BSP_DISCO_F746NG/#1050c589b2ad
--- a/SDRAM_DISCO_F746NG.lib	Thu Jun 08 13:21:00 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-https://developer.mbed.org/teams/ST/code/SDRAM_DISCO_F746NG/#370f402a2219
--- a/main.cpp	Thu Jun 08 13:21:00 2017 +0000
+++ b/main.cpp	Wed Nov 20 11:10:32 2019 +0100
@@ -1,66 +1,69 @@
 #include "mbed.h"
-#include "AUDIO_DISCO_F746NG.h"
-#include "SDRAM_DISCO_F746NG.h"
+#include "stm32746g_discovery_audio.h"
+#include "stm32746g_discovery_sdram.h"
 
-AUDIO_DISCO_F746NG audio;
-// audio IN_OUT buffer is stored in the SDRAM, SDRAM needs to be initialized and FMC enabled
-SDRAM_DISCO_F746NG sdram;
 
-DigitalOut led_green(LED1);
-DigitalOut led_red(LED2);
-Serial pc(USBTX, USBRX);
-
-typedef enum
-{
+typedef enum {
     BUFFER_OFFSET_NONE = 0,
     BUFFER_OFFSET_HALF = 1,
     BUFFER_OFFSET_FULL = 2,
-}BUFFER_StateTypeDef;
+} BUFFER_StateTypeDef;
+
 
 #define AUDIO_BLOCK_SIZE   ((uint32_t)512)
-#define AUDIO_BUFFER_IN     SDRAM_DEVICE_ADDR     /* In SDRAM */
-#define AUDIO_BUFFER_OUT   (SDRAM_DEVICE_ADDR + (AUDIO_BLOCK_SIZE * 2)) /* In SDRAM */
-__IO uint32_t  audio_rec_buffer_state = BUFFER_OFFSET_NONE;
-static uint8_t SetSysClock_PLL_HSE_200MHz();
+#define AUDIO_BUFFER_IN     SDRAM_DEVICE_ADDR
+#define AUDIO_BUFFER_OUT   (AUDIO_BUFFER_IN + (AUDIO_BLOCK_SIZE * 2))
+
+volatile uint32_t  audio_rec_buffer_state = BUFFER_OFFSET_NONE;
+
+
 int main()
 {
-    SetSysClock_PLL_HSE_200MHz();
-    pc.baud(9600);
+    printf("\n\nAUDIO LOOPBACK EXAMPLE START:\n");
+
+    BSP_AUDIO_IN_OUT_Init(INPUT_DEVICE_DIGITAL_MICROPHONE_2, OUTPUT_DEVICE_HEADPHONE, DEFAULT_AUDIO_IN_FREQ, DEFAULT_AUDIO_IN_BIT_RESOLUTION, DEFAULT_AUDIO_IN_CHANNEL_NBR);
+    printf("AUDIO loop from digital micro (U20 & U21 components on board) to headphone (CN10 jack connector)\n");
+
 
-    pc.printf("\n\nAUDIO LOOPBACK EXAMPLE START:\n");
-    led_red = 0;
-  
-    pc.printf("\nAUDIO RECORD INIT OK\n");
-    pc.printf("Microphones sound streamed to headphones\n");
-    
     /* Initialize SDRAM buffers */
-    memset((uint16_t*)AUDIO_BUFFER_IN, 0, AUDIO_BLOCK_SIZE*2);
-    memset((uint16_t*)AUDIO_BUFFER_OUT, 0, AUDIO_BLOCK_SIZE*2);
+    BSP_SDRAM_Init();
+    memset((uint16_t *)AUDIO_BUFFER_IN, 0, AUDIO_BLOCK_SIZE * 2);
+    memset((uint16_t *)AUDIO_BUFFER_OUT, 0, AUDIO_BLOCK_SIZE * 2);
+    printf("SDRAM init done\n");
+
     audio_rec_buffer_state = BUFFER_OFFSET_NONE;
 
     /* Start Recording */
-    audio.IN_Record((uint16_t*)AUDIO_BUFFER_IN, AUDIO_BLOCK_SIZE);
+    if (BSP_AUDIO_IN_Record((uint16_t *)AUDIO_BUFFER_IN, AUDIO_BLOCK_SIZE) != AUDIO_OK) {
+        printf("BSP_AUDIO_IN_Record error\n");
+    }
 
     /* Start Playback */
-    audio.OUT_SetAudioFrameSlot(CODEC_AUDIOFRAME_SLOT_02);
-    audio.OUT_Play((uint16_t*)AUDIO_BUFFER_OUT, AUDIO_BLOCK_SIZE * 2);
+    BSP_AUDIO_OUT_SetAudioFrameSlot(CODEC_AUDIOFRAME_SLOT_02);
+    if (BSP_AUDIO_OUT_Play((uint16_t *)AUDIO_BUFFER_OUT, AUDIO_BLOCK_SIZE * 2) != AUDIO_OK) {
+        printf("BSP_AUDIO_OUT_Play error\n");
+    }
 
-  
     while (1) {
         /* Wait end of half block recording */
-        while(audio_rec_buffer_state == BUFFER_OFFSET_HALF) {
+        while (audio_rec_buffer_state == BUFFER_OFFSET_HALF) {
         }
         audio_rec_buffer_state = BUFFER_OFFSET_NONE;
+
         /* Copy recorded 1st half block */
         memcpy((uint16_t *)(AUDIO_BUFFER_OUT), (uint16_t *)(AUDIO_BUFFER_IN), AUDIO_BLOCK_SIZE);
+
         /* Wait end of one block recording */
-        while(audio_rec_buffer_state == BUFFER_OFFSET_FULL) {
+        while (audio_rec_buffer_state == BUFFER_OFFSET_FULL) {
         }
         audio_rec_buffer_state = BUFFER_OFFSET_NONE;
+
         /* Copy recorded 2nd half block */
         memcpy((uint16_t *)(AUDIO_BUFFER_OUT + (AUDIO_BLOCK_SIZE)), (uint16_t *)(AUDIO_BUFFER_IN + (AUDIO_BLOCK_SIZE)), AUDIO_BLOCK_SIZE);
     }
 }
+
+
 /*-------------------------------------------------------------------------------------
        Callbacks implementation:
            the callbacks API are defined __weak in the stm32746g_discovery_audio.c file
@@ -74,8 +77,7 @@
   */
 void BSP_AUDIO_IN_TransferComplete_CallBack(void)
 {
-  audio_rec_buffer_state = BUFFER_OFFSET_FULL;
-  return;
+    audio_rec_buffer_state = BUFFER_OFFSET_FULL;
 }
 
 /**
@@ -85,52 +87,15 @@
   */
 void BSP_AUDIO_IN_HalfTransfer_CallBack(void)
 {
-  audio_rec_buffer_state = BUFFER_OFFSET_HALF;
-  return;
+    audio_rec_buffer_state = BUFFER_OFFSET_HALF;
 }
 
-static uint8_t SetSysClock_PLL_HSE_200MHz()
+/**
+  * @brief  Audio IN Error callback function.
+  * @param  None
+  * @retval None
+  */
+void BSP_AUDIO_IN_Error_CallBack(void)
 {
-  RCC_ClkInitTypeDef RCC_ClkInitStruct;
-  RCC_OscInitTypeDef RCC_OscInitStruct;
-
-  // Enable power clock  
-  __PWR_CLK_ENABLE();
-  
-  // Enable HSE oscillator and activate PLL with HSE as source
-  RCC_OscInitStruct.OscillatorType      = RCC_OSCILLATORTYPE_HSE;
-  RCC_OscInitStruct.HSEState            = RCC_HSE_ON; /* External xtal on OSC_IN/OSC_OUT */
-
-  // Warning: this configuration is for a 25 MHz xtal clock only
-  RCC_OscInitStruct.PLL.PLLState        = RCC_PLL_ON;
-  RCC_OscInitStruct.PLL.PLLSource       = RCC_PLLSOURCE_HSE;
-  RCC_OscInitStruct.PLL.PLLM            = 25;            // VCO input clock = 1 MHz (25 MHz / 25)
-  RCC_OscInitStruct.PLL.PLLN            = 400;           // VCO output clock = 400 MHz (1 MHz * 400)
-  RCC_OscInitStruct.PLL.PLLP            = RCC_PLLP_DIV2; // PLLCLK = 200 MHz (400 MHz / 2)
-  RCC_OscInitStruct.PLL.PLLQ            = 8;             // USB clock = 50 MHz (400 MHz / 8)
-  
-  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
-  {
-    return 0; // FAIL
-  }
-
-  // Activate the OverDrive to reach the 216 MHz Frequency
-  if (HAL_PWREx_EnableOverDrive() != HAL_OK)
-  {
-    return 0; // FAIL
-  }
-  
-  // Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers
-  RCC_ClkInitStruct.ClockType      = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
-  RCC_ClkInitStruct.SYSCLKSource   = RCC_SYSCLKSOURCE_PLLCLK; // 200 MHz
-  RCC_ClkInitStruct.AHBCLKDivider  = RCC_SYSCLK_DIV1;         // 200 MHz
-  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;           //  50 MHz
-  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;           // 100 MHz
-  
-  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_7) != HAL_OK)
-  {
-    return 0; // FAIL
-  }
-  HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSE, RCC_MCODIV_4);
-  return 1; // OK
+    printf("BSP_AUDIO_IN_Error_CallBack\n");
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Wed Nov 20 11:10:32 2019 +0100
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#699372421a3b388fe568e9be85b1a985749a438f
--- a/mbed.bld	Thu Jun 08 13:21:00 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-https://mbed.org/users/mbed_official/code/mbed/builds/86740a56073b
\ No newline at end of file