Hi
STM32F4, MDK, CMSIS SPI.
I have a uSD card on SPI5. I also have some other devices on SPI5. The uSD/FS and these devices may be accessed from differing tasks creating a resource locking requirement. Within the context of the FS also being on SPI5, can anyone advise how to talk to SPI devices such that the SPI lib manages resource locking?
At the moment I am accessing the devices by the following code.... HAL_GPIO_WritePin(GPIOH, GPIO_PIN_4, GPIO_PIN_RESET); //CS pSPI->Send(buffer, 6); HAL_GPIO_WritePin(GPIOH, GPIO_PIN_4, GPIO_PIN_SET); //CS
The problem is that: (a) I do not know if the driver->Send locks the SPI resource so that nothing else can use it (I believe it may do from browsing the FS code) (b) even if it did I am driving the CS line before I use the ->Send which is a conflict
I can add locking by implementing new fread, fwrite etc to add locking around fread (etc). I can also add locking on the callback the FS allows to set/reset the uSD CS. However, I am hoping someone tells me "no need, this is already a part of this system by doing.....". Something like this pSPI->Lock(); HAL_GPIO_WritePin(GPIOH, GPIO_PIN_4, GPIO_PIN_RESET); //CS pSPI->Send(buffer, 6); HAL_GPIO_WritePin(GPIOH, GPIO_PIN_4, GPIO_PIN_SET); //CS pSPI->Unlock();
or pSPI->Control(ARM_SPI_LOCK); HAL_GPIO_WritePin(GPIOH, GPIO_PIN_4, GPIO_PIN_RESET); //CS pSPI->Send(buffer, 6); HAL_GPIO_WritePin(GPIOH, GPIO_PIN_4, GPIO_PIN_SET); //CS pSPI->Control(ARM_SPI_UNLOCK);
But, it seems, ->Lock or ->Control(AMR_SPI_LOCK) do not exist. Anyone have another way of doing this that may be implemented.
Thanks Mark
As shown here: www.danlhenry.com/.../keil_code.png
At the moment I am accessing the devices by the following code....
HAL_GPIO_WritePin(GPIOH, GPIO_PIN_4, GPIO_PIN_RESET); //CS pSPI->Send(buffer, 6); HAL_GPIO_WritePin(GPIOH, GPIO_PIN_4, GPIO_PIN_SET); //CS
I can add locking by implementing new fread, fwrite etc to add locking around fread (etc). I can also add locking on the callback the FS allows to set/reset the uSD CS. However, I am hoping someone tells me "no need, this is already a part of this system by doing.....". Something like this
pSPI->Lock(); HAL_GPIO_WritePin(GPIOH, GPIO_PIN_4, GPIO_PIN_RESET); //CS pSPI->Send(buffer, 6); HAL_GPIO_WritePin(GPIOH, GPIO_PIN_4, GPIO_PIN_SET); //CS pSPI->Unlock();
or
pSPI->Control(ARM_SPI_LOCK); HAL_GPIO_WritePin(GPIOH, GPIO_PIN_4, GPIO_PIN_RESET); //CS pSPI->Send(buffer, 6); HAL_GPIO_WritePin(GPIOH, GPIO_PIN_4, GPIO_PIN_SET); //CS pSPI->Control(ARM_SPI_UNLOCK);
You can check SPI Multi-Slave driver wrapper from the ARM::CMSIS-Driver pack (current version is 2.3.0).
Multi-Slave wrapper connects to the actual SPI driver and exports multiple SPI drivers which can be used from the application. Wrapper is limited to SPI master functionality but provides multi thread protection. From what you described I think it should suit your needs.
Pack documentation also contains simple master to multi-slave example implementation.