Message Structure inconsistencies
Your message buffer structure is inconsistent with the specification in https://github.com/raspberrypi/firmware/wiki/Mailbox-property-interface AND in your readme https://github.com/bztsrc/raspi3-tutorial/tree/master/04_mailboxes however you're consistent:
your description of the tags is:
0 size of the message in bytes, (x+1)*4 1 MBOX_REQUEST magic value, indicates request message 2-x tags x+1 MBOX_TAG_LAST magic value, indicates no more tags
Where each tag looks like:
n+0. tag identifier n+1. value buffer size in bytes n+2. must be zero n+3. optional value buffer
and then your code message looks like:
mbox[0] = 8*4; // length of the message
mbox[1] = MBOX_REQUEST; // this is a request message
mbox[2] = MBOX_TAG_GETSERIAL; // get serial number command
mbox[3] = 8; // buffer size
mbox[4] = 8;
mbox[5] = 0; // clear output buffer
mbox[6] = 0;
mbox[7] = MBOX_TAG_LAST;
The specification for get serial is:
Get board serial
- Tag: 0x00010004
- Request:
- Length: 0
- Response:
- Length: 8
- Value:
- u64: board serial
shouldn't your message look like:
[0] -> size [1] -> MBOX_REQUEST; [2] -> MOBOX_TAG_GETSERIAL; [3] -> 0; // there is no request data [4] -> MBOX_TAG_LAST
if you need to allocate the space for the response as well (which seems to be required after looking examples?) then it would be: [0] -> size [1] -> MBOX_REQUEST; [2] -> MOBOX_TAG_GETSERIAL; [3] -> 0; // there is no request data [4] -> 8; // response length is 8 bytes [5] -> 0; // first 4 bytes [6] -> 0; // second 4 bytes [7] -> MBOX_TAG_LAST;
This confusion is strengthened in https://github.com/bztsrc/raspi3-tutorial/blob/master/05_uart0/uart.c when you set the clock rate: spec:
Set clock rate
- Tag: 0x00038002
- Request:
- Length: 12
- Value:
- u32: clock id
- u32: rate (in Hz)
- u32: skip setting turbo
- Response:
- Length: 8
- Value:
- u32: clock id
- u32: rate (in Hz)
your code:
mbox[0] = 9*4;
mbox[1] = MBOX_REQUEST;
mbox[2] = MBOX_TAG_SETCLKRATE; // set clock rate
mbox[3] = 12;
mbox[4] = 8;
mbox[5] = 2; // UART clock
mbox[6] = 4000000; // 4Mhz
mbox[7] = 0; // clear turbo
mbox[8] = MBOX_TAG_LAST;
why are you putting 8 in mbox[4]? in this case mbox[4] is n+2 and your read me says:
n+2. must be zero