analogdevicesinc / msdk

Software Development Kit for Analog Device's MAX-series microcontrollers
Apache License 2.0
60 stars 76 forks source link

Document JLink Debugger Support #291

Closed chaitanya-smartrotamac closed 1 year ago

chaitanya-smartrotamac commented 1 year ago
//I changed the following changes as I want to check only power-down mode
#define USE_BUTTON 1
#define USE_ALARM  0

#define DISABLE_GPIO 0 //it configures all GPIOs as input to save power

#define DO_SLEEP     0
#define DO_LPM       0
#define DO_UPM       0
#define DO_STANDBY   0
#define DO_BACKUP    0 // will reset after wakeup`
#define DO_POWERDOWN 1 // will reset after wakeup

Now I am using FTHR board, Red light on > Clicked the trigger button > Red light off > waiting for 3.0/3.1 to be pressed. I connected the pin 3.1 to the gnd and found nothing is happening ? It should be supposed to wake up right? not happening. Is something wrong with my expectation?

chaitanya-smartrotamac commented 1 year ago

Examples/MAX78000/LP/main.c Path of the code

aniktash commented 1 year ago

Please use P3.0 or reset instead of P3.1. In either case, a reset will be triggered.

chaitanya-smartrotamac commented 1 year ago

How to use P3.0 because it is a shared signal between PMIC and MAX 78000 IC. I am using the FTHR board. is there a way I can use P3.1?

aniktash commented 1 year ago

Unfortunately not, only P3.0 or reset can be used as the wake-up source in Power Down mode. The example and documentation will be updated soon. You may use the reset instead, which works the same way.

chaitanya-smartrotamac commented 1 year ago

Unfortunately not, only P3.0 or reset can be used as the wake-up source in Power Down mode. The example and documentation will be updated soon. You may use the reset instead, which works the same way.

Thank you @aniktash We will use P3.0 in our product design.

Next question, this may not be related to the actual question

While I am testing I found "#include "led.h" " and "#include "pb.h" "

in code path : https://github.com/Analog-Devices-MSDK/msdk/blob/main/Examples/MAX78000/LP/main.c

includes paths that are not visible to the Eclipse IDE

check my includes, I included almost everything. Still there are some red line missing includes.

image

Did I miss something?

aniktash commented 1 year ago

There seems to be some includes missing compared to the original LP example project. You may want to try to add them, or import the original example: image

chaitanya-smartrotamac commented 1 year ago

yes, you are right @aniktash . But I thought adding just the /MiscDrivers will add all driver-related files.

Still, I can find some includes are missing, Can you tell me what are they? image image

though they are missing, Still the compiler can see them while building and always has 0 errors.

aniktash commented 1 year ago

This is just to help the Eclipse IDE indexing. They are not needed to build; The compiler uses make files to find them. LED1 and CONSOLE_UART are in include files: image pb_pin is here: C:\MaximSDK\Libraries\Boards\MAX78000\EvKit_V1\Source\board.c Generally, the indexer should be able to find if it is enabled: image Sometimes the indexer needs help; You may need to choose to search for unresolved includes, re-resolve or refresh and rebuild: image

chaitanya-smartrotamac commented 1 year ago

"Sometimes the indexer needs help; You may need to choose to search for unresolved includes, re-resolve or refresh and rebuild": image

Wow, That rebuild indexing did the trick. Thank you @aniktash

This will be my last question in this post chain,

image How to find to which function it was referring? I tried ctrl+click but it is going nowhere.

When debugging I can see by stepping in, But is there a way to know without debugging?

aniktash commented 1 year ago

The peripheral drivers are in this folder: C:\MaximSDK\Libraries\PeriphDrivers\Source Inside each peripheral folder, you can find the specific driver for MAX78000 tagged as ai85 (it's our internal die name), e.g. uart_ai85.c. For some peripherals, a generic driver is used, or a driver from another die (me17). You can see the list of drivers used for MAX78000 in this make file: C:\MaximSDK\Libraries\PeriphDrivers\max78000_files.mk

chaitanya-smartrotamac commented 1 year ago

Thank you @aniktash One more last issue. We developed our custom board with MAX78000 and found that JLINK is officially supported. We tried it with no luck. Is there a example code or project how to setup the Jlink to program max78000?

aniktash commented 1 year ago

@jessexm could you please support?

Jake-Carter commented 1 year ago

@chaitanya-smartrotamac I have a J-Link setup guide for Visual Studio Code on the VSCode-Maxim wiki here: https://github.com/Analog-Devices-MSDK/VSCode-Maxim/wiki/Segger-J-Link-Setup-Guide

There is an option to use either our OpenOCD server or the native JLink GDB server, which is discussed more in the document.

The setup guide will be migrated to the official MSDK User Guide soon, so if you encounter any issues or any missing info please let me know.

A tip for troubleshooting: If you have issues connecting with a JLink debugger try connecting with our PICO debugger first, and verify that works. If the PICO cannot connect either, then there may be some hardware issues with the custom board.

Jake-Carter commented 1 year ago

@chaitanya-smartrotamac for Eclipse there is some official documentation here: https://eclipse-embed-cdt.github.io/debug/jlink/

I haven't tested this thoroughly myself yet, but for VS Code I found I had to override the JLink Reset strategy to Type 2 (ResetPin) to get the native JLink Server to work reliably.

I passed the following command-line option to the JLink server:

-JLinkScriptFile Reset.JLinkScript

Where the contents of the Reset.JLinkScript file are:

/*********************************************************************
*                                                                     
*       ConfigTargetSettings   
*
*  Function description
*    Called before InitTarget(). Mainly used to set some global DLL variables to customize the
*    normal  connect  procedure.  For  ARM  CoreSight  devices  this  may  be  specifying  the  base
*    address of some CoreSight components (ETM, …) that cannot be auto-detected by J-Link
*    due to erroneous ROM tables etc. May also be used to specify the device name in case
*    debugger does not pass it to the DLL.                    
*
*  Notes
*    (1) May not, under absolutely NO circumstances, call any API functions that perform target communication.
*    (2) Should only set some global DLL variables
*
*  Return value
*    >= 0  O.K.
*     < 0  Error
*      -1  Unspecified error
*/
int ConfigTargetSettings(void) {
  //
  // Set reset strategy used by the J-Link to Reset + Halt After Bootloader Using Watchpoint.
  //
  JLINK_SYS_Report("-- Configure Reset Strategy --");
  JLINK_ExecCommand("SetResetType = 2"); // Use RESETPIN (Resets core & peripherals using RESET pin.) Other reset strategies proved to be unreliable.
  return 0;
}
chaitanya-smartrotamac commented 1 year ago

Hi @Jake-Carter Thank you for your response.

I will try your method in VS code and sure will let you know any issues with it.

We tried from our side with eclipse and found a working configuration, Which you can use for testing and add to the official document.

Hello world code folder structure I am using image

Debug configuration image

Debugger settings image

startup image

Common image

That's it, It worked.

I think prerequisites are

Please review the settings and suggest any changes required. Will share my code folder also if required, May help someone to resolve Jlink issue faster.

Jake-Carter commented 1 year ago

Thanks @chaitanya-smartrotamac, this is great. I'll test it out and get it added to our UG. Much appreciated!

Saicharan036 commented 1 year ago

Hi @Jake-Carter

I am trying to setup Visual studio jlink setup and following problems I am facing

1) Cant find open settings json

image

2) Build was successful but flash is failing

This is error :

Loaded project.mk arm-none-eabi-size --format=berkeley /c/Users/LENOVO/Max78000_1/P3_DSP_Development_P3board_UART_cmd/build/P3_DSP_Development_P3board_UART_cmd.elf text data bss dec hex filename 36572 2512 1284 40368 9db0 C:/Users/LENOVO/Max78000_1/P3_DSP_Development_P3board_UART_cmd/build/P3_DSP_Development_P3board_UART_cmd.elf

C:\MaximSDK\Tools\GNUTools\10.3\bin\arm-none-eabi-gdb.exe: warning: Couldn't determine a path for the index cache directory. The target architecture is set to "armv7e-m". Open On-Chip Debugger 0.11.0+dev-g56a818e4c (2022-11-16-05:46) Licensed under GNU GPL v2 For bug reports, read http://openocd.org/doc/doxygen/bugs.html Remote communication error. Target disconnected.: No error.

image

3) I changed the Jlink drivers using the process mentioned here https://github.com/Analog-Devices-MSDK/VSCode-Maxim/wiki/Segger-J-Link-Setup-Guide

how to revert back to normal jlink?


I added this setting in User settings

image

I clicked on erase and I got this Open On-Chip Debugger 0.11.0+dev-g56a818e4c (2022-11-16-05:46) Licensed under GNU GPL v2 For bug reports, read http://openocd.org/doc/doxygen/bugs.html Info : J-Link V11 compiled Dec 14 2022 09:09:01 Info : Hardware version: 11.00 Info : VTarget = 1.772 V Info : clock speed 2000 kHz Info : SWD DPIDR 0x2ba01477 Info : max32xxx.cpu: Cortex-M4 r0p1 processor detected Info : max32xxx.cpu: target has 6 breakpoints, 4 watchpoints Info : max32xxx.cpu: external reset detected Info : starting gdb server for max32xxx.cpu on 3333
Info : Listening on port 3333 for gdb connections
target halted due to debug-request, current mode: Thread xPSR: 0x61000000 pc: 0x00002706 msp: 0x20003e38 Error: timed out while waiting for target halted TARGET: max32xxx.cpu - Not halted

Jake-Carter commented 1 year ago

Hi @Saicharan036

Cant find open settings json

Looks like VS Code changed the name of that option in the latest update, so my screenshot is outdated. You found the correct option - it's Open User Settings (JSON)

how to revert back to normal jlink?

You can follow steps 1-3 from https://github.com/Analog-Devices-MSDK/VSCode-Maxim/wiki/Segger-J-Link-Setup-Guide#option-2-j-link-with-jlinkgdbserver to revert the adapter back to the normal JLink drivers

why is it "TARGET: max32xxx.cpu - Not halted" but I have MAX78000

max32xxx is a common CPU configuration across all of our micros, so this is expected.

Everything looks correct on your setup. There should be a "flash.log" file in your project with some more detailed OpenOCD output on why the flash failed. Can you attach it?

chaitanya-smartrotamac commented 1 year ago

Hi @Jake-Carter @aniktash Can someone help me quickly with my issues? I want to interface with a Bluetooth microcontroller to program the MAX78000 using the serial bootloader. I mentioned everything in this issue here https://github.com/MaximIntegratedAI/secure-loader/issues/3#issue-1618428238

Right now, I want to understand how this works by programming MAX78000 fthr eval kit using another MAX78000 fthr eval kit.