Initial commit
main.cpp@0:bb348c97df44, 2020-09-16 (annotated)
- Committer:
- lypinator
- Date:
- Wed Sep 16 01:11:49 2020 +0000
- Revision:
- 0:bb348c97df44
Added PWM
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lypinator | 0:bb348c97df44 | 1 | #include "mbed.h" |
lypinator | 0:bb348c97df44 | 2 | #include "MemoryController.h" |
lypinator | 0:bb348c97df44 | 3 | #include "FastPWM.h" |
lypinator | 0:bb348c97df44 | 4 | |
lypinator | 0:bb348c97df44 | 5 | DigitalOut CE(PA_5); |
lypinator | 0:bb348c97df44 | 6 | DigitalOut CLE(PA_6); |
lypinator | 0:bb348c97df44 | 7 | DigitalOut ALE(PA_7); |
lypinator | 0:bb348c97df44 | 8 | DigitalOut WE(PA_8); |
lypinator | 0:bb348c97df44 | 9 | DigitalOut RE(PA_9); |
lypinator | 0:bb348c97df44 | 10 | DigitalOut WP(PA_10); |
lypinator | 0:bb348c97df44 | 11 | DigitalIn RDY(PA_3); |
lypinator | 0:bb348c97df44 | 12 | |
lypinator | 0:bb348c97df44 | 13 | FastPWM PWMTrial(PC_12); |
lypinator | 0:bb348c97df44 | 14 | |
lypinator | 0:bb348c97df44 | 15 | //Not sure what to do here |
lypinator | 0:bb348c97df44 | 16 | |
lypinator | 0:bb348c97df44 | 17 | void Error_Handler(void) |
lypinator | 0:bb348c97df44 | 18 | { |
lypinator | 0:bb348c97df44 | 19 | /* USER CODE BEGIN Error_Handler_Debug */ |
lypinator | 0:bb348c97df44 | 20 | /* User can add his own implementation to report the HAL error return state */ |
lypinator | 0:bb348c97df44 | 21 | |
lypinator | 0:bb348c97df44 | 22 | /* USER CODE END Error_Handler_Debug */ |
lypinator | 0:bb348c97df44 | 23 | } |
lypinator | 0:bb348c97df44 | 24 | |
lypinator | 0:bb348c97df44 | 25 | void SystemClock_Config(void) |
lypinator | 0:bb348c97df44 | 26 | { |
lypinator | 0:bb348c97df44 | 27 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; |
lypinator | 0:bb348c97df44 | 28 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; |
lypinator | 0:bb348c97df44 | 29 | |
lypinator | 0:bb348c97df44 | 30 | /** Configure the main internal regulator output voltage |
lypinator | 0:bb348c97df44 | 31 | */ |
lypinator | 0:bb348c97df44 | 32 | __HAL_RCC_PWR_CLK_ENABLE(); |
lypinator | 0:bb348c97df44 | 33 | __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); |
lypinator | 0:bb348c97df44 | 34 | /** Initializes the RCC Oscillators according to the specified parameters |
lypinator | 0:bb348c97df44 | 35 | * in the RCC_OscInitTypeDef structure. |
lypinator | 0:bb348c97df44 | 36 | */ |
lypinator | 0:bb348c97df44 | 37 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; |
lypinator | 0:bb348c97df44 | 38 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; |
lypinator | 0:bb348c97df44 | 39 | RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; |
lypinator | 0:bb348c97df44 | 40 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
lypinator | 0:bb348c97df44 | 41 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; |
lypinator | 0:bb348c97df44 | 42 | RCC_OscInitStruct.PLL.PLLM = 16; |
lypinator | 0:bb348c97df44 | 43 | RCC_OscInitStruct.PLL.PLLN = 336; |
lypinator | 0:bb348c97df44 | 44 | RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; |
lypinator | 0:bb348c97df44 | 45 | RCC_OscInitStruct.PLL.PLLQ = 4; |
lypinator | 0:bb348c97df44 | 46 | RCC_OscInitStruct.PLL.PLLR = 2; |
lypinator | 0:bb348c97df44 | 47 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
lypinator | 0:bb348c97df44 | 48 | { |
lypinator | 0:bb348c97df44 | 49 | Error_Handler(); |
lypinator | 0:bb348c97df44 | 50 | } |
lypinator | 0:bb348c97df44 | 51 | /** Initializes the CPU, AHB and APB buses clocks |
lypinator | 0:bb348c97df44 | 52 | */ |
lypinator | 0:bb348c97df44 | 53 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |
lypinator | 0:bb348c97df44 | 54 | |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; |
lypinator | 0:bb348c97df44 | 55 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
lypinator | 0:bb348c97df44 | 56 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
lypinator | 0:bb348c97df44 | 57 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; |
lypinator | 0:bb348c97df44 | 58 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; |
lypinator | 0:bb348c97df44 | 59 | |
lypinator | 0:bb348c97df44 | 60 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) |
lypinator | 0:bb348c97df44 | 61 | { |
lypinator | 0:bb348c97df44 | 62 | Error_Handler(); |
lypinator | 0:bb348c97df44 | 63 | } |
lypinator | 0:bb348c97df44 | 64 | } |
lypinator | 0:bb348c97df44 | 65 | |
lypinator | 0:bb348c97df44 | 66 | |
lypinator | 0:bb348c97df44 | 67 | DigitalOut led(LED1); |
lypinator | 0:bb348c97df44 | 68 | |
lypinator | 0:bb348c97df44 | 69 | int main() |
lypinator | 0:bb348c97df44 | 70 | { |
lypinator | 0:bb348c97df44 | 71 | wait(1); |
lypinator | 0:bb348c97df44 | 72 | printf("Program Begin\r\n"); |
lypinator | 0:bb348c97df44 | 73 | PWMTrial.pulsewidth_ticks(50); |
lypinator | 0:bb348c97df44 | 74 | PWMTrial.period_ticks(100); |
lypinator | 0:bb348c97df44 | 75 | PWMTrial.write(0.5); |
lypinator | 0:bb348c97df44 | 76 | |
lypinator | 0:bb348c97df44 | 77 | /* |
lypinator | 0:bb348c97df44 | 78 | //Initialize |
lypinator | 0:bb348c97df44 | 79 | PinName DQ[8]; |
lypinator | 0:bb348c97df44 | 80 | DQ[0] = PA_13; |
lypinator | 0:bb348c97df44 | 81 | DQ[1] = PA_14; |
lypinator | 0:bb348c97df44 | 82 | DQ[2] = PA_15; |
lypinator | 0:bb348c97df44 | 83 | DQ[3] = PB_7; |
lypinator | 0:bb348c97df44 | 84 | DQ[4] = PC_13; |
lypinator | 0:bb348c97df44 | 85 | DQ[5] = PC_11; |
lypinator | 0:bb348c97df44 | 86 | DQ[6] = PA_0; |
lypinator | 0:bb348c97df44 | 87 | DQ[7] = PA_1; |
lypinator | 0:bb348c97df44 | 88 | |
lypinator | 0:bb348c97df44 | 89 | MemoryController mem(CE,CLE,ALE,WE,RE,WP,DQ,RDY); |
lypinator | 0:bb348c97df44 | 90 | char *dataOutput; |
lypinator | 0:bb348c97df44 | 91 | //Reserve Output Data Space |
lypinator | 0:bb348c97df44 | 92 | dataOutput = (char*)malloc(4321 * sizeof(char)); |
lypinator | 0:bb348c97df44 | 93 | //Set Test Address |
lypinator | 0:bb348c97df44 | 94 | mem.Address.col1 = 0x02; |
lypinator | 0:bb348c97df44 | 95 | mem.Address.col2 = 0x02; |
lypinator | 0:bb348c97df44 | 96 | mem.Address.page = 0x02; |
lypinator | 0:bb348c97df44 | 97 | mem.Address.block1= 0x02; |
lypinator | 0:bb348c97df44 | 98 | mem.Address.block2= 0x02; |
lypinator | 0:bb348c97df44 | 99 | |
lypinator | 0:bb348c97df44 | 100 | |
lypinator | 0:bb348c97df44 | 101 | //Initialize the device |
lypinator | 0:bb348c97df44 | 102 | printf("Reset Being\r\n"); |
lypinator | 0:bb348c97df44 | 103 | mem.ResetDevice(); |
lypinator | 0:bb348c97df44 | 104 | printf("ResetComplete\r\n"); |
lypinator | 0:bb348c97df44 | 105 | wait_us(100); |
lypinator | 0:bb348c97df44 | 106 | |
lypinator | 0:bb348c97df44 | 107 | //read a page |
lypinator | 0:bb348c97df44 | 108 | printf("Bein Page Read\r\n"); |
lypinator | 0:bb348c97df44 | 109 | dataOutput[0] = 1; |
lypinator | 0:bb348c97df44 | 110 | dataOutput[1] = 2; |
lypinator | 0:bb348c97df44 | 111 | printf("%i, %i\r\n",dataOutput[0],dataOutput[1]); |
lypinator | 0:bb348c97df44 | 112 | mem.ReadPage(mem.Address, dataOutput); |
lypinator | 0:bb348c97df44 | 113 | printf("Page Read Complete\r\n"); |
lypinator | 0:bb348c97df44 | 114 | |
lypinator | 0:bb348c97df44 | 115 | printf("Printing Data Values\r\n"); |
lypinator | 0:bb348c97df44 | 116 | for(int i =0; i<128;i++){ |
lypinator | 0:bb348c97df44 | 117 | printf("%i\r\n",dataOutput[i]); |
lypinator | 0:bb348c97df44 | 118 | } |
lypinator | 0:bb348c97df44 | 119 | |
lypinator | 0:bb348c97df44 | 120 | for (int i=0; i<128;i++){ |
lypinator | 0:bb348c97df44 | 121 | dataOutput[i]=i; |
lypinator | 0:bb348c97df44 | 122 | } |
lypinator | 0:bb348c97df44 | 123 | printf("Program New Values\r\n"); |
lypinator | 0:bb348c97df44 | 124 | mem.ProgramPage(mem.Address, dataOutput); |
lypinator | 0:bb348c97df44 | 125 | for(int i = 0;i<150;i++){ |
lypinator | 0:bb348c97df44 | 126 | dataOutput[i] = 0; |
lypinator | 0:bb348c97df44 | 127 | } |
lypinator | 0:bb348c97df44 | 128 | printf("Reading New Values\r\n"); |
lypinator | 0:bb348c97df44 | 129 | mem.ReadPage(mem.Address,dataOutput); |
lypinator | 0:bb348c97df44 | 130 | for(int i =0;i<150;i++){ |
lypinator | 0:bb348c97df44 | 131 | printf("%i\r\n",dataOutput[i]); |
lypinator | 0:bb348c97df44 | 132 | } |
lypinator | 0:bb348c97df44 | 133 | */ |
lypinator | 0:bb348c97df44 | 134 | //write that page |
lypinator | 0:bb348c97df44 | 135 | |
lypinator | 0:bb348c97df44 | 136 | //read that page |
lypinator | 0:bb348c97df44 | 137 | |
lypinator | 0:bb348c97df44 | 138 | //erase that page |
lypinator | 0:bb348c97df44 | 139 | |
lypinator | 0:bb348c97df44 | 140 | //read that page |
lypinator | 0:bb348c97df44 | 141 | |
lypinator | 0:bb348c97df44 | 142 | } |