2019-04-11 12:43 AM
Dear Members,
I am writing to STM32 flash but application not running ?
I reset it, it's still not responding,
any ideas ? I can read and write to the chip,
thanks
2019-04-12 01:29 AM
this one is right ?
void SystemInit (void)
{
/*!< Set MSION bit */
RCC->CR |= (uint32_t)0x00000100;
/*!< Reset SW[1:0], HPRE[3:0], PPRE1[2:0], PPRE2[2:0], MCOSEL[2:0] and MCOPRE[2:0] bits */
RCC->CFGR &= (uint32_t)0x88FFC00C;
/*!< Reset HSION, HSEON, CSSON and PLLON bits */
RCC->CR &= (uint32_t)0xEEFEFFFE;
/*!< Reset HSEBYP bit */
RCC->CR &= (uint32_t)0xFFFBFFFF;
/*!< Reset PLLSRC, PLLMUL[3:0] and PLLDIV[1:0] bits */
RCC->CFGR &= (uint32_t)0xFF02FFFF;
/*!< Disable all interrupts */
RCC->CIR = 0x00000000;
#ifdef DATA_IN_ExtSRAM
SystemInit_ExtMemCtl();
#endif /* DATA_IN_ExtSRAM */
#ifdef VECT_TAB_SRAM
SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */
#else
SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */
#endif
}
2019-04-12 04:49 AM
this block of code making the system freeze, I have no idea why, but when I take it out from the while loop, it's working
//Mount drive
res = f_mount(&FatFs, "", 1); //1=mount now
if (res != FR_OK) {
printf("f_mount error (%i)\r\n", res);
while(1);
}
DWORD free_clusters, free_sectors, total_sectors;
FATFS* getFreeFs;
res = f_getfree("", &free_clusters, &getFreeFs);
if (res != FR_OK) {
printf("f_getfree error (%i)\r\n", res);
while(1);
}
total_sectors = (getFreeFs->n_fatent - 2) * getFreeFs->csize;
free_sectors = free_clusters * getFreeFs->csize;
printf("SD card stats:\r\n%10lu KiB total drive space.\r\n%10lu KiB available.\r\n", total_sectors / 2, free_sectors / 2);
//Try to open file
res = f_open(&fil, "test.txt", FA_WRITE | FA_CREATE_ALWAYS);
if (res != FR_OK) {
printf("f_open error (%i)\r\n");
while(1);
}
printf("I was able to open 'test.txt' for reading!\r\n");
BYTE readBuf[1024];
//We can either use f_read OR f_gets to get data out of files
//f_gets is a wrapper on f_read that does some string formatting for us
//TCHAR* rres = f_gets((TCHAR*)readBuf, 1024, &fil);
while (f_gets(line, sizeof line, &fil))
printf(line);
/*
if(rres != 0) {
printf("Read string from 'test.txt' contents: %s\r\n", readBuf);
} else {
printf("f_gets error (%i)\r\n", res);
}*/
//Close file, don't forget this!
f_close(&fil);
res = f_open(&fil, "write.txt", FA_WRITE | FA_OPEN_ALWAYS | FA_CREATE_ALWAYS);
if(res == FR_OK) {
printf("I was able to open 'write.txt' for writing\r\n");
} else {
printf("f_open error (%i)\r\n", res);
}
strncpy((char*)readBuf, "a new file is made!", 19);
UINT bytesWrote;
res = f_write(&fil, readBuf, 19, &bytesWrote);
if(res == FR_OK) {
printf("Wrote %i bytes to 'write.txt'!\r\n", bytesWrote);
} else {
printf("f_write error (%i)\r\n");
}
//Close file, don't forget this!
f_close(&fil);
//De-mount drive
f_mount(NULL, "", 0);
//while(1);