Showing results for 
Search instead for 
Did you mean: 

adding a few cases in switch() gives below error "....ANY selector matching ..."


hi there

I have a STM32f030c8t6 which has 64kbyte FLASH. I've compiled my code before and I can see that only 34Kbyte is used.

now I want to develop my code.

I have a timer which interrupts every 4ms. entering timer interrupt, I have a function which is just a switch()/case with 15 cases. when I add 6 more cases I get below error

"...Error: L6406E: No space in execution regions with .ANY selector matching ...."

which is indicting that I do not have enough space in FLASH.

why is that? I mean, the code size was 33Kbytes, how can adding some more cases consume all of FLASH?

Principal III

Compilers tend to create jump tables for switch statements with many cases. If the numerical difference between your cases is large, that table may get huge. Seems like the compiler is not smart enough to find a way out here. Try refactoring your code by using if statements, breaking the code into several switch statements, or fiddling with the compiler options. Looks like you are using a commerical product, so ask the compiler support for specific help.



Chief II

Are those cases currently empty? Or do they call something that pulls in something big?

I tried to write all of my cases(they are 63) using if/else statements. this also gave me that .ANY ERROR...

no it's a PCB board I designed for a process and I use CubeMX and Keil

the cases are invoked every time the switch() variable changes to those cases. i.e




//do something




//do something



here in program I change page_cmd variable so every time it should enter different case

No space for execution regions - free version of keil - Keil forum - Support forums - Arm Community

you can switch to CubeIDE and gcc or optimize your code under 32k.


Change compile options or break the big switch case into several by range to workaround compiler. What happen if using if elsif elseif..... ?

Perhaps it's the secondary effect of the functions and related call trees of the code that are now needed, that the linker had previously dumped via dead code elimination.

Say it had functions using floating point, or sprintf, etc​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

how can I change compiler options? and which options? and change them to what value?

using 63 if elseif elseif s... also give me .ANY error

can you explain a bit more? I didnt get that entirely...