Merge pull request #3850 from SimpleInit/master

修复"response+1"导致STM32 HAL库SPI内存非对齐访问的hard fault
This commit is contained in:
Bernard Xiong 2020-09-11 09:15:32 +08:00 committed by GitHub
commit 8ea34bf936
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 0 deletions

View File

@ -233,6 +233,17 @@ static rt_err_t _send_cmd(
} }
else if (type == response_r2) else if (type == response_r2)
{ {
#if defined(__CORTEX_M) && __CORTEX_M == 0
/* initial message */
message.send_buf = RT_NULL;
message.recv_buf = recv_buffer;
message.length = 1;
message.cs_take = message.cs_release = 0;
/* transfer message */
device->bus->ops->xfer(device, &message);
response[1] = recv_buffer[0];
#else
/* initial message */ /* initial message */
message.send_buf = RT_NULL; message.send_buf = RT_NULL;
message.recv_buf = response + 1; message.recv_buf = response + 1;
@ -241,9 +252,24 @@ static rt_err_t _send_cmd(
/* transfer message */ /* transfer message */
device->bus->ops->xfer(device, &message); device->bus->ops->xfer(device, &message);
#endif
} }
else if ((type == response_r3) || (type == response_r7)) else if ((type == response_r3) || (type == response_r7))
{ {
#if defined(__CORTEX_M) && __CORTEX_M == 0
/* initial message */
message.send_buf = RT_NULL;
message.recv_buf = recv_buffer;
message.length = 4;
message.cs_take = message.cs_release = 0;
/* transfer message */
device->bus->ops->xfer(device, &message);
response[1] = recv_buffer[0];
response[2] = recv_buffer[1];
response[3] = recv_buffer[2];
response[4] = recv_buffer[3];
#else
/* initial message */ /* initial message */
message.send_buf = RT_NULL; message.send_buf = RT_NULL;
message.recv_buf = response + 1; message.recv_buf = response + 1;
@ -252,6 +278,7 @@ static rt_err_t _send_cmd(
/* transfer message */ /* transfer message */
device->bus->ops->xfer(device, &message); device->bus->ops->xfer(device, &message);
#endif
} }
else else
{ {