reversebias / mitosis

Firmware for nordic MCUs used in the Mitosis Keyboard
GNU General Public License v3.0
195 stars 125 forks source link

Debug through ST LinkV2 #16

Closed realSpok closed 5 years ago

realSpok commented 6 years ago

I have been trying to debug my slightly modified receiver code, on a linux system with st link v2. Just a simple variable print would do. I can compile and flash the nrf51822 without any problem, but I don't understand how to see the output of app_uart_put() on my computer. I have tried openocd/gdb, after some googling, but nothing seems to show up on the console. The ST link doesn't seem to show up on a serial port. Would anyone have a pointer in the right direction?

joric commented 6 years ago

There's no tracing hardware in nrf51 series so I just used a single UART pin, see https://github.com/joric/mitosis/tree/devel/mitosis-bluetooth

realSpok commented 6 years ago

Interesting project. I can see what you mean with the video. I have Arduinos laying around that I could hookup to the nrf51822 UART and use to relay the Serial print to my computer. Thanks for the heads up.

joric commented 6 years ago

There are easier ways, as figures, you don't have to setup uart it's already done. CFLAGS += -DNRF_LOG_USES_UART=1 -DNRF_LOG_ENABLED=1 -DENABLE_DEBUG_LOG_SUPPORT=1 -DDM_DISABLE_LOGS=1 (dm disables device manager logs, they're pretty verbose, add the same for ASMFLAGS as well) then app_trace_init(); app_trace_log("Hello world!\n");

SDK 11 works at 115200 baud by default SDK 10 works at 38400 baud

realSpok commented 5 years ago

Thanks for your comments. Sorry I didn't respond earlier but I hadn't have time to work on this project lately. I have restarted looking into it, and noticed that you have made a lot of progress on the bluetosis since then. This project looks better and better. I have attempted a couple things to get the debug working on my side, but I still cannot get any TX signal from any pin on the core nrf51822…

I have slightly modified the main function of the bluetosis firmware into the following:

int main(void){
static const uint8_t row_pin_array[MATRIX_ROWS] = {26,23,24,25};                
static const uint8_t column_pin_array[MATRIX_COLS] = {2,0};                     

uint32_t err_code;                                                              
err_code = NRF_LOG_INIT(NULL);                                                  

for (uint_fast8_t i = MATRIX_ROWS; i--;)                                        
{                                                                               
    nrf_gpio_cfg(                                                               
        (uint32_t)row_pin_array[i],                                             
        NRF_GPIO_PIN_DIR_OUTPUT,                                                
        NRF_GPIO_PIN_INPUT_DISCONNECT,                                          
        NRF_GPIO_PIN_NOPULL,                                                    
        NRF_GPIO_PIN_D0S1,                                                      
        NRF_GPIO_PIN_NOSENSE);                                                  
    nrf_gpio_pin_clear((uint32_t)row_pin_array[i]);         //Set pin to low    
}                                                                               
for (uint_fast8_t i = MATRIX_COLS; i--;)                                        
{                                                                               
    nrf_gpio_cfg_input((uint32_t)column_pin_array[i], NRF_GPIO_PIN_PULLUP);     
}                                                                               

// Enter main loop.                                                             
for (;;)                                                                        
{                                                                               

    NRF_LOG_INFO("HID Keyboard Start!\r\n");                                    
    NRF_LOG_DEBUG("GATT Server Timeout.\r\n");                                  
    printf("debugging");                                                        
    app_uart_put(0x12);

    nrf_gpio_pin_set(row_pin_array[0]);                                         
    nrf_gpio_pin_set(row_pin_array[3]);                                         
    nrf_delay_us(100);                                                          
    nrf_gpio_pin_clear(row_pin_array[0]);                                       
    nrf_delay_us(200);                                                          
    nrf_gpio_pin_clear(row_pin_array[3]);                                       
    nrf_delay_us(300);                                                          

}                                                                               
}

This code compile and seems to run fine. With the help of an oscilloscope, I clearly detect the squarish waveform on pin 25 for instance, but nothing ever shows up on the expected TX pin (I tried 21, 9, 6, and a lot of others, by changing the TX_PIN_NUMBER from mitosis_ble_gzll.h).

I am using gcc/openocd to compile and upload. Let me know if I should open another issue on your bluetosis repo instead.

realSpok commented 5 years ago

An update about this issue: I seem to have had problems with flashing the softdevice, which caused my issues above. I finally used the linux utility mergehex provided by nordics to merge my hex and the softdevice before flashing, and it worked out much better.

realSpok commented 5 years ago

I am not sure how to / if I can close this issue, but I think it can be considered solved

joric commented 5 years ago

@realSpok you DON'T have to flash softdevice, this firmware DOES NOT use softdevice at all. Don't flash softdevice.