Example #1
0
/* StartDefaultTask function */
void StartDefaultTask(void const * argument)
{
  /* init code for FATFS */
  MX_FATFS_Init();

  /* USER CODE BEGIN 5 */
uint8_t sec = 0;
RTC_TimeTypeDef	sTime;
RTC_DateTypeDef	sDate;
char buf[50];
	sprintf(buf, "idle run\r\n");
			HAL_UART_Transmit(&huart1,(uint8_t*)buf,strlen(buf),100);
  /* Infinite loop */
  for(;;)
  {	
		HAL_RTC_GetDate(&hrtc, &sDate, FORMAT_BIN);
		HAL_RTC_GetTime(&hrtc, &sTime, FORMAT_BIN);
		//memset(buf,0,255);
		if(sec != sTime.Seconds){
			sec = sTime.Seconds;
		memset(buf,0,50);
		sprintf(buf, "Date: %02d/%02d/%02d Time: %02d:%02d:%02d\r\n\0", sDate.Date, sDate.Month, 
		sDate.Year, sTime.Hours, sTime.Minutes, sTime.Seconds);
		HAL_UART_Transmit(&huart1,(uint8_t*)buf,strlen(buf),100);
		}
    osDelay(1000);
  }
  /* USER CODE END 5 */ 
}
Example #2
0
int main(void)
{

  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_I2S2_Init();
  MX_SDIO_SD_Init();
  MX_FATFS_Init();

  /* USER CODE BEGIN 2 */
	printf("Init complete");
	//WavePlayerStartSample();
	while((res=f_mount (&fatfs, SD_Path, 1))!=FR_OK)
	{
		printf("QQ");
	}
	WavePlayerStart_DMA("0:/akuno.wav");
	//playindex=rand()%6;
	/*switch(playindex)
	{
		case :
			WavePlayerStart_DMA("0:/test.wav");
			break;
		case 1:
			WavePlayerStart_DMA("0:/akuno.wav");
			break;
		default:
			WavePlayerStart_DMA("0:/akuno.wav");
			break;
	}*/
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */
		//WavePlayerStart_DMA("0:/test.wav");
  }
  /* USER CODE END 3 */

}
Example #3
0
File: main.c Project: MrH2S/periph
/* StartDefaultTask function */
void StartDefaultTask(void const * argument)
{
  /* init code for FATFS */
  MX_FATFS_Init();

  /* USER CODE BEGIN 5 */
  /* Infinite loop */
  for(;;)
  {
    osDelay(1);
  }
  /* USER CODE END 5 */ 
}
Example #4
0
/* StartDefaultTask function */
void StartDefaultTask(void const * argument)
{
  /* init code for FATFS */
  MX_FATFS_Init();

  /* USER CODE BEGIN StartDefaultTask */

    /* Infinite loop */
    for(;;)
    {
        HAL_GPIO_TogglePin(GPIOG, GPIO_PIN_13);
        osDelay(3000);
    }
  /* USER CODE END StartDefaultTask */
}
Example #5
0
void SDCard::init() {
	__HAL_RCC_GPIOC_CLK_ENABLE();
	__HAL_RCC_GPIOD_CLK_ENABLE();

	hsd.Instance = SDIO;
	hsd.Init.ClockEdge = SDIO_CLOCK_EDGE_RISING;
	hsd.Init.ClockBypass = SDIO_CLOCK_BYPASS_DISABLE;
	hsd.Init.ClockPowerSave = SDIO_CLOCK_POWER_SAVE_DISABLE;
	hsd.Init.BusWide = SDIO_BUS_WIDE_1B;
	hsd.Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_DISABLE;
	hsd.Init.ClockDiv = 0;

	MX_FATFS_Init();

	//info("SD card united");
}
int main(void)
{

  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_SPI1_Init();
  MX_USART2_UART_Init();
  MX_FATFS_Init();

  /* USER CODE BEGIN 2 */

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  init();
  while (1)
  {
    loop();
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

  }
  /* USER CODE END 3 */

}
Example #7
0
void system_init(void)
{
    SCB_EnableICache();
    SCB_EnableDCache();

    DBG_INIT();

    init_system_clock();

    HAL_Init();

    BSP_SDRAM_Init();
    BSP_LED_Init(LED1);
    BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_GPIO);

    MX_FATFS_Init();

    FRESULT res = f_mount(&ctx.fs, SD_Path, 0);
    ASSERT_WARN(res == FR_OK);

    gui_init();
}
Example #8
0
int main(void)
{
  uint8_t oldRelease = 0;
  /* USER CODE BEGIN 1 */
  /* USER CODE END 1 */
  /* Enable I-Cache-------------------------------------------------------------*/
  SCB_EnableICache();
  /* Enable D-Cache-------------------------------------------------------------*/
  SCB_EnableDCache();
  /* MCU Configuration----------------------------------------------------------*/
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
  /* Configure the system clock */
  SystemClock_Config();
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_ADC1_Init();
  MX_DMA_Init();
  MX_CAN1_Init();
  MX_CAN2_Init();
  MX_DAC_Init();
  MX_DMA2D_Init();
  MX_FMC_Init();
  MX_I2C2_Init();
  MX_SDMMC1_SD_Init();
  MX_SPI2_Init();
  MX_TIM6_Init();
  MX_TIM7_Init();
  MX_USART2_UART_Init();
  MX_USART3_UART_Init();
  MX_USART6_UART_Init();
  MX_FATFS_Init();
  MX_USB_HOST_Init();
  MX_TIM11_Init();
  MX_TIM13_Init();
  MX_TIM14_Init();

  /* USER CODE BEGIN 2 */
  //MPU_Config(); 
  InitPeriph();
  
  /* USER CODE END 2 */
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while(1){
  /* USER CODE END WHILE */
    MX_USB_HOST_Process();

  /* USER CODE BEGIN 3 */
   RoutineFast(); // get and run deals from medium queue 

   if(oldRelease && Touch_Data.status == TOUCH_RELEASED){
   ReleaseFunction();
   }
   else
   {oldRelease = 1;}
 if(UpdateScreen|| DISP.ReleaseFlag || TimeIsReady){
  Run_GUI();

  Show_GUI();
  UpdateScreen = 0;
  DISP.ReleaseFlag = 0;
  }
    
  }
  /* USER CODE END 3 */

}
Example #9
0
int main(void)
{

  /* USER CODE BEGIN 1 */
	myDaq = new DaqADS1298();
	//printf("Hello\n");
  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  //MX_GPIO_Init();
	myDaq->initGPIO();
  MX_SDIO_SD_Init();
  MX_SPI1_Init();
  MX_SPI2_Init();
  MX_SPI3_Init();
  MX_FATFS_Init();
	
	/* Test SD card module */
	uint32_t wbytes;  /* File write counts */
  uint8_t wtext[] = "text to write logical disk";  /* File write buffer */
	
    if(f_mount(&mynewdiskFatFs, (TCHAR const*)mynewdiskPath, 0) == FR_OK)
    {
      if(f_open(&MyFile, "STM32.TXT", FA_CREATE_ALWAYS | FA_WRITE) == FR_OK)
      {
        if(f_write(&MyFile, wtext, sizeof(wtext), &wbytes) == FR_OK)
        {
          f_close(&MyFile);
        }
      }
    }
	
	
	myDaq->setSpiHandle(&hspi1);
	
	myDaq->setup();
	

  /* USER CODE BEGIN 2 */

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

  }
  /* USER CODE END 3 */

}
Example #10
0
int main(void)
{

  /* USER CODE BEGIN 1 */

//  AxesRaw_t data;
	
	FRESULT res; /* FatFs function common result code */
	uint32_t byteswritten, bytesread; /* File write/read counts */
	char rtext[256]; /* File read buffer */
	
	//	HALL_SENS_PWR_ON;
	//	CLAMP_SENS_PWR_ON;
	
	//	1. SPI1 is for ACC 
	
	
  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_ADC_Init();
  MX_SDIO_SD_Init();
  MX_SPI1_Init();
  MX_SPI2_Init();
  MX_USART1_UART_Init();
  MX_USART2_UART_Init();
  MX_FATFS_Init();
  MX_RTC_Init();

  /* USER CODE BEGIN 2 */
	HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);
	HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 1, RTC_WAKEUPCLOCK_CK_SPRE_16BITS);

  EXTI0_IRQHandler_Config();
//	EXTI13_IRQHandler_Config();
	
//	HAL_DBGMCU_EnableDBGStopMode();


	//HALL_SENS_PWR_ON;
	//CLAMP_SENS_PWR_OFF;
	
	
	// init gpio before!
	UC_2_8V;
 
 
	printf("FW start\r\n");


	LIS3DH_PreInit();
	LIS3DH_SetMode(LIS3DH_NORMAL); 				//reg1
	LIS3DH_SetODR(LIS3DH_ODR_400Hz); 			//reg1
	LIS3DH_SetAxis(LIS3DH_X_ENABLE | LIS3DH_Y_ENABLE | LIS3DH_Z_ENABLE ); //reg1

	//Direct IRQ from watemark and overrun to 1st pin. reg3
	LIS3DH_SetInt1Pin(LIS3DH_CLICK_ON_PIN_INT1_DISABLE 		| 	LIS3DH_I1_INT1_ON_PIN_INT1_DISABLE 	| 	LIS3DH_I1_INT2_ON_PIN_INT1_DISABLE 	| 
										LIS3DH_I1_DRDY1_ON_INT1_DISABLE			| 	LIS3DH_I1_DRDY2_ON_INT1_DISABLE 		| 	LIS3DH_WTM_ON_INT1_ENABLE 					| LIS3DH_INT1_OVERRUN_DISABLE);

	//REG4
	LIS3DH_SetBDU(MEMS_ENABLE);
  LIS3DH_SetFullScale(LIS3DH_FULLSCALE_2);  //reg4

	//REG5
  LIS3DH_FIFOModeEnable(LIS3DH_FIFO_STREAM_MODE);	//Enable store into FIFO reg5
	LIS3DH_Int1LatchEnable(MEMS_ENABLE);
	
	
	//LIS3DH_FIFO_CTRL_REG
	LIS3DH_SetTriggerInt(LIS3DH_TRIG_INT1);
	LIS3DH_SetWaterMark(15); 									// watermark for irq generation from fifo  LIS3DH_FIFO_CTRL_REG

	LIS3DH_ReadFIFO();												// clean FIFO and reset IRQ


while (1) {
	//LIS3DH_GetInt1Src(&resp);
	//printf("INT1SRC %i ", resp);
	
	/*LIS3DH_GetFifoSourceBit(LIS3DH_FIFO_SRC_WTM, &resp);
	printf("WTM %i ", resp);
	
	LIS3DH_GetReg3Bit(LIS3DH_I1_WTM, &resp);
	printf("WMBIT %i ", resp);
	
	LIS3DH_GetFifoSourceFSS(&resp);
	printf("FIFO %i\r\n", resp);
	
	
	//LIS3DH_GetIntCounter(&resp);
	//printf("Interrupts counter=%i\r\n", resp);	
	if (resp > 26) {
		
		//rep:
			//LIS3DH_GetFifoSourceFSS(&resp);
			//printf("> %i recs in FIFO (while)\r\n", resp);
			//HAL_Delay(15);
		//LIS3DH_GetInt1Src(&resp);
/*		rep:
		if(LIS3DH_GetAccAxesRaw(&data)==1){
				LIS3DH_GetFifoSourceBit(LIS3DH_FIFO_SRC_WTM, &resp);
				//printf("X=%6d Y=%6d Z=%6d \r\n", data.AXIS_X, data.AXIS_Y, data.AXIS_Z); 
			printf("  READ WTM%i\r\n", resp);
		} else {
				printf("ER\r\n");
		}
		
		LIS3DH_GetFifoSourceFSS(&resp);
		if (resp > 0) goto rep;
		
		LIS3DH_ResetInt1Latch();
		
		
		LIS3DH_FIFOModeEnable(LIS3DH_FIFO_STREAM_MODE);*/

			LIS3DH_ReadFIFO();
	HAL_Delay(2000);
}
//ENABLE ALL IRQs
//LIS3DH_SetInt1Pin(LIS3DH_CLICK_ON_PIN_INT1_DISABLE | LIS3DH_I1_INT1_ON_PIN_INT1_ENABLE | LIS3DH_I1_INT2_ON_PIN_INT1_ENABLE | LIS3DH_I1_DRDY1_ON_INT1_ENABLE | LIS3DH_I1_DRDY2_ON_INT1_ENABLE | LIS3DH_WTM_ON_INT1_ENABLE | LIS3DH_INT1_OVERRUN_ENABLE);
//LIS3DH_SetInt2Pin(LIS3DH_CLICK_ON_PIN_INT2_DISABLE | LIS3DH_I2_INT1_ON_PIN_INT2_ENABLE | LIS3DH_I2_INT2_ON_PIN_INT2_ENABLE | LIS3DH_I2_BOOT_ON_INT2_ENABLE | LIS3DH_INT_ACTIVE_HIGH);
//	HAL_Delay(2000);
	
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)  {
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */
		
//		if(LIS3DH_GetAccAxesRaw(&data)==1){
//			printf("X=%6d Y=%6d Z=%6d \r\n", data.AXIS_X, data.AXIS_Y, data.AXIS_Z); 
//		} else {
//			printf("ER\r\n");
//		}
		HAL_Delay(50);

		//	lowest_power();		//go to stop. Wakeup on RTC wakeup or 1st or 2d PIN wakeup
  }
	
	
//SDIO FAT PART.
	
	//ENABLE_2_5V;	//DC-DC enable
	SD_PWR_ON;		//Power to SD card
	//INIT SD and CARD after because no power to sd
	
	HAL_Delay(50);
  MX_SDIO_SD_Init();
  MX_FATFS_Init();

/*##-1- FatFS: Link the SD disk I/O driver ##########*/
 
 if(FATFS_LinkDriver(&SD_Driver, SDPath) == 0){
		/* success: set the orange LED on */
		 //HAL_GPIO_WritePin(GPIOG, GPIO_PIN_7, GPIO_PIN_RESET);
		/*##-2- Register the file system object to the FatFs module 
	 
		NB! mout right now!
	 ###*/
		res = f_mount(&SDFatFs, (TCHAR const*)SD_Path, 1) ;
	 
		 if(res != FR_OK){
				 /* FatFs Initialization Error : set the red LED on */
				 printf ("Problem fmount\r\n");
				 while(1);
		 } else {
				/*##-3- Create a FAT file system (format) on the logical drive#*/
				 /* WARNING: Formatting the uSD card will delete all content on the device */
					res = f_mkfs((TCHAR const*)SD_Path, 0, 0);
					if(res != FR_OK){
						 /* FatFs Format Error : set the red LED on */
							printf ("Problem f_mkfs\r\n");
						 while(1);
					} else {
						/*##-4- Create & Open a new text file object with write access#*/
						 if(f_open(&MyFile, "Hello.txt", FA_CREATE_ALWAYS | FA_WRITE) != FR_OK){
								 /* 'Hello.txt' file Open for write Error : set the red LED on */
								 printf ("Problem f_open\r\n");
								 while(1);
						 } else {
								 /*##-5- Write data to the text file ####################*/
								 res = f_write(&MyFile, wtext, sizeof(wtext), (void*)&byteswritten);
									 
								 if((byteswritten == 0) || (res != FR_OK)){
										 /* 'Hello.txt' file Write or EOF Error : set the red LED on */
										 printf ("Problem f_write\r\n");
										 while(1);
								 } else {
									 
										 /*##-6- Successful open/write : set the blue LED on */
										// HAL_GPIO_WritePin(GPIOG, GPIO_PIN_12, GPIO_PIN_RESET);
										 f_close(&MyFile);
									 
										 /*##-7- Open the text file object with read access #*/
										 if(f_open(&MyFile, "Hello.txt", FA_READ) != FR_OK){
												 /* 'Hello.txt' file Open for read Error : set the red LED on */
												//HAL_GPIO_WritePin(GPIOG, GPIO_PIN_10, GPIO_PIN_RESET);
													printf ("Problem f_open\r\n");
												 while(1);
										 } else {
												 /*##-8- Read data from the text file #########*/
												 res = f_read(&MyFile, rtext, sizeof(wtext), &bytesread);
//												 if((strcmp(rtext,wtext)!=0)|| (res != FR_OK)){
//													 /* 'Hello.txt' file Read or EOF Error : set the red LED on */
//													 				 printf ("Problem f_read\r\n");
//													 while(1);
//												 } else {
//													 printf ("FAT operation done OK!\r\n");
													 /* Successful read : set the green LED On */
													 //HAL_GPIO_WritePin(GPIOG, GPIO_PIN_6, GPIO_PIN_RESET);
													 /*##-9- Close the open text file ################*/
													 f_close(&MyFile);
												 }
										 }
								 }
						 }
				 }
		 }
 
 /*##-10- Unlink the micro SD disk I/O driver #########*/
 FATFS_UnLinkDriver(SD_Path);
	
  /* USER CODE END 3 */

}