Report
5 years ago.

Move Serial Interrupt function to RAM

Hi everyone,

I am trying to write data in the Flash memory without disabling the UART0 interrupts.

Since the interrupts vector is already moved to the RAM at the first call of NVIC_SetVector (cmsis_nvic.c), I theorically just have to move my interrupt function from Flash to RAM.

Here is how I tried to do it:

uart0 interrupt function

#define NEXT(x)         		((x+1)&BUFFER_SIZE)
#define IS_RX_FULL(rxi,rxo)     (((rxi + 1) & BUFFER_SIZE) == rxo)

char * bs_rx_buffer0;
volatile int bs_rx_in0;
volatile int bs_rx_out0;

void __attribute((section(".data"))) Rx_interrupt_uart0()
{
    uint32_t IRR = LPC_UART0->IIR;
    (void)IRR;
    if(!IS_RX_FULL(bs_rx_in0, bs_rx_out0)){
        bs_rx_buffer0[bs_rx_in0] = LPC_UART0->RBR;
        bs_rx_in0 = NEXT(bs_rx_in0);
    }
}

I bind this function to the UART0 interrupt with

uart0 interrupt binding code

LPC_UART0->IER |= 1;
bs_rx_in0 = 0;
bs_rx_out0 = 0;
bs_rx_buffer0 = new char[BUFFER_SIZE];
func = (uint32_t)Rx_interrupt_uart0;
NVIC_SetVector(UART0_IRQn, func);
NVIC_EnableIRQ(UART0_IRQn);

The used size of .text (Flash) section is actually smaller and .data section is bigger.

However, an erase/write operation still blocks my interruption someway, since I can notice a disturbance in the received characters...

I work with an LPC1768 with LPCXpresso and I compile with gcc.

Do you have an idea of why it doesn't work properly?

Comment on this question

1 Answer

5 years ago.

We use the IAP calls to write to Flash all the time. NXP does not publish the code that is the target of these, and I am happy to let them handle that part of the code.

Their code in that call does run from RAM as the Flash is disabled during the erase/write process. My guess (an educated one) is that the CPU switches back to running from IRC to keep timing constant and probably disables other interrupts. So if the interrupt disable doesn't get you the clock switch probably would.

While I guess the RX FIFO could hold 16 bytes, that may not be enough time when compared to the write operation.

We have had similar situations and just opted for an external serial EEPROM, they are real small SC-70 and real cheap.


You need to log in to post a question