cours 1

Dependencies:   mbed USBDevice

Committer:
kanope_benny
Date:
Thu Sep 17 12:51:11 2020 +0000
Revision:
8:c6ec6b9f6a55
Parent:
3:7990c80e953c
Child:
9:41207561508d
met3 origine

Who changed what in which revision?

UserRevisionLine numberNew contents of line
samux 3:7990c80e953c 1 // Hello World example for the USBMIDI library
kanope_benny 8:c6ec6b9f6a55 2 #if 1
kanope_benny 8:c6ec6b9f6a55 3
kanope_benny 8:c6ec6b9f6a55 4
kanope_benny 8:c6ec6b9f6a55 5 #include "mbed.h"
kanope_benny 8:c6ec6b9f6a55 6 #include "USBSerial.h"
kanope_benny 8:c6ec6b9f6a55 7
kanope_benny 8:c6ec6b9f6a55 8
kanope_benny 8:c6ec6b9f6a55 9 void setup(void)
kanope_benny 8:c6ec6b9f6a55 10 {
kanope_benny 8:c6ec6b9f6a55 11 RCC_ClkInitTypeDef RCC_ClkInitStruct;
kanope_benny 8:c6ec6b9f6a55 12 RCC_OscInitTypeDef RCC_OscInitStruct;
kanope_benny 8:c6ec6b9f6a55 13
kanope_benny 8:c6ec6b9f6a55 14 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE;
kanope_benny 8:c6ec6b9f6a55 15 RCC_OscInitStruct.HSEState = RCC_HSE_ON;
kanope_benny 8:c6ec6b9f6a55 16
kanope_benny 8:c6ec6b9f6a55 17 RCC_OscInitStruct.LSIState = RCC_LSI_ON;
kanope_benny 8:c6ec6b9f6a55 18 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
kanope_benny 8:c6ec6b9f6a55 19 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
kanope_benny 8:c6ec6b9f6a55 20
kanope_benny 8:c6ec6b9f6a55 21 RCC_OscInitStruct.PLL.PLLM = 25; // VCO input clock = 1 MHz (25 MHz / 25)
kanope_benny 8:c6ec6b9f6a55 22 RCC_OscInitStruct.PLL.PLLN = 192; // VCO output clock = 192 MHz (1 MHz * 192)
kanope_benny 8:c6ec6b9f6a55 23 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; // PLLCLK = 96 MHz (192 MHz / 2)
kanope_benny 8:c6ec6b9f6a55 24 RCC_OscInitStruct.PLL.PLLQ = 4; // USB clock = 48 MHz (192 MHz / 4) --> Good for USB
kanope_benny 8:c6ec6b9f6a55 25
kanope_benny 8:c6ec6b9f6a55 26 HAL_RCC_OscConfig(&RCC_OscInitStruct);
kanope_benny 8:c6ec6b9f6a55 27
kanope_benny 8:c6ec6b9f6a55 28 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1;
kanope_benny 8:c6ec6b9f6a55 29 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
kanope_benny 8:c6ec6b9f6a55 30 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
kanope_benny 8:c6ec6b9f6a55 31 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);
kanope_benny 8:c6ec6b9f6a55 32
kanope_benny 8:c6ec6b9f6a55 33 SystemCoreClockUpdate();
kanope_benny 8:c6ec6b9f6a55 34 SystemCoreClock = 96000000;
kanope_benny 8:c6ec6b9f6a55 35
kanope_benny 8:c6ec6b9f6a55 36 //HAL_RCC_MCOConfig(RCC_MCO2, RCC_MCO2SOURCE_SYSCLK, RCC_MCODIV_1); // output SYSCLOCK to pin PC9 to monitor frequency
kanope_benny 8:c6ec6b9f6a55 37 }
kanope_benny 8:c6ec6b9f6a55 38
kanope_benny 8:c6ec6b9f6a55 39
kanope_benny 8:c6ec6b9f6a55 40
kanope_benny 8:c6ec6b9f6a55 41 DigitalOut myled(PC_13);
kanope_benny 8:c6ec6b9f6a55 42
kanope_benny 8:c6ec6b9f6a55 43 int main() {
kanope_benny 8:c6ec6b9f6a55 44
kanope_benny 8:c6ec6b9f6a55 45 setup();
kanope_benny 8:c6ec6b9f6a55 46
kanope_benny 8:c6ec6b9f6a55 47 USBSerial pc;
kanope_benny 8:c6ec6b9f6a55 48
kanope_benny 8:c6ec6b9f6a55 49
kanope_benny 8:c6ec6b9f6a55 50 while (1) {
kanope_benny 8:c6ec6b9f6a55 51 pc.printf("\ncalisse de guidoune!");
kanope_benny 8:c6ec6b9f6a55 52 myled = !myled; // LED
kanope_benny 8:c6ec6b9f6a55 53 wait_ms( 100 );
kanope_benny 8:c6ec6b9f6a55 54 }
kanope_benny 8:c6ec6b9f6a55 55 }
kanope_benny 8:c6ec6b9f6a55 56
kanope_benny 8:c6ec6b9f6a55 57
kanope_benny 8:c6ec6b9f6a55 58 #endif
kanope_benny 8:c6ec6b9f6a55 59
kanope_benny 8:c6ec6b9f6a55 60 #if 0
samux 3:7990c80e953c 61
samux 3:7990c80e953c 62 #include "mbed.h"
samux 3:7990c80e953c 63 #include "USBMIDI.h"
samux 3:7990c80e953c 64
samux 3:7990c80e953c 65
kanope_benny 8:c6ec6b9f6a55 66 void setup(void)
kanope_benny 8:c6ec6b9f6a55 67 {
kanope_benny 8:c6ec6b9f6a55 68 RCC_ClkInitTypeDef RCC_ClkInitStruct;
kanope_benny 8:c6ec6b9f6a55 69 RCC_OscInitTypeDef RCC_OscInitStruct;
kanope_benny 8:c6ec6b9f6a55 70
kanope_benny 8:c6ec6b9f6a55 71 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE;
kanope_benny 8:c6ec6b9f6a55 72 RCC_OscInitStruct.HSEState = RCC_HSE_ON;
kanope_benny 8:c6ec6b9f6a55 73
kanope_benny 8:c6ec6b9f6a55 74 RCC_OscInitStruct.LSIState = RCC_LSI_ON;
kanope_benny 8:c6ec6b9f6a55 75 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
kanope_benny 8:c6ec6b9f6a55 76 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
kanope_benny 8:c6ec6b9f6a55 77
kanope_benny 8:c6ec6b9f6a55 78 RCC_OscInitStruct.PLL.PLLM = 25; // VCO input clock = 1 MHz (25 MHz / 25)
kanope_benny 8:c6ec6b9f6a55 79 RCC_OscInitStruct.PLL.PLLN = 192; // VCO output clock = 192 MHz (1 MHz * 192)
kanope_benny 8:c6ec6b9f6a55 80 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; // PLLCLK = 96 MHz (192 MHz / 2)
kanope_benny 8:c6ec6b9f6a55 81 RCC_OscInitStruct.PLL.PLLQ = 4; // USB clock = 48 MHz (192 MHz / 4) --> Good for USB
kanope_benny 8:c6ec6b9f6a55 82
kanope_benny 8:c6ec6b9f6a55 83 HAL_RCC_OscConfig(&RCC_OscInitStruct);
kanope_benny 8:c6ec6b9f6a55 84
kanope_benny 8:c6ec6b9f6a55 85 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1;
kanope_benny 8:c6ec6b9f6a55 86 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
kanope_benny 8:c6ec6b9f6a55 87 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
kanope_benny 8:c6ec6b9f6a55 88 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);
kanope_benny 8:c6ec6b9f6a55 89
kanope_benny 8:c6ec6b9f6a55 90 SystemCoreClockUpdate();
kanope_benny 8:c6ec6b9f6a55 91 SystemCoreClock = 96000000;
kanope_benny 8:c6ec6b9f6a55 92
kanope_benny 8:c6ec6b9f6a55 93 //HAL_RCC_MCOConfig(RCC_MCO2, RCC_MCO2SOURCE_SYSCLK, RCC_MCODIV_1); // output SYSCLOCK to pin PC9 to monitor frequency
kanope_benny 8:c6ec6b9f6a55 94 }
kanope_benny 8:c6ec6b9f6a55 95
kanope_benny 8:c6ec6b9f6a55 96
kanope_benny 8:c6ec6b9f6a55 97
kanope_benny 8:c6ec6b9f6a55 98 int main() {
kanope_benny 8:c6ec6b9f6a55 99
kanope_benny 8:c6ec6b9f6a55 100 setup();
kanope_benny 8:c6ec6b9f6a55 101
kanope_benny 8:c6ec6b9f6a55 102 USBMIDI midi;
kanope_benny 8:c6ec6b9f6a55 103
kanope_benny 8:c6ec6b9f6a55 104
samux 3:7990c80e953c 105 while (1) {
samux 3:7990c80e953c 106 for(int i=48; i<83; i++) { // send some messages!
samux 3:7990c80e953c 107 midi.write(MIDIMessage::NoteOn(i));
samux 3:7990c80e953c 108 wait(0.25);
samux 3:7990c80e953c 109 midi.write(MIDIMessage::NoteOff(i));
samux 3:7990c80e953c 110 wait(0.5);
kanope_benny 8:c6ec6b9f6a55 111 myled = !myled; // LED
samux 3:7990c80e953c 112 }
samux 3:7990c80e953c 113 }
samux 3:7990c80e953c 114 }
kanope_benny 8:c6ec6b9f6a55 115 #endif