ARMmbed / mbed-os

Arm Mbed OS is a platform operating system designed for the internet of things
https://mbed.com
Other
4.68k stars 2.99k forks source link

STM32F091 can't pass argument #13201

Closed pilotak closed 4 years ago

pilotak commented 4 years ago

Description of defect

When running code bellow on F091 there is always following error: functions pass() is the problem, exactly the part where i try to read from data no matter if it's in printf or assigned to a variable.

If this code is run on NUCLEO_F412ZG there is no problem.

++ MbedOS Fault Handler ++

FaultType: HardFault

Context:
R0: 200000C5
R1: 20000280
R2: 9
R3: 80001A3
R4: 200000C4
R5: 0
R6: 0
R7: 0
R8: 0
R9: 0
R10: 0
R11: 0
R12: 0
SP   : 20001C28
LR   : 80001A9
PC   : 8000180
xPSR : 1000000
PSP  : 20001C08
MSP  : 20007FB8
CPUID: 410CC200
Mode : Thread
Priv : Privileged
Stack: PSP

-- MbedOS Fault Handler --

++ MbedOS Error Info ++
Error Status: 0x80FF013D Code: 317 Module: 255
Error Message: Fault exception
Location: 0x8000180
Error Value: 0x20000BAC
Current Thread: main Id: 0x200004FC Entry: 0x8001AA9 StackSize: 0x1000 StackMem: 0x20000C50 SP: 0x20001C28
Next:
main  State: 0x2 Entry: 0x8001AA9 Stack Size: 0x1000 Mem: 0x20000C50 SP: 0x20001C10
Ready:
rtx_idle  State: 0x1 Entry: 0x8001BA5 Stack Size: 0x200 Mem: 0x20000990 SP: 0x20000B50
Wait:
rtx_timer  State: 0x83 Entry: 0x8003371 Stack Size: 0x300 Mem: 0x20000690 SP: 0x20000918
Delay:
For more info, visit: https://mbed.com/s/error?error=0x80FF013D&tgt=NUCLEO_F091RC
-- MbedOS Error Info --

Target(s) affected by this defect ?

NUCLEO_F091RC

Toolchain(s) (name and version) displaying this defect ?

GCC_ARM

What version of Mbed-os are you using (tag or sha) ?

a6207cadad0acd1876f436dc6baeddf46c42af06

What version(s) of tools are you using. List all that apply (E.g. mbed-cli)

mbed-cli

How is this defect reproduced ?

#include "mbed.h"
unsigned char packet[3] = {0, 1, 2};

void pass(const unsigned char *data) {
    printf("pass: %u\n", *(unsigned short *)(data + 1));
}

void test() {
    printf("test: %u\n", *(unsigned short *)(packet + 1));
    pass(packet);
}

int main() {
    test();
    return 0;
}
0xc0170 commented 4 years ago

Additional details:

NUCLEO_F091RC is Cortex-M0 and NUCLEO_F412ZG is Cortex M4F.

Can you test std library (see https://github.com/ARMmbed/mbed-os/blob/master/platform/source/minimal-printf/README.md) to confirm this is an issue with minimal printf implementation?

pilotak commented 4 years ago

It's not related to printf (although i have tried "target.printf_lib": "std" as well)

If I alter the code to following, the error is still there

void pass(const unsigned char *t) {
    unsigned short var = *(unsigned short *)(t + 1);

    if (var == 1) {
        printf("yes\n");

    } else {
        printf("no\n");
    }
}
ciarmcom commented 4 years ago

@pilotak thank you for raising this issue.Please take a look at the following comments:

We cannot automatically identify a release based on the version of Mbed OS that you have provided. Please provide either a single valid sha of the form #abcde12 or #3b8265d70af32261311a06e423ca33434d8d80de or a single valid release tag of the form mbed-os-x.y.z . E.g. 'mbed-os-99.99.99' signifies master branch and is not a unique single snapshot. NOTE: If there are fields which are not applicable then please just add 'n/a' or 'None'.This indicates to us that at least all the fields have been considered. Please update the issue header with the missing information, the issue will not be mirroredto our internal defect tracking system or investigated until this has been fully resolved.

0xc0170 commented 4 years ago

I see now.

You are getting a hard fault but due to misaligned access. Cortex M3/M4 tolerate it, but M0 does not. You have 8bit buffer but accessing it via casting to 16bit pointer. Check The Definitive Guide to the ARM Cortex-M0 , page 83 for details.

I'll close this as resolved.

pilotak commented 4 years ago

Ok, thank you I did know that