This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

SPI doesn't work with bootloader

Hi,

I'm creating a simple SPI bootloader without SD for nRF51822 based on this post

The bootloader is connected to Freescale 22F through SPI and it will be without any BLE. The application itself is simple, which is only sending some SPI data back to 22F.

Here's the application:

int main(void)
{
    // Set 16 MHz crystal as our 16 MHz clock source (as opposed to internal RCOSC)
    NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
    NRF_CLOCK->TASKS_HFCLKSTART = 1;
    while(NRF_CLOCK->EVENTS_HFCLKSTARTED == 0)
    {
        // Wait
    }
	
	init_spi();
	
	while (true) {
		spi_tx.data = 123;
		spi_send(spi_tx);
		nrf_delay_us(10);
	}
}

IROM1: start = 0x2000, size = 0x39000 IRAM1: start = 0x20000000, size = 0x8000

The bootloader is also a simple one which will just take the application from 22F through SPI and then write the application into flash. Here's the bootloader code:

__asm void bjump(void)
{
   LDR   R2, [#0x00002000]               ; Get App MSP.
   MSR   MSP, R2                ; Set the main stack pointer to the applications MSP.
   LDR   R3, [#0x00002004]  ; Get application reset vector address.
   BX    R3       ; No return - stack code is now activated only through SVC and plain interrupts.
   ALIGN
}

int main(void)
{
    // Set 16 MHz crystal as our 16 MHz clock source (as opposed to internal RCOSC)
    NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
    NRF_CLOCK->TASKS_HFCLKSTART = 1;
    while(NRF_CLOCK->EVENTS_HFCLKSTARTED == 0)
    {
        // Wait
    }
	init_spi();

#if 1
	int count = 200;
	while (true) {
		spi_tx.data = 234;
		spi_send(spi_tx);
		nrf_delay_us(10);
		count--;
		if(count <= 0) {
			bjump();    // jump #1
		}
	}
#endif
	
	bjump();    // jump #2
	
	init_bootloader();
		
    while (true)
    {   
		... main loop for bootloader communication with SPI

IROM1: start = 0x0, size = 0x1F00 IRAM1: start = 0x20000000, size = 0x8000

Currently, I put two debugging codes (bjump), one at location #1 and one at location #2. If I enabled the code at #1, the bootloading process will work properly. I.e., it will send the "234" data couple of times and then the data got changed to "123" which is coming from the application itself.

However, if I disabled the jump code at #1 and enabled the code at #2, only the "234" was received by 22F. After that, the application seems to stuck at some loop. When I ran the bootloader with debugger, I can see that it executed the jump command and then pass the PC to the application, but cannot debug further since I can only see the assembly code.

What could have I missed here?

Thanks, -- Steven

Related