cancel
Showing results for 
Search instead for 
Did you mean: 

Calling HAL_SRAM_Init() twice ?

ranran
Senior II

Hello,

HAL contains both HAL_SRAM_Init and HAL_NOR_Init.

But what if we have additional memory in PSRAM (FPGA device in our case).

If we register the additional interface with HAL_SRAM_Init , it will call HAL_SRAM_MspInit again , and register again with the same mdma handle mdma_handle.

Isn't it problematic to call HAL_SRAM_Init & HAL_SRAM_MspInit twice ?

Doesn't it mean that we can't use MDMA for both memories at the same time ?

please see code snippet below for HAL_SRAM_MspInit:

void HAL_SRAM_MspInit(SRAM_HandleTypeDef *hsram)
{
...
  __HAL_RCC_FMC_CLK_ENABLE();
....	
  gpio_init_structure.Pin   = GPIO_PIN_7;   
  HAL_GPIO_Init(GPIOB, &gpio_init_structure);
...
    mdma_handle.Init.Request = MDMA_REQUEST_SW;
...
    mdma_handle.Instance = MDMA_Channel1;
 
  __HAL_LINKDMA(hsram, hmdma, mdma_handle);
...  
  HAL_MDMA_DeInit(&mdma_handle);
  HAL_MDMA_Init(&mdma_handle);
...
  HAL_NVIC_SetPriority(MDMA_IRQn, 0x0F, 0);
  HAL_NVIC_EnableIRQ(MDMA_IRQn);   
}

Thanks,

ranran

4 REPLIES 4

It passes you an instance of the structure, check it to make sure you initialize the correct interface.

Bunch of lazy coding in the examples, assume you're going to have to tighten things up based on your own specific use cases.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
ranran
Senior II

Hi Clive,

The SRAM_HandleTypeDef instance which is passed to HAL_SRAM_MspInit for each memory is different of cource.

But did you find in the code snippet above another problematic "lazy" initialization aside of mdma_handle (which obviously should be re-written so that it will use a different instance for each memory) ?

Thanks!

ranran
Senior II

I think that the real problem is that it is using

mdma_handle.Instance = MDMA_Channel1;

which obviosuly can't be used together with another memory.

I haven't find other real problem aside from this, when it is called twice.

Do you think there is any other problem ?

Anyway, I ended up creating additional HAL_FPGA_init.

Thanks.

ranran
Senior II

The problem is that there is only one interrupt for all mdma channels.

void MDMA_IRQHandler(void)
{
    HAL_MDMA_IRQHandler(hsram.hmdma);
  }

Is it some HW limitation ?

Is there a way to solve it or do we need to choose between the 2 memories which one shall be capable of DMAing and which shall not ?

Thanks