This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

I need help with converting any example from Keil to SES

Hello,

I've been trying for days to convert any example from Keil to SES, I have road probably every question here on the dev zone but I am unable to fix this, I ever specially install windows on my mac to try if there it would work.

So, I have done everything from official nordic documents, I've been through several problems which I happily solve, but that I'm not able to.

I get those errors:


unplaced section: .log_dynamic_data_app [nrf_log_frontend.o], size=12, align=4

undefined symbol: __SRAM_segment_end__

undefined symbol: __start_log_const_data

undefined symbol: __start_log_dynamic_data

undefined symbol: __stop_log_const_data

I'm working on latest SEGGER, I have tried latest SDK, also 14.2 . The same errors. 

Thanks for reply

Parents
  • It seems like you are not using the correct startup code.  Startup code and linker scripts are different.  Startup code and linker script go in pair. You need to use the one made for SES.

  • Hey, I have followed instructions from here https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/segger-embedded-studio-a-cross-platform-ide but its a little bit outdated since now there is SES 4.50.

    Maybe there is a tutorial of how to rewrite programs from Keil to SES? Please like, I have spent so much hours for that, everyone seems get it done, and I am unable to transfer even Blinky example... 

  • Okay thanks, so what else could be causing the bool res = HardwareInit(); error? Something in the code? or connection mpu9250 to dev board? 

    Maybe there is a way to check whether dev board sees mpu9250 or not? 

  • Well, you have the debugger setup and running. Just step through and you will what happens.

  • Okay I will be trying, thanks.

    I have one question also,

    Can you explain me this lines 4 and 5? 

    static const I2CCFG s_I2cCfg = {
    	0,			// I2C device number
    	{
    		{I2C0_SDA_PORT, I2C0_SDA_PIN, I2C0_SDA_PINOP, IOPINDIR_BI, IOPINRES_PULLUP, IOPINTYPE_OPENDRAIN},
    		{I2C0_SCL_PORT, I2C0_SCL_PIN, I2C0_SCL_PINOP, IOPINDIR_OUTPUT, IOPINRES_PULLUP, IOPINTYPE_OPENDRAIN},
    	},
    	115200,	    // Rate
    	I2CMODE_MASTER,
    	5,			// Retry
    	0,			// Number of slave addresses
    	{0,},		// Slave addresses
    	true,	    // DMA
    	false,		// Use interrupt
    	7,			// Interrupt prio
    	NULL		// Event callback
    };


    Especially this:
    I2C0_SDA_PORT, I2C0_SDA_PIN, I2C0_SDA_PINOP

    and

    I2C0_SCL_PORT, I2C0_SCL_PIN, I2C0_SCL_PINOP

    Because those are declared in board.h for board BLUEIO_TAG_BME680_PROTO

    here:

    //#define BLUEIO_TAG_BME680_PROTO
    #ifdef BLUEIO_TAG_BME680_PROTO
    #define I2C0_SDA_PORT					BLUEIO_TAG_BME280_I2C_SDA_PORT
    #define I2C0_SDA_PIN					BLUEIO_TAG_BME280_I2C_SDA_PIN
    #define I2C0_SDA_PINOP					BLUEIO_TAG_BME280_I2C_SDA_PINOP
    #define I2C0_SCL_PORT					BLUEIO_TAG_BME280_I2C_SCL_PORT
    #define I2C0_SCL_PIN					BLUEIO_TAG_BME280_I2C_SCL_PIN
    #define I2C0_SCL_PINOP					BLUEIO_TAG_BME280_I2C_SCL_PINOP
    #else
    #define I2C0_SDA_PORT					BLUEIO_TAG_BME680_I2C_SDA_PORT
    #define I2C0_SDA_PIN					BLUEIO_TAG_BME680_I2C_SDA_PIN
    #define I2C0_SDA_PINOP					BLUEIO_TAG_BME680_I2C_SDA_PINOP
    #define I2C0_SCL_PORT					BLUEIO_TAG_BME680_I2C_SCL_PORT
    #define I2C0_SCL_PIN					BLUEIO_TAG_BME680_I2C_SCL_PIN
    #define I2C0_SCL_PINOP					BLUEIO_TAG_BME680_I2C_SCL_PINOP
    #endif


    Why I am using some ports from different board than mine and bee 680 sensor for I2C configuration? Is this a must? Or I can delete it? Or change it anyway to be assigned to my board nrf 52 dk?


    And also this lines:
    //#include "sensor.h"
    //#define AK0991x_DEFAULT_I2C_ADDR	0x0C	/* The default I2C address for AK0991x Magnetometers */
    //#define AK0991x_SECONDARY_I2C_ADDR  0x0E    /* The secondary I2C address for AK0991x Magnetometers */


    Do I need to delete "//" and enable it? Or as I assume can I delete  it? Because mpu9250 has AK8963 magnetometer not a AK0991x.

  • That is the pins setting for the I2C and board.h is where you assign the pins for your board.  The example I created is for my boards. You define what ever your board is.

    also you rate setting is wrong, 115200 is uart rate.  For I2C try 100000 for 100KHz.

  • I have changed the rate settings thanks for that.

    I was trying to find out how to assign pins to my board but I have not idea. But For sure my board sees MPU9250 at adress 0x68 at pins 26,27 because I flashed twi_scanner example and got message that communication is or right.

    I've been looking on the internet for a while, and I really don't know what to do next, the code seems fine, the mpu9250 is connected to the right pins, but still failure to initialize hardware. It looks like the code do not listen to the right pins or something. 

    What would you recommend? I was also trying to debug it, but I don't know in what place should I look.

Reply
  • I have changed the rate settings thanks for that.

    I was trying to find out how to assign pins to my board but I have not idea. But For sure my board sees MPU9250 at adress 0x68 at pins 26,27 because I flashed twi_scanner example and got message that communication is or right.

    I've been looking on the internet for a while, and I really don't know what to do next, the code seems fine, the mpu9250 is connected to the right pins, but still failure to initialize hardware. It looks like the code do not listen to the right pins or something. 

    What would you recommend? I was also trying to debug it, but I don't know in what place should I look.

Children
  • Check if that pin is not used for other thing in your code and check also it is assigned only to the I2C.

    I see in your snippet code that you didn't assign the pins to the I2C.

    Assign pins

    #define I2C0_SDA_PORT					0
    #define I2C0_SDA_PIN					26
    #define I2C0_SDA_PINOP					1
    #define I2C0_SCL_PORT					0
    #define I2C0_SCL_PIN					27
    #define I2C0_SCL_PINOP					1
    

  • I defined them like you said already, but still it's not working.


    I attach you my board.h and mot_sensor_demo.cpp maybe you will find something, and as you can see those pins are assign only for the I2C. 

    board.h

    #ifndef __BOARD_H__
    #define __BOARD_H__
    
    #include "nrf.h"
    
    #define UART_TX_PIN					9
    #define UART_RX_PIN					11
    #define UART_RTS_PIN			    8
    #define UART_CTS_PIN				10
    
    #define I2C0_SDA_PORT				0
    #define I2C0_SDA_PIN				26
    #define I2C0_SDA_PINOP				1
    #define I2C0_SCL_PORT				0
    #define I2C0_SCL_PIN				27
    #define I2C0_SCL_PINOP				1
    
    #endif // __BOARD_H__


    mot_sensor_demo.cpp
    #include <stdio.h>
    #include <atomic>
    #include <inttypes.h>
    
    #include "nrf.h"
    #include "coredev/iopincfg.h"
    #include "coredev/i2c.h"
    #include "coredev/uart.h"
    #include "iopinctrl.h"
    #include "timer_nrf5x.h"
    #include "sensors/agm_mpu9250.h"
    #include "imu/imu_mpu9250.h"
    #include "stddev.h"
    #include "timer_nrf5x.h"
    #include "idelay.h"
    
    
    #define MPU9250
    #include "board.h"
    
    std::atomic<bool> g_bTest(false);
    
    void TimerHandler(Timer *pTimer, uint32_t Evt);
    
    const static TIMER_CFG s_TimerCfg = {
        .DevNo = 0,
    	.ClkSrc = TIMER_CLKSRC_DEFAULT,
    	.Freq = 0,			// 0 => Default highest frequency
    	.IntPrio = 1,
    	.EvtHandler = TimerHandler,
    };
    
    TimerLFnRF5x g_Timer;
    
    
    //********** I2C **********
    static const I2CCFG s_I2cCfg = {
    	0,			// I2C device number
    	{
    		{I2C0_SDA_PORT, I2C0_SDA_PIN, I2C0_SDA_PINOP, IOPINDIR_BI, IOPINRES_PULLUP, IOPINTYPE_OPENDRAIN},
    		{I2C0_SCL_PORT, I2C0_SCL_PIN, I2C0_SCL_PINOP, IOPINDIR_OUTPUT, IOPINRES_PULLUP, IOPINTYPE_OPENDRAIN},
    	},
    	100000,	    // Rate
    	I2CMODE_MASTER,
    	5,			// Retry
    	0,			// Number of slave addresses
    	{0,},		// Slave addresses
    	true,	    // DMA
    	false,		// Use interrupt
    	7,			// Interrupt prio
    	NULL		// Event callback
    };
    
    I2C g_I2c;
    
    DeviceIntrf *g_pIntrf = &g_I2c;
    
    
    
    
    static const ACCELSENSOR_CFG s_AccelCfg = {
    	.DevAddr = MPU9250_I2C_DEV_ADDR0,
    	.OpMode = SENSOR_OPMODE_CONTINUOUS,
    	.Freq = 1000,
    	.Scale = 2,
    	.FltrFreq = 0,
    	.bInter = true,
    	.IntPol = DEVINTR_POL_LOW,
    };
    
    static const GYROSENSOR_CFG s_GyroCfg = {
    	.DevAddr = MPU9250_I2C_DEV_ADDR0,
    	.OpMode = SENSOR_OPMODE_CONTINUOUS,
    	.Freq = 50000,
    	.Sensitivity = 10,
    	.FltrFreq = 200,
    };
    
    static const MAGSENSOR_CFG s_MagCfg = {
    	.DevAddr = MPU9250_I2C_DEV_ADDR0,
    	.OpMode = SENSOR_OPMODE_CONTINUOUS,
    	.Freq = 50000,
    	.Precision = MAGSENSOR_PRECISION_HIGH,
    };
    
    void ImuEvtHandler(Device * const pDev, DEV_EVT Evt);
    
    static const IMU_CFG s_ImuCfg = {
    	.EvtHandler = ImuEvtHandler
    };
    
    
    ImuMpu9250 g_Imu;
    AgmMpu9250 g_MotSensor;
    
    AccelSensor *g_pAccel = NULL;
    GyroSensor *g_pGyro = NULL;
    MagSensor *g_pMag = NULL;
    
    uint32_t g_DT = 0;
    static uint32_t g_TPrev = 0;
    
    void TimerHandler(Timer *pTimer, uint32_t Evt)
    {
        if (Evt & TIMER_EVT_TRIGGER(0))
        {
        }
    }
    
    void ImuEvtHandler(Device * const pDev, DEV_EVT Evt)
    {
    	ACCELSENSOR_DATA accdata;
    	IMU_QUAT quat;
    
    	switch (Evt)
    	{
    		case DEV_EVT_DATA_RDY:
    			g_MotSensor.Read(accdata);
    			g_Imu.Read(accdata);
    			printf("Accel %d: %d %d %d\r\n", accdata.Timestamp, accdata.X, accdata.Y, accdata.Z);
    			g_Imu.Read(quat);
    			printf("Quat %d: %d %d %d %d\r\n", quat.Timestamp, quat.Q1, quat.Q2, quat.Q2, quat.Q3);
    
    			break;
    	}
    }
    
    
    void ImuIntHandler(int IntNo)
    {
    	if (IntNo == 0)
    	{
    		uint32_t t = g_Timer.uSecond();
    		g_DT = t - g_TPrev;
    		g_TPrev = t;
    
    		g_Imu.IntHandler();
    		g_MotSensor.IntHandler();
    	}
    }
    
    
    bool HardwareInit()
    {
    	bool res;
    
    	g_Timer.Init(s_TimerCfg);
    
    	res = g_I2c.Init(s_I2cCfg);
    
    	if (res == true)
    	{
    		res = g_MotSensor.Init(s_AccelCfg, &g_I2c, &g_Timer);
    		if (res == true)
    		{
    			g_pAccel = &g_MotSensor;
    		}
    
    		res = g_Imu.Init(s_ImuCfg, &g_MotSensor, &g_MotSensor, &g_MotSensor);
    	}
    
    	if (res == true)
    	{
    
    		int8_t m[9] = { 1, 0, 0,
    						0, 1, 0,
    						0, 0, 1 };
    	}
    
    	return res;
    }
    
    int main()
    {
    	bool res = HardwareInit();
    
    
    	if (res == false)
    	{
    		printf("Failed initializing hardware\r\n");
    
    		return 1;
    	}
    
    	printf("MotionSensorDemo\r\n");
    
    	ACCELSENSOR_RAWDATA arawdata;
    	ACCELSENSOR_DATA accdata;
    	GYROSENSOR_RAWDATA grawdata;
    	GYROSENSOR_DATA gyrodata;
    	MAGSENSOR_RAWDATA mrawdata;
    
    	memset(&arawdata, 0, sizeof(ACCELSENSOR_RAWDATA));
    	memset(&accdata, 0, sizeof(ACCELSENSOR_DATA));
    	memset(&gyrodata, 0, sizeof(GYROSENSOR_DATA));
    
    
    	uint32_t prevt = 0;
    	int cnt = 100;
    	while (1)
    	{
    		uint32_t t = g_Timer.uSecond();
    
    
    		g_MotSensor.UpdateData();
    
    		uint32_t dt = arawdata.Timestamp - prevt;
    		prevt = arawdata.Timestamp;
    
    		g_MotSensor.Read(arawdata);
    
    		if (g_pGyro)
    		{
    			g_pGyro->Read(grawdata);
    		}
    
    		if (g_pMag)
    		{
    			g_pMag->Read(mrawdata);
    		}
    
    		g_Imu.Read(accdata);
    
    		if (cnt-- < 0)
    		{
    			cnt = 100;
    			printf("Accel %d %d: %d %d %d\r\n", (uint32_t)g_DT, (uint32_t)dt, arawdata.X, arawdata.Y, arawdata.Z);
    			//printf("Accel %d %d: %f %f %f\r\n", (uint32_t)g_DT, (uint32_t)dt, accdata.X, accdata.Y, accdata.Z);
    		}
    	}
    }


    It seems like g_I2c with I2cCfg is bringing false. So, there is a problem with I2cCfg?
    ( res = g_I2c.Init(s_I2cCfg ); --> false 

  • You can trace into it to see what exactly is wrong.  I don't think I2C is returning false but it may not detect the sensor. Use the debugger and step into it. You will see why it returns false

  • I've been looking to it, setting couple breakpoints but actually It was my first time debugging such thing, and I do not know where to start, where set breakpoints and what to look for?

    Can you help me a little bit more?

    (And I checked twi_scanner example again, to be sure that's everything is  connected, and it is, twi_scanner discovers mpu9250 at 0x68)

Related