STM32F429DISCOVERY, STM32CUBEIDE 1.12.0 I've created a class for a communication packet. It has global scope. Upon instantiation, the code hard faults.
If I comment out the instantiation, compile and run, then uncomment the instantiation, compile and run, the code will work fine from that point on. But it will not run without hard faulting unless I do the comment / uncomment thing. Here's the code for the class:
class MDIO_Packet
{
public:
short OPCode; // This defines whether the packet is Read, Write or Address assignment.
short TA;
uint32_t PHYAddress;
uint32_t DEVAddress;
uint32_t* Register;
double Packet;
MDIO_Packet(short OpCode, uint32_t PHAddress, uint32_t DVAddress, uint32_t* REGISTER)
{
OPCode = OpCode;
PHYAddress = PHAddress;
DEVAddress = DVAddress;
Register = REGISTER;
}// end Constructor
MDIO_Packet()
{
OPCode = 0x0000;
PHYAddress = 0x0000;
DEVAddress = 0x0000;
*Register = 0x0000;
} // end Constructor
uint32_t Packetize()
{
uint32_t BitMask = 0;
BitMask |= (OPCode << 28);
BitMask |= (PHYAddress << 23);
BitMask |= (DEVAddress << 18);
switch (OPCode)
{
case 0x00:
TA = 0x02;
break;
case 0x01:
TA = 0x02;
break;
case 0x02:
TA = 0x0;
case 0x003:
TA = 0x00; // Binary Z0
break;
} // end switch
BitMask |= (TA << 16);
BitMask |= *Register;
return BitMask;
}// end Packetize
}; // class dismissed
And here is the instantiation:
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_CRC_Init();
MX_DMA2D_Init();
MX_FMC_Init();
MX_I2C3_Init();
MX_SPI5_Init();
MX_TIM1_Init();
MX_USART1_UART_Init();
MX_USB_HOST_Init();
MX_SPI3_Init();
MX_SPI4_Init();
MX_USART6_UART_Init();
MX_TIM2_Init();
/* USER CODE BEGIN 2 */
MDIO_Packet MyPacket;
MyPacket.PHYAddress = 0xc050;
MyPacket.DEVAddress = 1;
/* USER CODE END 2 */