Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sd_init_driver() bricking the Pico #54

Closed
mchobby opened this issue Mar 4, 2023 · 2 comments
Closed

sd_init_driver() bricking the Pico #54

mchobby opened this issue Mar 4, 2023 · 2 comments

Comments

@mchobby
Copy link

mchobby commented Mar 4, 2023

Hi,
I'm trying to include the no-OS-FatFS-SD-SPI-RPI-Pico into the Picoterm project .
Constraint: because of the VGA rendering and USB Host (for Keyboard), I cannot use the UART debugging, Neither USB debugging.
So I do send debugging message over GP28 with a PIO TX based uart (see the debug_print() call below in the code).

As current configuration I'm using the standard hw_config configuration together with an Adafruit microSD breakout (for SPI).
The config & wiring are: SO->GP16, CS->GP17, CLK->GP18, SI->GP19,Detect->GP22, 3.3V & GND.

From my main() I do call the test_sdcard() available here below after the sdio_init_all() call.
I can see the message "SD Card driver initializing" then the Pico stops running!
This means that sd_init_driver() does crashed.

The result is the same with an SD inserted and without SD.
Did I miss something obvious ?

void test_sdcard() {
	FRESULT fr;
	FATFS fs;
	FIL fil;
	int ret;
	char buf[100];
	char filename[] = "test02.txt";

	// https://www.digikey.com/en/maker/projects/raspberry-pi-pico-rp2040-sd-card-example-with-micropython-and-cc/e472c7f578734bfd96d437e68e670050
	 debug_print("------BEGIN SDCARD test----");
	 debug_print("SD Card driver initializing");
	 // Initialize SD card
	if (!sd_init_driver()) {
		 debug_print("ERROR: Could not initialize SD card\r\n");
		 return;
	}
	debug_print("SD Card driver initialized"),
	// Mount drive
	fr = f_mount(&fs, "0:", 1);
	if (fr != FR_OK) {
			sprintf( debug_msg, "ERROR: Could not mount filesystem (%d)\r\n", fr);
			debug_print( debug_msg );
			return;
	}

	// Open file for writing ()
	fr = f_open(&fil, filename, FA_WRITE | FA_CREATE_ALWAYS);
	if (fr != FR_OK) {
			sprintf( debug_msg, "ERROR: Could not open file (%d)\r\n", fr);
			debug_print( debug_msg );
			return;
	}

	debug_print("------END OF SDCARD test----");

}
@carlk3
Copy link
Owner

carlk3 commented Mar 5, 2023

I didn't dig into how you've implemented everything, but people have had similar sounding problems with exclusive DMA_IRQ conflicts in the past. (For example, see #8.) If you're using the sdio branch, you could try setting the DMA_IRQ_num in the spi_t instance to DMA_IRQ_1. (It defaults to DMA_IRQ_0.) For example, see https://github.com/carlk3/no-OS-FatFS-SD-SPI-RPi-Pico/blob/sdio/examples/command_line/hw_config.c.

If that's not it, you might have to resort to enabling or adding some printfs. For example, (again, assuming sdio branch), there is a USE_DBG_PRINTF compiler define that you can enable (e.g., uncomment https://github.com/carlk3/no-OS-FatFS-SD-SPI-RPi-Pico/blob/sdio/examples/command_line/CMakeLists.txt#L37).

@evolutional
Copy link

evolutional commented Mar 7, 2023

fwiw I'm using main branch and I get the same problem, soon after calling the init function (and doing nothing else), I get this output over usb serial shortly after.

*** PANIC ***

Hard assert

I can get to the point of mounting the drive, but it also panics soon after.

EDIT: I think you may be right about the DMA IRQ conflict; the panic went away after I disabled the video output. Investigating...

EDIT2: Yes, it was the DMA + assumptions about the channels in use; I changed the qvga video code to claim unused channels and use DMA irq1 and it all works with this lib nicely

@carlk3 carlk3 closed this as completed Jul 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants