Thomas Lyp / DevLibMemoryController

Dependencies:   FastPWM

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "MemoryController.h"
00003 #include "FastPWM.h"
00004 
00005 DigitalOut CE(PA_5);
00006 DigitalOut CLE(PA_6);
00007 DigitalOut ALE(PA_7);
00008 DigitalOut WE(PA_8);
00009 DigitalOut RE(PA_9);
00010 DigitalOut WP(PA_10);
00011 DigitalIn  RDY(PA_3);
00012 
00013 FastPWM PWMTrial(PC_12);
00014 
00015 //Not sure what to do here
00016 
00017 void Error_Handler(void)
00018 {
00019   /* USER CODE BEGIN Error_Handler_Debug */
00020   /* User can add his own implementation to report the HAL error return state */
00021 
00022   /* USER CODE END Error_Handler_Debug */
00023 }
00024 
00025 void SystemClock_Config(void)
00026 {
00027   RCC_OscInitTypeDef RCC_OscInitStruct = {0};
00028   RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
00029 
00030   /** Configure the main internal regulator output voltage
00031   */
00032   __HAL_RCC_PWR_CLK_ENABLE();
00033   __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
00034   /** Initializes the RCC Oscillators according to the specified parameters
00035   * in the RCC_OscInitTypeDef structure.
00036   */
00037   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
00038   RCC_OscInitStruct.HSIState = RCC_HSI_ON;
00039   RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
00040   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
00041   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
00042   RCC_OscInitStruct.PLL.PLLM = 16;
00043   RCC_OscInitStruct.PLL.PLLN = 336;
00044   RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
00045   RCC_OscInitStruct.PLL.PLLQ = 4;
00046   RCC_OscInitStruct.PLL.PLLR = 2;
00047   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
00048   {
00049     Error_Handler();
00050   }
00051   /** Initializes the CPU, AHB and APB buses clocks
00052   */
00053   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
00054                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
00055   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
00056   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
00057   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
00058   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
00059 
00060   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
00061   {
00062     Error_Handler();
00063   }
00064 }
00065 
00066 
00067 DigitalOut led(LED1);
00068 
00069 int main()
00070 {
00071     wait(1);
00072     printf("Program Begin\r\n");
00073     PWMTrial.pulsewidth_ticks(50);
00074     PWMTrial.period_ticks(100);
00075     PWMTrial.write(0.5);
00076     
00077     /*
00078     //Initialize 
00079     PinName DQ[8];
00080     DQ[0] = PA_13;
00081     DQ[1] = PA_14;
00082     DQ[2] = PA_15;
00083     DQ[3] = PB_7;
00084     DQ[4] = PC_13;
00085     DQ[5] = PC_11;
00086     DQ[6] = PA_0;
00087     DQ[7] = PA_1;
00088     
00089     MemoryController mem(CE,CLE,ALE,WE,RE,WP,DQ,RDY);
00090     char *dataOutput;
00091     //Reserve Output Data Space
00092     dataOutput = (char*)malloc(4321 * sizeof(char));
00093     //Set Test Address
00094     mem.Address.col1 = 0x02;
00095     mem.Address.col2 = 0x02;
00096     mem.Address.page = 0x02;
00097     mem.Address.block1= 0x02;
00098     mem.Address.block2= 0x02;
00099     
00100     
00101     //Initialize the device
00102     printf("Reset Being\r\n");
00103     mem.ResetDevice();
00104     printf("ResetComplete\r\n");
00105     wait_us(100);
00106     
00107     //read a page
00108     printf("Bein Page Read\r\n");
00109     dataOutput[0] = 1;
00110     dataOutput[1] = 2;
00111     printf("%i, %i\r\n",dataOutput[0],dataOutput[1]);
00112     mem.ReadPage(mem.Address, dataOutput);
00113     printf("Page Read Complete\r\n");
00114     
00115     printf("Printing Data Values\r\n");
00116     for(int i =0; i<128;i++){
00117         printf("%i\r\n",dataOutput[i]);
00118     }
00119     
00120     for (int i=0; i<128;i++){
00121         dataOutput[i]=i;
00122     }
00123     printf("Program New Values\r\n");
00124     mem.ProgramPage(mem.Address, dataOutput);
00125     for(int i = 0;i<150;i++){
00126         dataOutput[i] = 0;
00127     }
00128     printf("Reading New Values\r\n");
00129     mem.ReadPage(mem.Address,dataOutput);
00130     for(int i =0;i<150;i++){
00131         printf("%i\r\n",dataOutput[i]);    
00132     }
00133     */
00134     //write that page
00135     
00136     //read that page
00137     
00138     //erase that page
00139     
00140     //read that page
00141 
00142 }