cancel
Showing results for 
Search instead for 
Did you mean: 

Data not updating on each UART_RxCpltCallback

robotwhisperer
Associate II

I have a 2-board communication project set up with 2 NUCLEO-H753ZI boards, where they communicate over UART. The sender side sends a 22-byte stream of data that is received by the receiver side and gets parsed into data. This data can then be streamed to a PC over Ethernet. 

Inside of the UART_RxCpltCallback, I toggle the Red on-board LED, which gives me the rate at which packets are coming in. Inside the UART_TxCpltCallback I am calling a function that takes the data from the UART buffer, and moves it into a member variable of an object. All this should happen at 2KHz, but for some reason the data is only updating every few seconds, and it is not a specific rate at which it updates, it seems random. The graph might better illustrate what I am talking about. The graph *should* look like a sawtooth waveform. 

robotwhisperer_0-1758220233030.png

The confusing part is that the LEDs work as expected, i.e. those blocks of code that are responsible for getting the data where it needs to be are surely executing, they just don't seem to do the thing I think they are doing. 

AFAIK the receive buffer being used is in a non-cacheable region, so the issue should not be MPU or cache related. 

void MPU_Config(void)
{
  MPU_Region_InitTypeDef MPU_InitStruct = {0};

  /* Disables the MPU */
  HAL_MPU_Disable();

  /** Initializes and configures the Region and the memory to be protected
  */
  MPU_InitStruct.Enable = MPU_REGION_ENABLE;
  MPU_InitStruct.Number = MPU_REGION_NUMBER0;
  MPU_InitStruct.BaseAddress = 0x0;
  MPU_InitStruct.Size = MPU_REGION_SIZE_4GB;
  MPU_InitStruct.SubRegionDisable = 0x87;
  MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
  MPU_InitStruct.AccessPermission = MPU_REGION_NO_ACCESS;
  MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_DISABLE;
  MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
  MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
  MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;

  HAL_MPU_ConfigRegion(&MPU_InitStruct);

  /** Initializes and configures the Region and the memory to be protected
  */
  MPU_InitStruct.Number = MPU_REGION_NUMBER1;
  MPU_InitStruct.BaseAddress = 0x30010000;
  MPU_InitStruct.Size = MPU_REGION_SIZE_64KB;
  MPU_InitStruct.SubRegionDisable = 0x0;
  MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL1;
  MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
  MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;

  HAL_MPU_ConfigRegion(&MPU_InitStruct);

  /** Initializes and configures the Region and the memory to be protected
  */
  MPU_InitStruct.Number = MPU_REGION_NUMBER2;
  MPU_InitStruct.BaseAddress = 0x30020000;
  MPU_InitStruct.Size = MPU_REGION_SIZE_128KB;

  HAL_MPU_ConfigRegion(&MPU_InitStruct);

  /** Initializes and configures the Region and the memory to be protected
  */
  MPU_InitStruct.Number = MPU_REGION_NUMBER3;
  MPU_InitStruct.BaseAddress = 0x30040000;
  MPU_InitStruct.Size = MPU_REGION_SIZE_512B;
  MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
  MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
  MPU_InitStruct.IsBufferable = MPU_ACCESS_BUFFERABLE;

  HAL_MPU_ConfigRegion(&MPU_InitStruct);
  /* Enables the MPU */
  HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);

}

Linked script snippet:

  {
    . = ALIGN(8);
    . = ABSOLUTE(0x30000000);
    *(.RxUsartBuffer)

    . = ALIGN(8);
    . = ABSOLUTE(0x30008000);
    *(.TxBuffer)

    . = ALIGN(8);
    . = ABSOLUTE(0x30010000);
    *(.Adc1Buffer)

    . = ALIGN(8);
    . = ABSOLUTE(0x30014000);
    *(.Adc2Buffer)

    . = ALIGN(8);
    . = ABSOLUTE(0x30018000);
    *(.Adc3Buffer)

    . = ALIGN(8);
    . = ABSOLUTE(0x30040000);
    *(.RxDecripSection)

    . = ALIGN(8);
    . = ABSOLUTE(0x30040100);
    *(.TxDecripSection)

    . = ALIGN(8);
    . = ABSOLUTE(0x30040200);
    *(.Rx_PoolSection)

    . = ALIGN(8);

  } >RAM_D2

and the buffer 

std::array<uint8_t, SerialRxBuffer::kSize> SerialCommunication::rx_buffer_
    __attribute__((section(".RxUsartBuffer")));

 

2 REPLIES 2
TDK
Super User

Where is your code that takes data and translates that into a sawtooth wave that we see? Surely the issue lies in there somewhere.

If you feel a post has answered your question, please click "Accept as Solution".
MNapi
Senior III

The first thing to check:


 UART_TxCpltCallback functions correctly in both DMA and interrupt modes, but it does not operate in blocking mode.


I'm not sure which chip you're using, but I suspect it might be an STM32H series (Cortex-M7). Try disabling all memory protection features and see if that resolves the issue.