Olimex LPC2148 & SFE USB Bootloader

I am currently trying to get Sparkfun’s USB Bootloader code working on a Olimex LPC2148 board. I have successfully gotten the bootloader onto the arm device however the removable drive does not show any files. I believe this is due to the declarations of MOSI, SCK, and MISO. They are currently configured for SPI0 rather than SPI1.

I believe I changed everything necessary to change over to SPI1. Can anyone who has attempted this or has more experience with ARM SPI verify the following changes?

SW_RAW_CONFIG.H

#define SS_PORT_1
#define SPI_SS_PIN	20

//SPI Chip Select Defines for SD Access
#ifdef SS_PORT_1
	#define	SPI_SS_IODIR	IODIR1
	#define	SPI_SS_IOCLR	IOCLR1
	#define	SPI_SS_IOSET	IOSET1  
	#define SPI_SS_IOPIN	IOPIN1
#endif
#ifdef	SS_PORT_0
	#define	SPI_SS_IODIR	IODIR0
	#define	SPI_SS_IOCLR	IOCLR0
	#define	SPI_SS_IOSET	IOSET0
	#define	SPI_SS_IOPIN	IOPIN0
#endif  

/* defines for customisation of sd/mmc port access */
#define configure_pin_mosi() 	PINSEL1 |= (1 << 12)
#define configure_pin_sck() 	PINSEL1 |= (1 << 8)
#define configure_pin_miso() 	PINSEL1 |= (1 << 10)
#define configure_pin_ss() 		SPI_SS_IODIR |= (1<<SPI_SS_PIN)

and SPI.H

#define SS_PORT_1
#define SPI_SS_PIN	20

//SPI Chip Select Defines for SD Access
#ifdef SS_PORT_1
	#define	SPI_SS_IODIR	IODIR1
	#define	SPI_SS_IOCLR	IOCLR1
	#define	SPI_SS_IOSET	IOSET1   
#endif
#ifdef	SS_PORT_0
	#define	SPI_SS_IODIR	IODIR0
	#define	SPI_SS_IOCLR	IOCLR0
	#define	SPI_SS_IOSET	IOSET0
#endif  

//SPI Pin Location Definitions
#define SPI_IODIR      	IODIR1
#define SPI_SCK_PIN    	17       
#define SPI_MISO_PIN   	18        
#define SPI_MOSI_PIN   	19        
		 

#define SPI_PINSEL     		PINSEL1
#define SPI_SCK_FUNCBIT   	8
#define SPI_MISO_FUNCBIT  	10
#define SPI_MOSI_FUNCBIT  	12

#define SPI_PRESCALE_REG  	SSPCPSR

Thats not enough.You must also re-write functions for void sd_raw_send_byte(unsigned char b) and unsigned char sd_raw_rec_byte(void).Oh and dont forget to change select_card() and unselect_card().

Regards.

Changed SD_raw_init()

    /* initialize SPI with lowest frequency; max. 400kHz during identification mode of card */
    //S0SPCCR = 150;  /* Set frequency to 400kHz */
    //S0SPCR = 0x38;
    SSPCPSR = 150;
    SSPCR0 = 0xC7;
    ...
    /* switch to highest SPI frequency possible */
    //S0SPCCR = 60; /* ~1MHz-- potentially can be faster */
    SSPCPSR = 60;

I also made changes to the two other functions that modify the SPI registers. As the SSPSR doesn’t generate an interrupt, I am checking if the Transmit FIFO is Empty.

void sd_raw_send_byte(unsigned char b)
{
    SSPDR = b;
    /* wait for byte to be shifted out */
    while(!(SSPSR & 0x01));
}
unsigned char sd_raw_rec_byte(void)
{
    /* send dummy data for receiving some */
    SSPDR = 0xff;
    while(!(SSPSR & 0x01));

    return SSPDR;
}

I believe select_card() and unselect_card() are modified when defining SS_PORT_1. Please correct me if I am wrong.

Made the following changing in lpc2000_spi.c which does initial initialization of the SPI hardware. Seems a little redundant with sd_raw.c doing the same. Now the device shows up as “USB Device Not Recognized”. I’ll keep hacking it.

//SSPSPCR0 Bit-Definitions
#define CPHA 7
#define CPOL 6
#define MSTR 5

static U8 my_SPISend(U8 outgoing)
{
    //S0SPDR = outgoing;
    //while (!(S0SPSR & (1 << SPIF)));
    //return S0SPDR;
	SSPDR = outgoing;
	while(!(SSPSR & 0x01));
	return SSPDR;
}

void SPIInit(void)
{
...
    // enable SPI-Master
    SSPCR0 = (1 << MSTR) | (0 << CPOL);   // TODO: check CPOL
    SSPCR1 = 0x02;
...
}

U8 SPISend(U8 outgoing)
{
    U8 incoming;

    SELECT_CARD();
    //S0SPDR = outgoing;
    //while (!(S0SPSR & (1 << SPIF)));
    //incoming = S0SPDR;
	SSPDR = outgoing;
	while(!(SSPSR & 0x01));
	incoming = SSPDR;
    UNSELECT_CARD();

    return incoming;
}

void SPISendN(U8 * pbBuf, int iLen)
{
    int i;

    SELECT_CARD();
    for (i = 0; i < iLen; i++)
    {
        //S0SPDR = pbBuf[i];
        //while (!(S0SPSR & (1 << SPIF)));
		SSPDR = pbBuf[i];
		while(!(SSPSR & 0x01));
    }
    UNSELECT_CARD();
}

void SPIRecvN(U8 * pbBuf, int iLen)
{
    int i;

    SELECT_CARD();
    for (i = 0; i < iLen; i++)
    {
        ///S0SPDR = 0xFF;
        //while (!(S0SPSR & (1 << SPIF)));
        //pbBuf[i] = S0SPDR;
		SSPDR = 0xFF;
		while(!(SSPSR & 0x01));
		pbBuf[i] = SSPDR;
    }
    UNSELECT_CARD();
}

Suggestions welcome please.

Erased the flash and rewrote the main.hex image and now the device shows up but still does not show file contents. I believe I changed everything necessary.

Files can be viewed here:

http://gameboydev.org/files/Olimex%2021 … 20Code.zip

I’m interest in change to port SPI1 too. I did changes but it didn’t work. I use your code changes but it didn’t work.

I program your code in my device but when I connect to USB the USB don’t reconize my device.

Your device is working with the port SPI1 ?

I need your help please, thanks for all,

Juan.

Hi Juan,

I never got the SPI1 working with the SD card. However, the code that I posted does show up as an external hard drive. However, when I click on the hard drive nothing shows up. What are you receiving as an output on UART0? I received an “0xFF Unrecognized Device” error but everything else booted correctly. Try double checking your hardware and if it is custom try verifying it with the Olimex LPC2148 schematic.

Just to verify the everything worked on the OLIMEX LPC-P2148, I jumpered SPI0 signals to SPI1 signals which connect to the SD card. Since the SPI1 pins are hi-Z I did not have to cut any connections

SSEL0–>SSEL1

SCK0–>SCK1

MOSI0–>MOSI1

MISO0–>MOSI1

Plugged in the USB cable, drive showed up immediately. I was able to copy files back and forth.

The Bootloader does not work. The bootloader tries to open rootdir and seems to get stuck in an ininite loop

kmeagher:
Just to verify the everything worked on the OLIMEX LPC-P2148, I jumpered SPI0 signals to SPI1 signals which connect to the SD card. Since the SPI1 pins are hi-Z I did not have to cut any connections

SSEL0–>SSEL1

SCK0–>SCK1

MOSI0–>MOSI1

MISO0–>MOSI1

Plugged in the USB cable, drive showed up immediately. I was able to copy files back and forth.

The Bootloader does not work. The bootloader tries to open rootdir and seems to get stuck in an ininite loop

Hi, Would you be interested in posting your SSP SPI1 register settings and related code to init, read and write SPI1??

Sorry for the delay, I just noticed your post. It will take me a few days to get the project back up and then I’ll post it.

Thanks i’m sure that it will help me greatly; so far havent had any success getting the SSP SP1 working with either the LIS3 accelerometer or a NOKIA 6610 LCD. Neil