STM32U575I-EV: While debugging I get an error and this function is called: void HardFault_Handler (void) - debugging

The error is generated in this part of the code and precisely here:
writeVal[j] = RBF1[i+1];
I am attaching the code:
#define _FPGA_UPLOAD_C_
#include "globdefs.h"
extern SPI_HandleTypeDef hspi1;
#define MEMORY_ADDR1 ((uint32_t)0x64000000) //FMC_BANK1_2
const uint8_t RBF1[] ={0xA0,0xFF,0x02,0x6A,0xE7,0x82,0xF7,0x07,0xE7,0xF7,0xE7,0xF1,0xFB,0xF1,0xF9,0x82,0xFB,0x83,0xF9,0x08};
uint16_t* fpgaRegx1 = (uint16_t*)FMC_BANK1_1; // FMC_BANK1_1: 0x60000000UL
int8_t FPGA_Loading(char TypeRBF)
{
HAL_GPIO_WritePin(NCONFIG_CYCLONE_GPIO_Port,NCONFIG_CYCLONE_Pin, GPIO_PIN_RESET);
Delay3micro();
HAL_GPIO_WritePin(NCONFIG_CYCLONE_GPIO_Port,NCONFIG_CYCLONE_Pin, GPIO_PIN_SET);
Delay3micro();
int i=0;
uint8_t* writeVal = (uint8_t*)(MEMORY_ADDR1 + sizeof(RBF1));
uint16_t loadOK = 0;
while (hspi1.State != HAL_SPI_STATE_READY)
{};
while (i < sizeof(RBF1))
{
uint8_t n = RBF1[i] & 0x7f;
if (RBF1[i] & 0x80)
{
for (int j=0; j<n; j++){
writeVal[j] = RBF1[i+1];
}
i += 2;
}
else
{
for (int j=0; j<n; j++)
writeVal[j] = RBF1[i+j+1];
i += (n+1);
}
if(HAL_SPI_Transmit (&hspi1, (uint8_t *) writeVal, n, 100)!=HAL_OK)
{
Error_Handler();
}
}
Delay3micro();
Delay3micro();
HAL_SPI_MspDeInit(&hspi1); //spengo l'spi usata per la programmazione dell'fpga
loadOK = fpgaRegx1[0];
loadOK &= 0xF000;
if (loadOK == (uint16_t)0xA000)
{
loadOK=1;
}
else
{
loadOK=0;
//Error_Handler();
}
return loadOK;
}
I tried to generate a new, simpler project by inserting only the code I entered above and I don't get any errors. At this point I have always added on the new project through CubeIDE FILEX, THREADX and SDMMC1 the latter generates the same error written above. For FILEX, THREADX and SDMMC1 the code is only the one generated by CubeIDE.

Related

Incompatible types in assigmnet of int to char[16] error - Arduino UNO

I've created an array of structs but I'm getting the error written on the title of this question. I'm still new to this so I was wondering if I could get some help.
Code:
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
lcd.begin(16, 2);
i = 0;
}
#define LIMIT 27
struct protocol {
char create[16];
char character;
int values;
int minimum;
int maximum;
};
struct protocol channels[LIMIT];
int i;
void create_channels() {
if (Serial.available() > 0) {
Serial.print("Enter the channel description");
channels[i].create = Serial.read();
Serial.print("Enter the starting character: ");
channels[i].character = Serial.read();
if (i == LIMIT) {
for (i = 0; i < LIMIT; i++)
{
Serial.println(channels[i].create);
Serial.println(channels[i].character);
}
i = 0;
}
}
}
Error:
cw.ino:24:38: error: incompatible types in assignment of 'int' to 'char [16]'
channels[i].create = Serial.read();

Getting an error - "undefined reference to 'logOn(int, int &)'"

I am working on this program (below) and keep getting the "undefined reference to 'logOn(int, int &)'". It also does this when I am calling the functions for logOn, logOff, and search when they are called. My code is not 100% correct, but I am trying to figure out my error before I can move on with the rest of the project.
#include <iostream>#include <iostream>
int menu(int &);
void logOn(int, int &);
int getUserID(int &);
int getLabNum(int &);
int getStation(int &, int &);
void logOff(int, int &);
void search(int, int &);
int main()
{
int userChoice = 0;
menu(userChoice);
int userID = 0;
int lab[4][6];
if (userChoice == 1)
{
logOn(lab[4][6], userID);
}
else if (userChoice == 2)
{
logOff(lab[4][6], userID);
}
else if (userChoice == 3)
{
search(lab[4][6], userID);
}
return 0;
}
And here are the three functions:
void logOn(int lab[4][6], int &userID)
{
int labNum, station = 0;
getUserID(userID);
getLabNum(labNum);
getStation(station, labNum);
int *lab_ptr = &labNum;
int *station_ptr = &station;
int *user_ptr = &userID;
for (int i = 1; i < 5; i++)
{
std::cout << "Lab " << i << ": ";
if (i == 1)
{
for (int j = 1; j < 6; j++)
{
lab[*lab_ptr][*station_ptr] = {*user_ptr};
}
}
}
}
void logOff(int lab[4][6], int &userID)
{
std::cout << "Please enter your student ID: ";
std::cin >> userID;
std::cout << std::endl;
for(int i = 1; i < 5; i++)
{
for(int j = 1; j < 7; j++)
{
if(lab[i][j] == userID)
{
lab[i][j] = 0;
}
}
}
}
void search(int lab[4][6], int &userID)
{
std::cout << "Please enter the User ID you would like to find: ";
std::cin >> userID;
for(int i = 1; i < 5; i++)
{
if (i == 1)
{
for(int j = 1; j < 6; j++)
{
if(lab[i][j] == userID)
{
std::cout << "This user is in lab " << i << " and at station " << j << std::endl;
return;
}
}
}
etc....
I think it has something to do with the lab[4][6] in the headers, but I saw another program with it and it ran with no problem. Any help would be appreciated!

Error with the output of Camera Calibration OPENCV 3.2 with C++ Visual Studio 2015. Cant save output value

i am getting an error when using opencv camera calibration. When i debug my code, it just open the webcam not show the camera calibration value output in Folder Location.
i am using opencv 3.2 with VS 15
My code:
#include "opencv2/core.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/aruco.hpp"
#include "opencv2/calib3d.hpp"
#include <sstream>
#include <iostream>
#include <fstream>
using namespace std;
using namespace cv;
const float calibrationSquareDimension = 0.01905f; //meters
const float arucoSquareDimension = 0.1016f; //meters
const Size chessboardDimensions = Size(9,6);
void createArucoMarkers()
{
Mat outputMarker;
Ptr<aruco::Dictionary> markerDictionary = aruco::getPredefinedDictionary(aruco::PREDEFINED_DICTIONARY_NAME::DICT_4X4_50);
for (int i = 0; i < 50; i++)
{
aruco::drawMarker(markerDictionary, i, 500, outputMarker, 1);
ostringstream convert;
string imageName = "4x4Marker_";
convert << imageName << i << ".jpg";
imwrite(convert.str(), outputMarker);
}
}
void createKnownBoardPosition(Size boardsize, float squareEdgeLength, vector<Point3f>& corners)
{
for (int i = 0; i < boardsize.height; i++)
{
for (int j = 0; j < boardsize.width; j++)
{
corners.push_back(Point3f(j * squareEdgeLength, i * squareEdgeLength, 0.0f));
}
}
}
void getchessboardcorners(vector<Mat> images, vector<vector<Point2f>>& allfoundcorners, bool showresults = false)
{
for (vector<Mat>::iterator iter = images.begin(); iter != images.end(); iter++)
{
vector<Point2f> pointBuf;
bool found = findChessboardCorners(*iter, Size(9, 6), pointBuf, CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_NORMALIZE_IMAGE);
if (found)
{
allfoundcorners.push_back(pointBuf);
}
if (showresults)
{
drawChessboardCorners(*iter, Size(9, 6), pointBuf, found);
imshow("Looking for Corners", *iter);
waitKey(0);
}
}
}
void cameraCalibration(vector<Mat> calibrationImages, Size boardSize, float squareEdgeLength, Mat& cameraMatrix, Mat& distanceCoefficients)
{
vector<vector<Point2f>> checkerboardImageSpacePoints;
getchessboardcorners(calibrationImages, checkerboardImageSpacePoints, false);
vector<vector<Point3f>> worldSpaceCornerPoints(1);
createKnownBoardPosition(boardSize, squareEdgeLength, worldSpaceCornerPoints[0]);
worldSpaceCornerPoints.resize(checkerboardImageSpacePoints.size(), worldSpaceCornerPoints[0]);
vector<Mat> rVectors, tVectors;
distanceCoefficients = Mat::zeros(8, 1, CV_64F);
calibrateCamera(worldSpaceCornerPoints, checkerboardImageSpacePoints, boardSize, cameraMatrix, distanceCoefficients, rVectors, tVectors );
}
bool saveCameraCalibration(string name, Mat cameraMatrix, Mat distanceCoefficients)
{
ofstream outStream(name);
if (outStream)
{
uint16_t rows = cameraMatrix.rows;
uint16_t columns = cameraMatrix.cols;
for (int r = 0; r < rows; r++)
{
for (int c = 0; c < columns; c++)
{
double value = cameraMatrix.at<double>(r, c);
outStream << value << endl;
}
}
rows = distanceCoefficients.rows;
columns = distanceCoefficients.cols;
for (int r = 0; r < rows; r++)
{
for (int c = 0; c < columns; c++)
{
double value = cameraMatrix.at<double>(r, c);
outStream << value << endl;
}
}
outStream.close();
return true;
}
return false;
}
int main(int argv, char** argc)
{
Mat frame;
Mat drawToFrame;
Mat cameraMatrix = Mat::eye(3, 3, CV_64F);
Mat distanceCoefficients;
vector<Mat> savedImages;
vector<vector<Point2f>> markerCorners, rejectedCandidates;
VideoCapture vid(0);
if (!vid.isOpened())
{
return 0;
}
int framesPersecond = 20;
namedWindow("Webcam", CV_WINDOW_AUTOSIZE);
while (true)
{
if (!vid.read(frame))
break;
vector<Vec2f> foundPoints;
bool found = false;
found = findChessboardCorners(frame, chessboardDimensions, foundPoints, CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_NORMALIZE_IMAGE );
frame.copyTo(drawToFrame);
drawChessboardCorners(drawToFrame, chessboardDimensions, foundPoints, found);
if (found)
imshow("Webcam", drawToFrame);
else
imshow("Webcam", frame);
char character = waitKey(1000 / framesPersecond);
switch (character)
{
case ' ':
//saving image
if(found)
{
Mat temp;
frame.copyTo(temp);
savedImages.push_back(temp);
}
break;
case 13:
//start calibration
if (savedImages.size() > 15)
{
cameraCalibration(savedImages, chessboardDimensions, calibrationSquareDimension, cameraMatrix, distanceCoefficients);
saveCameraCalibration("CameraCalibration", cameraMatrix, distanceCoefficients);
}
break;
case 27:
//exit
return 0;
break;
}
}
return 0;
}

ATMega wrong function argument

I am writting firmware for AT90CAN32 using AVR Studio + WinAVR.
It seems simple for experienced AVR programmers.
I pass int argument to function, but inside the function it is always zero.
There is inside protocol.c file:
#include <uart.h>
static char packet[16] = ":AA111122223!f\r\n";
void vDivRequesting(void)
{
uint8_t cntOfBms = getCountOfBms( );
for(uint8_t i=0; i<cntOfBms; i++)
{
createPacket(getBmsNetworkNumber(i), REQUEST_V_DIV, 1);
usartSendString(packet,11);
_delay_ms(200);
}
}
There is uart.c file:
void usartSendString( char *data, uint8_t len )
{
uint8_t i=0;
usartSendByte(len + 0x30);
for( i=0; i<len; i++)
{
usartSendByte(*data);
*data++;
}
}
And it prints me that len argument is zero. usartSendString function is defined in uart.h file. What is wrong with that code?

MFRC 522 with ATmega8. Mifare Classic 1K won't authenticate

I have a problem with an ATmega8 and Mifare RC-522 based NFC/RFID controller.
I'm using this library and I've managed to read the UID of a card.
However, I'd like to also read and write other parts of the card but whenever I try to use the MFRC522_Auth function I don't get the idle interrupt which I should, instead it gives me LoAlertIrq saying that FIFObuffer is almost empty.
Here are the docs for the reader and the card, and below are relevant parts of my code.
main.c :
byte = mfrc522_request(PICC_REQALL,str);
if(byte == CARD_FOUND)
{
byte = mfrc522_get_card_serial(str);
if(byte == CARD_FOUND)
{
byte = mfrc522_auth(PICC_AUTHENT1A, 7, sectorKeyA, str);
if( (byte == CARD_FOUND) )
{
byte = MFRC522_Read1(4, str);
if(byte == CARD_FOUND)
{
//write content of that block
}
}
}
Relevant functions from the library :
void mfrc522_write(uint8_t reg, uint8_t data)
{
ENABLE_CHIP();
spi_transmit((reg<<1)&0x7E);
spi_transmit(data);
DISABLE_CHIP();
}
uint8_t mfrc522_read(uint8_t reg)
{
uint8_t data;
ENABLE_CHIP();
spi_transmit(((reg<<1)&0x7E)|0x80);
data = spi_transmit(0x00);
DISABLE_CHIP();
return data;
}
uint8_t mfrc522_to_card(uint8_t cmd, uint8_t *send_data, uint8_t send_data_len, uint8_t *back_data, uint32_t *back_data_len)
{
uint8_t status = 0;
uint8_t irqEn = 0x00;
uint8_t waitIRq = 0x00;
uint8_t lastBits;
uint8_t n;
uint8_t tmp;
uint32_t i;
switch (cmd)
{
case MFAuthent_CMD: //Certification cards close
{
irqEn = 0x12;
waitIRq = 0x10;
break;
}
case Transceive_CMD: //Transmit FIFO data
{
irqEn = 0x77;
waitIRq = 0x30;
break;
}
default:
break;
}
mfrc522_write(ComIEnReg, irqEn|0x80); //Interrupt request
n=mfrc522_read(ComIrqReg);
mfrc522_write(ComIrqReg,n&(~0x80));//clear all interrupt bits
n=mfrc522_read(FIFOLevelReg);
mfrc522_write(FIFOLevelReg,n|0x80);//flush FIFO data
// mfrc522_write(CommandReg, Idle_CMD); //NO action; Cancel the current cmd???
n=mfrc522_read(CommandReg);
mfrc522_write(CommandReg,n|0x00);
//Writing data to the FIFO
for (i=0; i<send_data_len; i++)
{
mfrc522_write(FIFODataReg, send_data[i]);
}
//Execute the cmd
mfrc522_write(CommandReg, cmd);
if (cmd == Transceive_CMD)
{
n=mfrc522_read(BitFramingReg);
mfrc522_write(BitFramingReg,n|0x80);
}
//Waiting to receive data to complete
i = 2000; //i according to the clock frequency adjustment, the operator M1 card maximum waiting time 25ms???
while (1) {
n = mfrc522_read(ComIrqReg); // ComIrqReg[7..0] bits are: Set1 TxIRq RxIRq IdleIRq HiAlertIRq LoAlertIRq ErrIRq TimerIRq
if (n & waitIRq) { // One of the interrupts that signal success has been set.
break;
}
if (n & 0x01) { // Timer interrupt - nothing received in 25ms
// return 6; //debug purpose
if (cmd == MFAuthent_CMD) {
LCD_Clear();
LCD_WriteTextXY(1, 3, LCD_itoa( mfrc522_read(ComIrqReg) ) );
_delay_ms(2500);
}
break;
}
if (--i == 0) { // The emergency break. If all other condions fail we will eventually terminate on this one after 35.7ms. Communication with the MFRC522 might be down.
if (cmd == MFAuthent_CMD) {
LCD_Clear();
LCD_WriteTextXY(1, 3, LCD_itoa( mfrc522_read(ComIrqReg) ) );
_delay_ms(2500);
}
break;
}
}
tmp=mfrc522_read(BitFramingReg);
mfrc522_write(BitFramingReg,tmp&(~0x80));
if (i != 0)
{
if(!(mfrc522_read(ErrorReg) & 0x1B)) //BufferOvfl Collerr CRCErr ProtecolErr
{
status = CARD_FOUND;
if (n & irqEn & 0x01)
{
status = CARD_NOT_FOUND; //??
}
if (cmd == Transceive_CMD)
{
n = mfrc522_read(FIFOLevelReg);
lastBits = mfrc522_read(ControlReg) & 0x07;
if (lastBits)
{
*back_data_len = (n-1)*8 + lastBits;
}
else
{
*back_data_len = n*8;
}
if (n == 0)
{
n = 1;
}
if (n > MAX_LEN)
{
n = MAX_LEN;
}
//Reading the received data in FIFO
for (i=0; i<n; i++)
{
back_data[i] = mfrc522_read(FIFODataReg);
}
}
}
if (cmd == MFAuthent_CMD) {
LCD_WriteTextXY(1, 10, LCD_itoa16( mfrc522_read(Status2Reg) ) );
_delay_ms(2500);
}
} else status = 9;
return status;
}
uint8_t mfrc522_get_card_serial(uint8_t * serial_out)
{
uint8_t status;
uint8_t i;
uint8_t serNumCheck=0;
uint32_t unLen;
mfrc522_write(BitFramingReg, 0x00); //TxLastBists = BitFramingReg[2..0]
serial_out[0] = PICC_ANTICOLL;
serial_out[1] = 0x20;
status = mfrc522_to_card(Transceive_CMD, serial_out, 2, serial_out, &unLen);
if (status == CARD_FOUND)
{
//Check card serial number
for (i=0; i<4; i++)
{
serNumCheck ^= serial_out[i];
}
if (serNumCheck != serial_out[i])
{
status = ERROR;
}
}
return status;
}
uint8_t mfrc522_auth(uint8_t authMode, uint8_t BlockAddr, uint8_t *Sectorkey, uint8_t *serNum)
{
uint8_t status;
uint32_t recvBits;
uint8_t i;
uint8_t buff[12];
// Validate instruction block address + sector + password + card serial number
buff[0] = authMode;
buff[1] = BlockAddr;
for (i=0; i<6; i++)
{
buff[i+2] = 0xFF /**(Sectorkey+i)*/;
}
for (i=0; i<4; i++)
{
buff[i+8] = *(serNum+i);
}
status = mfrc522_to_card(MFAuthent_CMD, buff, 12, buff, &recvBits);
return status;
}
uint8_t MFRC522_Read1(uint8_t blockAddr, uint8_t *recvData)
{
uint8_t status = 0;
uint8_t unLen, efa;
recvData[0] = PICC_READ;
recvData[1] = blockAddr;
CalculateCRC(recvData, 2, &recvData);
status = mfrc522_to_card(Transceive_CMD, recvData, 4, recvData, &unLen);
if ((status != CARD_FOUND)|| (unLen != 0x90))
{
status = ERROR;
}
return status;
}
uint8_t CalculateCRC(uint8_t *pIndata, uint8_t len, uint8_t *pOutData)
{
uint8_t i, n;
uint8_t status = 0;
n = mfrc522_read(DivIrqReg);
mfrc522_write(DivIrqReg,n&(~0x04)); //CRCIrq = 0
n = mfrc522_read(FIFOLevelReg); //FIFO
mfrc522_write(FIFOLevelReg, n|0x80);
//Write_MFRC522(CommandReg, PCD_IDLE);
// Write data to the FIFO
for (i=0; i<len; i++)
{
mfrc522_write(FIFODataReg, *(pIndata+i));
}
mfrc522_write(CommandReg, CalcCRC_CMD);
// Read the CRC calculation result
i = 0xFF;
while(1){
n = mfrc522_read(DivIrqReg);
if (n & 0x04) {
break;
}
if (--i != 0) {
return 7;
}
}
// Read the CRC calculation result
pOutData[3] = mfrc522_read(CRCResultReg_2);
pOutData[4] = mfrc522_read(CRCResultReg_1);
return status = 0;
}

Resources