Loading...
 

SW4STM32 and SW4Linux fully supports the STM32MP1 asymmetric multicore Cortex/A7+M4 MPUs

   With System Workbench for Linux, Embedded Linux on the STM32MP1 family of MPUs from ST was never as simple to build and maintain, even for newcomers in the Linux world.
And, if you install System Workbench for Linux in System Workbench for STM32 you can seamlessly develop and debug asymmetric applications running partly on Linux, partly on the Cortex-M4.
You can get more information from the ac6-tools website and download two short videos (registration required) highlighting:

System Workbench for STM32


No break at the end of case

The following code produced the warning, “No break at the end of case.
If default: is removed the warning goes away.
I do not believe that System Wrokbench should complain as the code is legal syntax.


case USB_REQ_TYPE_STANDARD:
switch (req->bRequest)
{
case USB_REQ_GET_INTERFACE :
USBD_CtlSendData (pdev,
&ifalt,
1);
break;

case USB_REQ_SET_INTERFACE :
break;
}

default:

break;

Your terminating } should be after the final break in your code snippet :-)
Looks like a nested switch to me.

A couple of internet reference sites like this one say that default is just like case, it can be placed aywhere in the switch.

http://www.c4learn.com/c-programming/c-switch-case-rules/Question

The full function is below.

This is from the bottom of STM example code, usbd_cdc.c.

static uint8_t USBD_CDC_Setup (USBD_HandleTypeDef *pdev,
USBD_SetupReqTypedef *req)
{
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
static uint8_t ifalt = 0;

switch (req->bmRequest & USB_REQ_TYPE_MASK)
{
case USB_REQ_TYPE_CLASS :
if (req->wLength)
{
if (req->bmRequest & 0x80)
{
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest,
(uint8_t *)hcdc->data,
req->wLength);
USBD_CtlSendData (pdev,
(uint8_t *)hcdc->data,
req->wLength);
}
else
{
hcdc->CmdOpCode = req->bRequest;
hcdc->CmdLength = req->wLength;

USBD_CtlPrepareRx (pdev,
(uint8_t *)hcdc->data,
req->wLength);
}

}
else
{
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest,
(uint8_t*)req,
0);
}
break;

case USB_REQ_TYPE_STANDARD:
switch (req->bRequest)
{
case USB_REQ_GET_INTERFACE :
USBD_CtlSendData (pdev,
&ifalt,
1);
break;

case USB_REQ_SET_INTERFACE :
break;
}

// deafult was commented out as System Workbench issued a warning about no break at the end of case
// default:

break;
}
return USBD_OK;
}


France

Hi everybody,

Effectively, the break at the end of a case is optional, and the code will just continue in the next case alternative; this may even be useful in some situations, avoiding to duplicate code.

However it is widely considered as bad practice to fall from a specific case alternative to the default alternative or to omit the break at the end of the last case of a switch; this is the reason of the warning emitted here.

This warning is emitted as it is quite current that a forgotten break, at the end of the last case of a switch, if additional cases are subsequently added will, by error, fall down into the added alternative.

In the example given what is really needed is having a break before the default; suppressing the default is a bad idea that only works because the default alternative is empty. Furthermore static code analyzers will likely consider an error to have a break without a default, so the inner switch may also need a default alternative, that, as Richard states, may be placed anywhere in the switch body (although it is customary to place it either at end or at beginning of the switch).

Bernard


I think the compiler is correct, there is no break at the end of your “case USB_REQ_TYPE_STANDARD:”
If you gave a proper indentation to your code, you could see it right away.
Even if it looks redundant, I recommend to keep it, the compiler will optimize it anyway.
Having no default is not a good practice either, as it is adviced to catch all possible cases.

the last lines of the function should be:
...
..case USB_REQ_TYPE_STANDARD:
....switch (req->bRequest)
....{ ...}
....break; // end of USB_REQ_TYPE_STANDARD case
..default:
....break;
..}
..return USBD_OK;
}


Actually the code is properly indented, you just can’t see the indentation in this moronically broken forum software that OpenSTM32 have chosen to use.
What’s up with the double set of scroll bars to the right as well?

Seriously, if you’re gonna do a compiler code formum you should seriously choose forum software that facilitates the same. And for what it’s worht, STM is the same way, their forums could almost be considered as worse.

France

Hi Richard,

when you want to post code on a forum, you must warn the forum software that it is code; on the OpenSTM32 forum you just have to bracket your code between

{CODE(colors="language")} and {CODE}

For example:

{CODE(colors="clike" ln="1")} 
case USB_REQ_TYPE_STANDARD:
	switch (req->bRequest)
	{
		case USB_REQ_GET_INTERFACE :
			USBD_CtlSendData (pdev, &ifalt, 1);
			break;
		case USB_REQ_SET_INTERFACE :
			break;
	}

default:
	break; 
{CODE}

Will produce:

case USB_REQ_TYPE_STANDARD:
	switch (req->bRequest)
	{
		case USB_REQ_GET_INTERFACE :
			USBD_CtlSendData (pdev, &ifalt, 1);
			break;
		case USB_REQ_SET_INTERFACE :
			break;
	}

default:
	break;

Note that currently the C syntax coloring is not yet working but it will in the future...

I admit the syntax may not be the most intuitive (especially you sould not forget the parentheses in the opening tag, even if you don’t provide any parameters) but it is quite simple anyway.

Bernard