Esempio n. 1
0
/**
 * @brief   HAL initialization.
 */
void halInit(void) {

  hal_lld_init();

#if CH_HAL_USE_PAL
  palInit(&pal_default_config);
#endif
#if CH_HAL_USE_ADC
  adcInit();
#endif
#if CH_HAL_USE_CAN
  canInit();
#endif
#if CH_HAL_USE_MAC
  macInit();
#endif
#if CH_HAL_USE_PWM
  pwmInit();
#endif
#if CH_HAL_USE_SERIAL
  sdInit();
#endif
#if CH_HAL_USE_SPI
  spiInit();
#endif
#if CH_HAL_USE_MMC_SPI
  mmcInit();
#endif
}
Esempio n. 2
0
/**
 * @brief   HAL initialization.
 * @details This function invokes the low level initialization code then
 *          initializes all the drivers enabled in the HAL. Finally the
 *          board-specific initialization is performed by invoking
 *          @p boardInit() (usually defined in @p board.c).
 *
 * @init
 */
void halInit(void) {

  hal_lld_init();

#if HAL_USE_TM || defined(__DOXYGEN__)
  tmInit();
#endif
#if HAL_USE_PAL || defined(__DOXYGEN__)
  palInit(&pal_default_config);
#endif
#if HAL_USE_ADC || defined(__DOXYGEN__)
  adcInit();
#endif
#if HAL_USE_CAN || defined(__DOXYGEN__)
  canInit();
#endif
#if HAL_USE_EXT || defined(__DOXYGEN__)
  extInit();
#endif
#if HAL_USE_GPT || defined(__DOXYGEN__)
  gptInit();
#endif
#if HAL_USE_I2C || defined(__DOXYGEN__)
  i2cInit();
#endif
#if HAL_USE_ICU || defined(__DOXYGEN__)
  icuInit();
#endif
#if HAL_USE_MAC || defined(__DOXYGEN__)
  macInit();
#endif
#if HAL_USE_PWM || defined(__DOXYGEN__)
  pwmInit();
#endif
#if HAL_USE_SERIAL || defined(__DOXYGEN__)
  sdInit();
#endif
#if HAL_USE_SDC || defined(__DOXYGEN__)
  //KL All in Kl_sdc sdcInit();
#endif
#if HAL_USE_SPI || defined(__DOXYGEN__)
  spiInit();
#endif
#if HAL_USE_UART || defined(__DOXYGEN__)
  uartInit();
#endif
#if HAL_USE_USB || defined(__DOXYGEN__)
  usbInit();
#endif
#if HAL_USE_MMC_SPI || defined(__DOXYGEN__)
  mmcInit();
#endif
#if HAL_USE_SERIAL_USB || defined(__DOXYGEN__)
  sduInit();
#endif
#if HAL_USE_RTC || defined(__DOXYGEN__)
  rtcInit();
#endif
}
Esempio n. 3
0
int main( void )
{
  WDTCTL = WDTPW + WDTHOLD;

  //Initialisation of the MMC/SD-card
  while (status != 0)                       // if return in not NULL an error did occur and the
                                            // MMC/SD-card will be initialized again 
  {
    status = mmcInit();
    timeout++;
    if (timeout == 150)                      // Try 50 times till error
    {
      //printf ("No MMC/SD-card found!! %x\n", status);
      break;
    }
  }

  while ((mmcPing() != MMC_SUCCESS));      // Wait till card is inserted

  // Read the Card Size from the CSD Register
  cardSize =  mmcReadCardSize();
    
// Clear Sectors on MMC
  for (i = 0; i < 50; i++) buffer[i] = 1;
  mmcWriteSector(0, buffer);                // write a 50 Byte big block beginning at the (aligned) adress

  for (i = 0; i < 50; i++) buffer[i] = 0;
  mmcWriteSector(1, buffer);                // write a 50 Byte big block beginning at the (aligned) adress

  mmcReadSector(0, buffer);                 // read a size Byte big block beginning at the address.
  for (i = 0; i < 50; i++) if(buffer[i] != 0) P1OUT |= 0x01;
  
  mmcReadSector(1, buffer);                 // read a size Byte big block beginning at the address.
  for (i = 0; i < 50; i++) if(buffer[i] != 0) P1OUT |= 0x02;


// Write Data to MMC  
  for (i = 0; i < 50; i++) buffer[i] = i;
  mmcWriteSector(0, buffer);                // write a 50 Byte big block beginning at the (aligned) adress

  for (i = 0; i < 50; i++) buffer[i] = i+64;
  mmcWriteSector(1, buffer);                // write a 50 Byte big block beginning at the (aligned) adress

  mmcReadSector(0, buffer);                 // read a size Byte big block beginning at the address.
  for (i = 0; i < 50; i++) if(buffer[i] != (unsigned char)i) P1OUT |= 0x04;

  mmcReadSector(1, buffer);                 // read a size Byte big block beginning at the address.
  for (i = 0; i < 50; i++) if(buffer[i] != (unsigned char)(i+64)) P1OUT |= 0x08;

  for (i = 0; i < 50; i++)
    mmcReadSector(i, buffer);               // read a size Byte big block beginning at the address.

  mmcGoIdle();                              // set MMC in Idle mode

  while (1);
}
Esempio n. 4
0
void mmcTest(void)
{
	uint32_t sector=0;
	uint8_t buffer[0x200];
	int c;

	// initialize MMC interface
	mmcInit();

	// print new prompt
	rprintf("\r\ncmd>");

	// testing loop
	while(1)
	{
		// check for keypress
		if((c=uartGetByte()) != -1)
		{
			switch(c)
			{
			case 'i':
				// initialize card 
				rprintf("\r\nResetting MMC/SD Card\r\n");
				mmcReset();
				break;
			case 'r':
				// read current sector into buffer
				rprintf("\r\nRead Sector %d\r\n", sector);
				mmcRead(sector, buffer);
				// print buffer contents
				debugPrintHexTable(0x200, buffer);
				break;
			case 'w':
				// write current sector with data from buffer
				rprintf("\r\nWrite Sector %d\r\n", sector);
				mmcWrite(sector, buffer);
				break;
			// move to new sector
			case '+': sector++;		rprintf("\r\nSector = %d", sector); break;
			case '-': sector--;		rprintf("\r\nSector = %d", sector); break;
			case '*': sector+=512;	rprintf("\r\nSector = %d", sector); break;
			case '/': sector-=512;	rprintf("\r\nSector = %d", sector); break;
			case '\r':
			default:
				break;
			}
			// print new prompt
			rprintf("\r\ncmd>");
		}
	}

}
Esempio n. 5
0
/**************************************************************************//**
 * \brief Initialize flash card for communication.
 *
 * Attempt
 *
 * \retval	0	Success
 * \retval	-1	Failure (timeout)
 * \sideeffect	Sets #readOnly if not successful
 *****************************************************************************/
int flashInit()
{
	unsigned int timeout = 0;

	MMC_CD_CONFIG();
	if(!MMC_CARD_PRESENT) return FLASH_NO_CARD;

	for(timeout = 0; timeout < INIT_TIMEOUT; timeout++){ 	// Try initialization up to 50 times
		if(mmcInit() == MMC_SUCCESS) break;		// If it occurs successfully we are done here
	}

	if(timeout >= INIT_TIMEOUT) return FLASH_TIMEOUT;
	else return FLASH_SUCCESS;
}
Esempio n. 6
0
/**
 * @brief   HAL initialization.
 * @details This function invokes the low level initialization code then
 *          initializes all the drivers enabled in the HAL. Finally the
 *          board-specific initialization is performed by invoking
 *          @p boardInit() (usually defined in @p board.c).
 *
 * @init
 */
void halInit(void) {

  /* Initializes the OS Abstraction Layer.*/
  osalInit();

  /* Platform low level initializations.*/
  hal_lld_init();

#if (HAL_USE_PAL == TRUE) || defined(__DOXYGEN__)
  palInit(&pal_default_config);
#endif
#if (HAL_USE_ADC == TRUE) || defined(__DOXYGEN__)
  adcInit();
#endif
#if (HAL_USE_CAN == TRUE) || defined(__DOXYGEN__)
  canInit();
#endif
#if (HAL_USE_DAC == TRUE) || defined(__DOXYGEN__)
  dacInit();
#endif
#if (HAL_USE_EXT == TRUE) || defined(__DOXYGEN__)
  extInit();
#endif
#if (HAL_USE_GPT == TRUE) || defined(__DOXYGEN__)
  gptInit();
#endif
#if (HAL_USE_I2C == TRUE) || defined(__DOXYGEN__)
  i2cInit();
#endif
#if (HAL_USE_I2S == TRUE) || defined(__DOXYGEN__)
  i2sInit();
#endif
#if (HAL_USE_ICU == TRUE) || defined(__DOXYGEN__)
  icuInit();
#endif
#if (HAL_USE_MAC == TRUE) || defined(__DOXYGEN__)
  macInit();
#endif
#if (HAL_USE_PWM == TRUE) || defined(__DOXYGEN__)
  pwmInit();
#endif
#if (HAL_USE_SERIAL == TRUE) || defined(__DOXYGEN__)
  sdInit();
#endif
#if (HAL_USE_SDC == TRUE) || defined(__DOXYGEN__)
  sdcInit();
#endif
#if (HAL_USE_SPI == TRUE) || defined(__DOXYGEN__)
  spiInit();
#endif
#if (HAL_USE_UART == TRUE) || defined(__DOXYGEN__)
  uartInit();
#endif
#if (HAL_USE_USB == TRUE) || defined(__DOXYGEN__)
  usbInit();
#endif
#if (HAL_USE_MMC_SPI == TRUE) || defined(__DOXYGEN__)
  mmcInit();
#endif
#if (HAL_USE_SERIAL_USB == TRUE) || defined(__DOXYGEN__)
  sduInit();
#endif
#if (HAL_USE_RTC == TRUE) || defined(__DOXYGEN__)
  rtcInit();
#endif
#if (HAL_USE_WDG == TRUE) || defined(__DOXYGEN__)
  wdgInit();
#endif

  /* Community driver overlay initialization.*/
#if defined(HAL_USE_COMMUNITY) || defined(__DOXYGEN__)
#if (HAL_USE_COMMUNITY == TRUE) || defined(__DOXYGEN__)
  halCommunityInit();
#endif
#endif

  /* Board specific initialization.*/
  boardInit();

/*
 *  The ST driver is a special case, it is only initialized if the OSAL is
 *  configured to require it.
 */
#if OSAL_ST_MODE != OSAL_ST_MODE_NONE
  stInit();
#endif
}
void main(void) {
	//Turn off the watchdog timer
	WDTCTL = WDTPW + WDTHOLD;

	P1DIR |= LED;
	P1OUT &= ~LED;

	//16MHz
	//Set DCO to 16 MHz calibrated
	DCOCTL = CALDCO_16MHZ;
	BCSCTL1 = CALBC1_16MHZ;

	//Reset SD card by cycling power
	//Credit to Boris Cherkasskiy and his blog post on Launchpad+MMC
	P2DIR |= BIT2;
	P2OUT &= ~BIT2;
	__delay_cycles(1600000);	// 100ms @ 16MHz
	P2OUT |= BIT2;
	__delay_cycles(1600000);	// 100ms @ 16MHz

	//Initialize MMC library
	while (MMC_SUCCESS != mmcInit());
	//Verify card ready
	while (MMC_SUCCESS != mmcPing());
	//Check the memory card size
	volatile unsigned long size = mmcReadCardSize();

	//Toggle the LED to indicate that reading was successful
	P1OUT ^= LED;

	//Test that the SD card is working
	//Read in the OEM name and version in bytes 3-10
	volatile unsigned char block[64] = {0};

	// Read in a 512 byte sector
	// This is a multipart process.
	// First you must mount the block, telling the SD card the relative offset
	// of your subsequent reads. Then you read the block in multiple frames.
	// We do this so we don't need to allocate a full 512 byte buffer in the
	// MSP430's memory. Instead we'll use smaller 64 byte buffers. This
	// means that an entire block will take 8 reads. The spiReadFrame command
	// reads in the given number of bytes into the byte array passed to it.
	// After reading all of the data in the block it should be unmounted.
	//volatile char result = mmcReadBlock(0, 64, block);
	//volatile char result = mmcMountBlock(0, 512);
	volatile char result = mmcMountBlock(0, 512);

	//My FAT partition apparently starts at block 129 (0x81)
	//If you have a FAT16 filesystem you could read data from that point
	//Read in the block 64 bytes at a time
	if (result == MMC_SUCCESS) {
		volatile int i = 0;
		//8 blocks of 64 to read
		for (i = 0; i < 8; ++i) {
			//If you set a breakpoint here you can examine the memory in the card.
			spiReadFrame((void*)block, 64);
		}
		mmcUnmountBlock();
	}

	while (1);
}